@@ 14-33 (lines=20) @@ | ||
11 | ||
12 | final class JsonToHtmlTest extends \PHPUnit_Framework_TestCase |
|
13 | { |
|
14 | public function testConvertBlockquoteToHtml() |
|
15 | { |
|
16 | $converter = new JsonToHtml(); |
|
17 | $converter->addConverter(new BlockquoteConverter()); |
|
18 | ||
19 | $json = json_encode(array( |
|
20 | 'data' => array(array( |
|
21 | 'type' => 'quote', |
|
22 | 'data' => array( |
|
23 | 'text' => 'Text', |
|
24 | 'cite' => 'Cite' |
|
25 | ) |
|
26 | )) |
|
27 | )); |
|
28 | $html = $converter->toHtml($json); |
|
29 | $this->assertEquals( |
|
30 | $html, |
|
31 | "<blockquote><p>Text</p>\n<cite><p>Cite</p>\n</cite></blockquote>" |
|
32 | ); |
|
33 | } |
|
34 | ||
35 | public function testConvertParagraphToHtml() |
|
36 | { |
|
@@ 35-51 (lines=17) @@ | ||
32 | ); |
|
33 | } |
|
34 | ||
35 | public function testConvertParagraphToHtml() |
|
36 | { |
|
37 | $converter = new JsonToHtml(); |
|
38 | $converter->addConverter(new BaseConverter()); |
|
39 | ||
40 | // Lets convert a normal text type that uses the default converter |
|
41 | $json = json_encode(array( |
|
42 | 'data' => array(array( |
|
43 | 'type' => 'text', |
|
44 | 'data' => array( |
|
45 | 'text' => 'test' |
|
46 | ) |
|
47 | )) |
|
48 | )); |
|
49 | $html = $converter->toHtml($json); |
|
50 | $this->assertEquals($html, "<p>test</p>\n"); |
|
51 | } |
|
52 | ||
53 | public function testConvertVideoToHtml() |
|
54 | { |
|
@@ 53-73 (lines=21) @@ | ||
50 | $this->assertEquals($html, "<p>test</p>\n"); |
|
51 | } |
|
52 | ||
53 | public function testConvertVideoToHtml() |
|
54 | { |
|
55 | $converter = new JsonToHtml(); |
|
56 | $converter->addConverter(new IframeConverter()); |
|
57 | ||
58 | // the video conversion |
|
59 | $json = json_encode(array( |
|
60 | 'data' => array(array( |
|
61 | 'type' => 'video', |
|
62 | 'data' => array( |
|
63 | 'source' => 'youtube', |
|
64 | 'remote_id' => '4BXpi7056RM' |
|
65 | ) |
|
66 | )) |
|
67 | )); |
|
68 | $html = $converter->toHtml($json); |
|
69 | $this->assertEquals( |
|
70 | $html, |
|
71 | "<iframe src=\"//www.youtube.com/embed/4BXpi7056RM?rel=0\" frameborder=\"0\" allowfullscreen></iframe>\n" |
|
72 | ); |
|
73 | } |
|
74 | ||
75 | public function testConvertHeadingToHtml() |
|
76 | { |
|
@@ 75-91 (lines=17) @@ | ||
72 | ); |
|
73 | } |
|
74 | ||
75 | public function testConvertHeadingToHtml() |
|
76 | { |
|
77 | $converter = new JsonToHtml(); |
|
78 | $converter->addConverter(new HeadingConverter()); |
|
79 | ||
80 | // The heading |
|
81 | $json = json_encode(array( |
|
82 | 'data' => array(array( |
|
83 | 'type' => 'heading', |
|
84 | 'data' => array( |
|
85 | 'text' => 'test' |
|
86 | ) |
|
87 | )) |
|
88 | )); |
|
89 | $html = $converter->toHtml($json); |
|
90 | $this->assertEquals($html, "<h2>test</h2>\n"); |
|
91 | } |
|
92 | ||
93 | public function testConvertImageToHtml() |
|
94 | { |
|
@@ 93-111 (lines=19) @@ | ||
90 | $this->assertEquals($html, "<h2>test</h2>\n"); |
|
91 | } |
|
92 | ||
93 | public function testConvertImageToHtml() |
|
94 | { |
|
95 | $converter = new JsonToHtml(); |
|
96 | $converter->addConverter(new ImageConverter()); |
|
97 | ||
98 | // images |
|
99 | $json = json_encode(array( |
|
100 | 'data' => array(array( |
|
101 | 'type' => 'image', |
|
102 | 'data' => array( |
|
103 | 'file' => array( |
|
104 | 'url' => '/frontend/files/sir-trevor/images/IMG_3867.JPG' |
|
105 | ) |
|
106 | ) |
|
107 | )) |
|
108 | )); |
|
109 | $html = $converter->toHtml($json); |
|
110 | $this->assertEquals($html, "<img src=\"/frontend/files/sir-trevor/images/IMG_3867.JPG\" />\n"); |
|
111 | } |
|
112 | } |
|
113 |