@@ -81,22 +81,24 @@ public function testParsesImpliedUPhotoFromDoublyNestedImgSrc() {
8181 $ this ->assertEquals ('http://example.com/img.png ' , $ output ['items ' ][0 ]['properties ' ]['photo ' ][0 ]);
8282 }
8383
84+ /*
85+ * see testImpliedPhotoFromNestedObject() and testImpliedPhotoFromNestedObject()
8486 public function testIgnoresImgIfNotOnlyChild() {
8587 $input = '<div class="h-card"><img src="http://example.com/img.png" /> <p>Moar text</p></div>';
8688 $parser = new Parser($input);
8789 $output = $parser->parse();
8890
8991 $this->assertArrayNotHasKey('photo', $output['items'][0]['properties']);
9092 }
91-
93+
9294 public function testIgnoresDoublyNestedImgIfNotOnlyDoublyNestedChild() {
9395 $input = '<div class="h-card"><span><img src="http://example.com/img.png" /> <p>Moar text</p></span></div>';
9496 $parser = new Parser($input);
9597 $output = $parser->parse();
9698
9799 $this->assertArrayNotHasKey('photo', $output['items'][0]['properties']);
98100 }
99-
101+ */
100102
101103 public function testParsesImpliedUUrlFromAHref () {
102104 $ input = '<a class="h-card" href="http://example.com/">Some Name</a> ' ;
@@ -182,4 +184,73 @@ public function testParsesImpliedNameFromAbbrTitle() {
182184 $ result = Mf2 \parse ($ input );
183185 $ this ->assertEquals ('Barnaby Walters ' , $ result ['items ' ][0 ]['properties ' ]['name ' ][0 ]);
184186 }
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+
185256}
0 commit comments