HtmlToJsonTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
c 3
b 0
f 0
lcom 1
cbo 5
dl 0
loc 40
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testConvertHeadingToJson() 0 9 1
A testConvertBlockquoteToJson() 0 17 1
A testConvertImageToJson() 0 9 1
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