HtmlToJsonTest::testConvertBlockquoteToJson()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
rs 9.4285
cc 1
eloc 9
nc 1
nop 0
1
<?php
2
3
namespace Sioen\Tests;
4
5
use Sioen\HtmlToJson;
6
use Sioen\HtmlToJson\HeadingConverter;
7
use Sioen\HtmlToJson\BlockquoteConverter;
8
use Sioen\HtmlToJson\ImageConverter;
9
10
final class HtmlToJsonTest extends \PHPUnit_Framework_TestCase
11
{
12
    public function testConvertHeadingToJson()
13
    {
14
        $htmlToJson = new HtmlToJson();
15
        $htmlToJson->addConverter(new HeadingConverter());
16
        $this->assertEquals(
17
            $htmlToJson->toJson('<h2>Test</h2>'),
18
            '{"data":[{"type":"heading","data":{"text":" Test"}}]}'
19
        );
20
    }
21
22
    public function testConvertBlockquoteToJson()
23
    {
24
        $htmlToJson = new HtmlToJson();
25
        $htmlToJson->addConverter(new BlockquoteConverter());
26
27
        // with cite
28
        $this->assertEquals(
29
            $htmlToJson->toJson('<blockquote><p>Text</p><cite>Cite</cite></blockquote>'),
30
            '{"data":[{"type":"quote","data":{"text":" Text","cite":" Cite"}}]}'
31
        );
32
33
        // without cite
34
        $this->assertEquals(
35
            $htmlToJson->toJson('<blockquote><p>Text</p></blockquote>'),
36
            '{"data":[{"type":"quote","data":{"text":" Text","cite":""}}]}'
37
        );
38
    }
39
40
    public function testConvertImageToJson()
41
    {
42
        $htmlToJson = new HtmlToJson();
43
        $htmlToJson->addConverter(new ImageConverter());
44
        $this->assertEquals(
45
            $htmlToJson->toJson('<img src="/path/to/img.jpg" />'),
46
            '{"data":[{"type":"image","data":{"file":{"url":"\/path\/to\/img.jpg"}}}]}'
47
        );
48
    }
49
}
50