1
|
|
|
<?php |
2
|
|
|
class PageTest extends \PHPUnit\Framework\TestCase |
3
|
|
|
{ |
4
|
|
|
public function testLanguage() |
5
|
|
|
{ |
6
|
|
|
$language = 'fr_FR'; |
7
|
|
|
$page = new \Suricate\Page(); |
8
|
|
|
$page->setLanguage($language); |
9
|
|
|
$this->assertSame($language, $page->getLanguage()); |
10
|
|
|
} |
11
|
|
|
|
12
|
|
|
public function testEncoding() |
13
|
|
|
{ |
14
|
|
|
$encoding = 'iso-8859-1'; |
15
|
|
|
|
16
|
|
|
$page = new \Suricate\Page(); |
17
|
|
|
$page->setEncoding($encoding); |
18
|
|
|
$this->assertSame($encoding, $page->getEncoding()); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function testTitle() |
22
|
|
|
{ |
23
|
|
|
$title = 'My great webpage'; |
24
|
|
|
|
25
|
|
|
$page = new \Suricate\Page(); |
26
|
|
|
$page->setTitle($title); |
27
|
|
|
$this->assertSame($title, $page->getTitle()); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testAddStylesheet() |
31
|
|
|
{ |
32
|
|
|
$page = new \Suricate\Page(); |
33
|
|
|
$page->addStylesheet('stylesheet-ref', '/my.css'); |
34
|
|
|
|
35
|
|
|
$reflector = new ReflectionClass(get_class($page)); |
36
|
|
|
$property = $reflector->getProperty('stylesheets'); |
37
|
|
|
$property->setAccessible(true); |
38
|
|
|
|
39
|
|
|
$this->assertEquals($property->getValue($page), [ |
40
|
|
|
'stylesheet-ref' => ['url' => '/my.css', 'media' => 'all'] |
41
|
|
|
]); |
42
|
|
|
$this->assertNotEquals($property->getValue($page), [ |
43
|
|
|
'another-stylesheet' => ['url' => '/my-2.css', 'media' => 'all'] |
44
|
|
|
]); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testRender() |
48
|
|
|
{ |
49
|
|
|
$page = new \Suricate\Page(); |
50
|
|
|
$this->assertEquals( |
51
|
|
|
'<!DOCTYPE html>' . |
52
|
|
|
'<html lang="en">' . |
53
|
|
|
'<head>' . |
54
|
|
|
'<title></title>' . |
55
|
|
|
'<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . |
56
|
|
|
'</head>' . |
57
|
|
|
'<body>' . |
58
|
|
|
'</body>' . |
59
|
|
|
'</html>', |
60
|
|
|
$page->render() |
61
|
|
|
); |
62
|
|
|
|
63
|
|
|
$page->setTitle('My Pageé'); |
64
|
|
|
$this->assertEquals( |
65
|
|
|
'<!DOCTYPE html>' . |
66
|
|
|
'<html lang="en">' . |
67
|
|
|
'<head>' . |
68
|
|
|
'<title>My Pageé</title>' . |
69
|
|
|
'<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . |
70
|
|
|
'</head>' . |
71
|
|
|
'<body>' . |
72
|
|
|
'</body>' . |
73
|
|
|
'</html>', |
74
|
|
|
$page->render() |
75
|
|
|
); |
76
|
|
|
|
77
|
|
|
$page->addHtmlClass('class1'); |
78
|
|
|
$page->addHtmlClass('class2'); |
79
|
|
|
|
80
|
|
|
$this->assertEquals( |
81
|
|
|
'<!DOCTYPE html>' . |
82
|
|
|
'<html lang="en" class="class1 class2">' . |
83
|
|
|
'<head>' . |
84
|
|
|
'<title>My Pageé</title>' . |
85
|
|
|
'<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . |
86
|
|
|
'</head>' . |
87
|
|
|
'<body>' . |
88
|
|
|
'</body>' . |
89
|
|
|
'</html>', |
90
|
|
|
$page->render() |
91
|
|
|
); |
92
|
|
|
|
93
|
|
|
$page->addScript('script-id', 'http://scripturl.com'); |
94
|
|
|
$page->addRss('rss-id', 'http://rssurl.com', 'RSS is not dead !'); |
95
|
|
|
$page->addStylesheet('css-id', 'http://cssurl.com'); |
96
|
|
|
$page->addMeta('metaname', 'metacontent'); |
97
|
|
|
$page->addMetaProperty('metapropertyname', 'metapropertycontent'); |
98
|
|
|
$page->addMetaLink('metalinkname', 'metalinktype', 'metalinkhref'); |
99
|
|
|
|
100
|
|
|
$this->assertEquals( |
101
|
|
|
'<!DOCTYPE html>' . |
102
|
|
|
'<html lang="en" class="class1 class2">' . |
103
|
|
|
'<head>' . |
104
|
|
|
'<title>My Pageé</title>' . |
105
|
|
|
'<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . |
106
|
|
|
'<meta name="metaname" content="metacontent">' . |
107
|
|
|
'<meta property="metapropertyname" content="metapropertycontent">' . |
108
|
|
|
'<link rel="metalinktype" href="metalinkhref">' . |
109
|
|
|
'<link rel="stylesheet" id="css-id" href="http://cssurl.com" type="text/css" media="all">' . |
110
|
|
|
'<script type="text/javascript" src="http://scripturl.com"></script>' . |
111
|
|
|
'<link rel="alternate" id="rss-id" href="http://rssurl.com" type="application/rss+xml" title="RSS is not dead !">' . |
112
|
|
|
'</head>' . |
113
|
|
|
'<body>' . |
114
|
|
|
'</body>' . |
115
|
|
|
'</html>', |
116
|
|
|
$page->render() |
117
|
|
|
); |
118
|
|
|
|
119
|
|
|
$page->addScript('script-id', 'http://scripturl.com', true); |
120
|
|
|
$this->assertEquals( |
121
|
|
|
'<!DOCTYPE html>' . |
122
|
|
|
'<html lang="en" class="class1 class2">' . |
123
|
|
|
'<head>' . |
124
|
|
|
'<title>My Pageé</title>' . |
125
|
|
|
'<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . |
126
|
|
|
'<meta name="metaname" content="metacontent">' . |
127
|
|
|
'<meta property="metapropertyname" content="metapropertycontent">' . |
128
|
|
|
'<link rel="metalinktype" href="metalinkhref">' . |
129
|
|
|
'<link rel="stylesheet" id="css-id" href="http://cssurl.com" type="text/css" media="all">' . |
130
|
|
|
'<script type="text/javascript" src="http://scripturl.com" async></script>' . |
131
|
|
|
'<link rel="alternate" id="rss-id" href="http://rssurl.com" type="application/rss+xml" title="RSS is not dead !">' . |
132
|
|
|
'</head>' . |
133
|
|
|
'<body>' . |
134
|
|
|
'</body>' . |
135
|
|
|
'</html>', |
136
|
|
|
$page->render() |
137
|
|
|
); |
138
|
|
|
|
139
|
|
|
$page->addScript('script-id', 'http://scripturl.com', false, true); |
140
|
|
|
$this->assertEquals( |
141
|
|
|
'<!DOCTYPE html>' . |
142
|
|
|
'<html lang="en" class="class1 class2">' . |
143
|
|
|
'<head>' . |
144
|
|
|
'<title>My Pageé</title>' . |
145
|
|
|
'<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . |
146
|
|
|
'<meta name="metaname" content="metacontent">' . |
147
|
|
|
'<meta property="metapropertyname" content="metapropertycontent">' . |
148
|
|
|
'<link rel="metalinktype" href="metalinkhref">' . |
149
|
|
|
'<link rel="stylesheet" id="css-id" href="http://cssurl.com" type="text/css" media="all">' . |
150
|
|
|
'<script type="text/javascript" src="http://scripturl.com" defer></script>' . |
151
|
|
|
'<link rel="alternate" id="rss-id" href="http://rssurl.com" type="application/rss+xml" title="RSS is not dead !">'. |
152
|
|
|
'</head>'. |
153
|
|
|
'<body>'. |
154
|
|
|
'</body>'. |
155
|
|
|
'</html>', |
156
|
|
|
$page->render() |
157
|
|
|
); |
158
|
|
|
|
159
|
|
|
$page->addScript('script-id', 'http://scripturl.com', true, true); |
160
|
|
|
$this->assertEquals( |
161
|
|
|
'<!DOCTYPE html>' . |
162
|
|
|
'<html lang="en" class="class1 class2">' . |
163
|
|
|
'<head>' . |
164
|
|
|
'<title>My Pageé</title>' . |
165
|
|
|
'<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . |
166
|
|
|
'<meta name="metaname" content="metacontent">' . |
167
|
|
|
'<meta property="metapropertyname" content="metapropertycontent">' . |
168
|
|
|
'<link rel="metalinktype" href="metalinkhref">' . |
169
|
|
|
'<link rel="stylesheet" id="css-id" href="http://cssurl.com" type="text/css" media="all">' . |
170
|
|
|
'<script type="text/javascript" src="http://scripturl.com" async defer></script>' . |
171
|
|
|
'<link rel="alternate" id="rss-id" href="http://rssurl.com" type="application/rss+xml" title="RSS is not dead !">' . |
172
|
|
|
'</head>' . |
173
|
|
|
'<body>' . |
174
|
|
|
'</body>' . |
175
|
|
|
'</html>', |
176
|
|
|
$page->render() |
177
|
|
|
); |
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
|