|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Sioen\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use Sioen\JsonToHtml; |
|
6
|
|
|
use Sioen\JsonToHtml\BlockquoteConverter; |
|
7
|
|
|
use Sioen\JsonToHtml\BaseConverter; |
|
8
|
|
|
use Sioen\JsonToHtml\IframeConverter; |
|
9
|
|
|
use Sioen\JsonToHtml\ImageConverter; |
|
10
|
|
|
use Sioen\JsonToHtml\HeadingConverter; |
|
11
|
|
|
|
|
12
|
|
|
class JsonToHtmlTest extends \PHPUnit_Framework_TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
public function testToHtml() |
|
15
|
|
|
{ |
|
16
|
|
|
$converter = new JsonToHtml(); |
|
17
|
|
|
$converter->addConverter(new BlockquoteConverter()); |
|
18
|
|
|
$converter->addConverter(new HeadingConverter()); |
|
19
|
|
|
$converter->addConverter(new IframeConverter()); |
|
20
|
|
|
$converter->addConverter(new ImageConverter()); |
|
21
|
|
|
$converter->addConverter(new BaseConverter()); |
|
22
|
|
|
|
|
23
|
|
|
// let's try a basic json |
|
24
|
|
|
$json = json_encode(array( |
|
25
|
|
|
'data' => array(array( |
|
26
|
|
|
'type' => 'quote', |
|
27
|
|
|
'data' => array( |
|
28
|
|
|
'text' => 'Text', |
|
29
|
|
|
'cite' => 'Cite' |
|
30
|
|
|
) |
|
31
|
|
|
)) |
|
32
|
|
|
)); |
|
33
|
|
|
$html = $converter->toHtml($json); |
|
34
|
|
|
$this->assertEquals( |
|
35
|
|
|
$html, |
|
36
|
|
|
"<blockquote><p>Text</p>\n<cite><p>Cite</p>\n</cite></blockquote>" |
|
37
|
|
|
); |
|
38
|
|
|
|
|
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
|
|
|
// the video conversion |
|
53
|
|
|
$json = json_encode(array( |
|
54
|
|
|
'data' => array(array( |
|
55
|
|
|
'type' => 'video', |
|
56
|
|
|
'data' => array( |
|
57
|
|
|
'source' => 'youtube', |
|
58
|
|
|
'remote_id' => '4BXpi7056RM' |
|
59
|
|
|
) |
|
60
|
|
|
)) |
|
61
|
|
|
)); |
|
62
|
|
|
$html = $converter->toHtml($json); |
|
63
|
|
|
$this->assertEquals( |
|
64
|
|
|
$html, |
|
65
|
|
|
"<iframe src=\"//www.youtube.com/embed/4BXpi7056RM?rel=0\" frameborder=\"0\" allowfullscreen></iframe>\n" |
|
66
|
|
|
); |
|
67
|
|
|
|
|
68
|
|
|
// The heading |
|
69
|
|
|
$json = json_encode(array( |
|
70
|
|
|
'data' => array(array( |
|
71
|
|
|
'type' => 'heading', |
|
72
|
|
|
'data' => array( |
|
73
|
|
|
'text' => 'test' |
|
74
|
|
|
) |
|
75
|
|
|
)) |
|
76
|
|
|
)); |
|
77
|
|
|
$html = $converter->toHtml($json); |
|
78
|
|
|
$this->assertEquals($html, "<h2>test</h2>\n"); |
|
79
|
|
|
|
|
80
|
|
|
// images |
|
81
|
|
|
$json = json_encode(array( |
|
82
|
|
|
'data' => array(array( |
|
83
|
|
|
'type' => 'image', |
|
84
|
|
|
'data' => array( |
|
85
|
|
|
'file' => array( |
|
86
|
|
|
'url' => '/frontend/files/sir-trevor/images/IMG_3867.JPG' |
|
87
|
|
|
) |
|
88
|
|
|
) |
|
89
|
|
|
)) |
|
90
|
|
|
)); |
|
91
|
|
|
$html = $converter->toHtml($json); |
|
92
|
|
|
$this->assertEquals($html, "<img src=\"/frontend/files/sir-trevor/images/IMG_3867.JPG\" />\n"); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|