-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathMicroformatsWikiExamplesTest.php
205 lines (184 loc) · 5.11 KB
/
MicroformatsWikiExamplesTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<?php
/**
* Tests of the parsing methods within mf2\Parser
*/
namespace Mf2\Parser\Test;
use Mf2\Parser;
use Yoast\PHPUnitPolyfills\TestCases\TestCase;
/**
* Microformats Wiki Examples
*
* Contains tests built directly from examples given on the microformats wiki pages about µf2.
*
* These tend to compare the JSON-encoded output of Parser::parse() with the JSON strings given on the wiki.
* If the given JSON is not within an `items` key of the root object, I add it and mark as so.
*
* @author Barnaby Walters waterpigs.co.uk <barnaby@waterpigs.co.uk>
*/
class MicroformatsWikiExamplesTest extends TestCase {
protected function set_up() {
date_default_timezone_set('Europe/London');
}
public function testHandlesEmptyStringsCorrectly() {
$input = '';
$expected = '{
"rels": {},
"rel-urls": {},
"items": []
}';
$parser = new Parser($input, '', true);
$output = $parser->parse();
$this->assertJsonStringEqualsJsonString(json_encode($output), $expected);
}
public function testHandlesNullCorrectly() {
$input = Null;
$expected = '{
"rels": {},
"rel-urls": {},
"items": []
}';
$parser = new Parser($input, '', true);
$parser->jsonMode = true;
$output = $parser->parse();
$this->assertJsonStringEqualsJsonString(json_encode($output), $expected);
}
/**
* From https://microformats.org/wiki/microformats-2
*/
public function testSimplePersonReference() {
$input = '<span class="h-card">Frances Berriman</span>';
$expected = '{
"rels": {},
"rel-urls": {},
"items": [{
"type": ["h-card"],
"properties": {
"name": ["Frances Berriman"]
}
}]
}';
$parser = new Parser($input, '', true);
$output = $parser->parse();
$this->assertJsonStringEqualsJsonString(json_encode($output), $expected);
}
/**
* From https://microformats.org/wiki/microformats-2
*/
public function testSimpleHyperlinkedPersonReference() {
$input = '<a class="h-card" href="http://benward.me">Ben Ward</a>';
$expected = '{
"rels": {},
"rel-urls": {},
"items": [{
"type": ["h-card"],
"properties": {
"name": ["Ben Ward"],
"url": ["http://benward.me"]
}
}]
}';
$parser = new Parser($input, '', true);
$output = $parser->parse();
$this->assertJsonStringEqualsJsonString(json_encode($output), $expected);
}
/**
* From https://microformats.org/wiki/microformats-2-implied-properties
*/
public function testSimplePersonImage() {
$input = '<img class="h-card" src="http://example.com/pic.jpg" alt="Chris Messina" />';
// Added root items key
$expected = '{
"rels": {},
"rel-urls": {},
"items": [{
"type": ["h-card"],
"properties": {
"name": ["Chris Messina"],
"photo": [{
"value": "http://example.com/pic.jpg",
"alt": "Chris Messina"
}]
}
}]}';
$parser = new Parser($input, '', true);
$output = $parser->parse();
$this->assertJsonStringEqualsJsonString(json_encode($output), $expected);
}
/**
* From https://microformats.org/wiki/microformats-2-implied-properties
*/
public function testHyperlinkedImageNameAndPhotoProperties() {
$input = '<a class="h-card" href="http://rohit.khare.org/">
<img alt="Rohit Khare"
src="https://s3.amazonaws.com/twitter_production/profile_images/53307499/180px-Rohit-sq_bigger.jpg" />
</a>';
// Added root items key
$expected = '{
"rels": {},
"rel-urls": {},
"items": [{
"type": ["h-card"],
"properties": {
"name": ["Rohit Khare"],
"url": ["http://rohit.khare.org/"],
"photo": [{
"value": "https://s3.amazonaws.com/twitter_production/profile_images/53307499/180px-Rohit-sq_bigger.jpg",
"alt": "Rohit Khare"
}]
}
}]}';
$parser = new Parser($input, '', true);
$output = $parser->parse();
$this->assertJsonStringEqualsJsonString(json_encode($output), $expected);
}
/**
* From https://microformats.org/wiki/microformats-2
*/
public function testMoreDetailedPerson() {
$input = '<div class="h-card">
<img class="u-photo" alt="photo of Mitchell"
src="https://webfwd.org/content/about-experts/300.mitchellbaker/mentor_mbaker.jpg"/>
<a class="p-name u-url"
href="http://blog.lizardwrangler.com/"
>Mitchell Baker</a>
(<a class="u-url"
href="https://twitter.com/MitchellBaker"
>@MitchellBaker</a>)
<span class="p-org">Mozilla Foundation</span>
<p class="p-note">
Mitchell is responsible for setting the direction and scope of the Mozilla Foundation and its activities.
</p>
<span class="p-category">Strategy</span>
<span class="p-category">Leadership</span>
</div>';
$expected = '{
"rels": {},
"rel-urls": {},
"items": [{
"type": ["h-card"],
"properties": {
"photo": [
{
"value": "https://webfwd.org/content/about-experts/300.mitchellbaker/mentor_mbaker.jpg",
"alt": "photo of Mitchell"
}
],
"name": ["Mitchell Baker"],
"url": [
"http://blog.lizardwrangler.com/",
"https://twitter.com/MitchellBaker"
],
"org": ["Mozilla Foundation"],
"note": ["Mitchell is responsible for setting the direction and scope of the Mozilla Foundation and its activities."],
"category": [
"Strategy",
"Leadership"
]
}
}]
}';
$parser = new Parser($input, '', true);
$output = $parser->parse();
$this->assertJsonStringEqualsJsonString(json_encode($output), $expected);
}
}