@@ -81,22 +81,24 @@ public function testParsesImpliedUPhotoFromDoublyNestedImgSrc() {
81
81
$ this ->assertEquals ('http://example.com/img.png ' , $ output ['items ' ][0 ]['properties ' ]['photo ' ][0 ]);
82
82
}
83
83
84
+ /*
85
+ * see testImpliedPhotoFromNestedObject() and testImpliedPhotoFromNestedObject()
84
86
public function testIgnoresImgIfNotOnlyChild() {
85
87
$input = '<div class="h-card"><img src="http://example.com/img.png" /> <p>Moar text</p></div>';
86
88
$parser = new Parser($input);
87
89
$output = $parser->parse();
88
90
89
91
$this->assertArrayNotHasKey('photo', $output['items'][0]['properties']);
90
92
}
91
-
93
+
92
94
public function testIgnoresDoublyNestedImgIfNotOnlyDoublyNestedChild() {
93
95
$input = '<div class="h-card"><span><img src="http://example.com/img.png" /> <p>Moar text</p></span></div>';
94
96
$parser = new Parser($input);
95
97
$output = $parser->parse();
96
98
97
99
$this->assertArrayNotHasKey('photo', $output['items'][0]['properties']);
98
100
}
99
-
101
+ */
100
102
101
103
public function testParsesImpliedUUrlFromAHref () {
102
104
$ input = '<a class="h-card" href="http://example.com/">Some Name</a> ' ;
@@ -182,4 +184,73 @@ public function testParsesImpliedNameFromAbbrTitle() {
182
184
$ result = Mf2 \parse ($ input );
183
185
$ this ->assertEquals ('Barnaby Walters ' , $ result ['items ' ][0 ]['properties ' ]['name ' ][0 ]);
184
186
}
187
+
188
+ public function testImpliedPhotoFromObject () {
189
+ $ input = '<object class="h-card" data="http://example/photo1.jpg">John Doe</object> ' ;
190
+ $ result = Mf2 \parse ($ input );
191
+
192
+ $ this ->assertArrayHasKey ('photo ' , $ result ['items ' ][0 ]['properties ' ]);
193
+ $ this ->assertEquals ('http://example/photo1.jpg ' , $ result ['items ' ][0 ]['properties ' ]['photo ' ][0 ]);
194
+ }
195
+
196
+ /**
197
+ * Correcting previous test testIgnoresImgIfNotOnlyChild()
198
+ * This *should* return the photo since h-x>img[src]:only-of-type:not[.h-*]
199
+ * @see https://indiewebcamp.com/User:Tantek.com
200
+ */
201
+ public function testImpliedPhotoFromNestedImg () {
202
+ $ input = '<span class="h-card"><a href="http://tantek.com/" class="external text" style="border: 0px none;"><img src="https://pbs.twimg.com/profile_images/423350922408767488/nlA_m2WH.jpeg" style="width:128px;float:right;margin-left:1em"><b><span style="font-size:2em">Tantek Çelik</span></b></a></span> ' ;
203
+ $ result = Mf2 \parse ($ input );
204
+
205
+ $ this ->assertArrayHasKey ('photo ' , $ result ['items ' ][0 ]['properties ' ]);
206
+ $ this ->assertEquals ('https://pbs.twimg.com/profile_images/423350922408767488/nlA_m2WH.jpeg ' , $ result ['items ' ][0 ]['properties ' ]['photo ' ][0 ]);
207
+ }
208
+
209
+ public function testIgnoredPhotoIfMultipleImg () {
210
+ $ input = '<div class="h-card"><img src="http://example/photo2.jpg" /> <img src="http://example/photo3.jpg" /> </div> ' ;
211
+ $ result = Mf2 \parse ($ input );
212
+
213
+ $ this ->assertArrayNotHasKey ('photo ' , $ result ['items ' ][0 ]['properties ' ]);
214
+ }
215
+
216
+ /**
217
+ * Correcting previous test testIgnoresDoublyNestedImgIfNotOnlyDoublyNestedChild()
218
+ * This *should* return the photo since .h-x>object[data]:only-of-type:not[.h-*]
219
+ */
220
+ public function testImpliedPhotoFromNestedObject () {
221
+ $ input = '<div class="h-card"><object data="http://example/photo3.jpg">John Doe</object> <p>Moar text</p></div> ' ;
222
+ $ result = Mf2 \parse ($ input );
223
+
224
+ $ this ->assertArrayHasKey ('photo ' , $ result ['items ' ][0 ]['properties ' ]);
225
+ $ this ->assertEquals ('http://example/photo3.jpg ' , $ result ['items ' ][0 ]['properties ' ]['photo ' ][0 ]);
226
+ }
227
+
228
+ public function testIgnoredPhotoIfMultipleObject () {
229
+ $ input = '<div class="h-card"><object data="http://example/photo3.jpg">John Doe</object> <object data="http://example/photo4.jpg"></object> </div> ' ;
230
+ $ result = Mf2 \parse ($ input );
231
+
232
+ $ this ->assertArrayNotHasKey ('photo ' , $ result ['items ' ][0 ]['properties ' ]);
233
+ }
234
+
235
+ public function testIgnoredPhotoIfNestedImgH () {
236
+ $ input = '<div class="h-entry"> <img src="http://example/photo2.jpg" class="h-card" /> </div> ' ;
237
+ $ result = Mf2 \parse ($ input );
238
+
239
+ $ this ->assertArrayNotHasKey ('photo ' , $ result ['items ' ][0 ]['properties ' ]);
240
+ }
241
+
242
+ public function testIgnoredPhotoIfNestedImgHasHClass () {
243
+ $ input = '<div class="h-entry"> <img src="http://example/photo2.jpg" alt="John Doe" class="h-card" /> </div> ' ;
244
+ $ result = Mf2 \parse ($ input );
245
+
246
+ $ this ->assertArrayNotHasKey ('photo ' , $ result ['items ' ][0 ]['properties ' ]);
247
+ }
248
+
249
+ public function testIgnoredPhotoIfNestedObjectHasHClass () {
250
+ $ input = '<div class="h-entry"> <object data="http://example/photo3.jpg" class="h-card">John Doe</object> </div> ' ;
251
+ $ result = Mf2 \parse ($ input );
252
+
253
+ $ this ->assertArrayNotHasKey ('photo ' , $ result ['items ' ][0 ]['properties ' ]);
254
+ }
255
+
185
256
}
0 commit comments