@@ -56,7 +56,7 @@ public function testNestedMicroformatPropertyNameWorks() {
5656 $ test = 'someclass p-location someotherclass u-author p-author ' ;
5757 $ actual = Mf2 \nestedMfPropertyNamesFromClass ($ test );
5858
59- $ this ->assertEquals ($ expected , $ actual );
59+ $ this ->assertEqualsCanonicalizing ($ expected , $ actual );
6060 }
6161
6262 public function testMicroformatNamesFromClassIgnoresPrefixesWithoutNames () {
@@ -898,5 +898,58 @@ public function testGetRootMfOnlyFindsValidElements() {
898898 $ this ->assertEquals (1 , count ($ rootEls ));
899899 $ this ->assertEquals ('h-vendor123-name ' , $ rootEls ->item (0 )->getAttribute ('class ' ));
900900 }
901+
902+ /**
903+ * @see https://github.com/microformats/php-mf2/issues/249
904+ */
905+ public function testInvalidNestedPropertiesIgnored1 () {
906+ $ input = <<<EOF
907+ <div class=" h-feed pt-2">
908+ <div class="p-4 h-entry">
909+ <a class="u-url" href="https://example.com/bar">bar </a>
910+ </div>
911+ <div class="p-4 h-entry">
912+ <a class="u-url" href="https://example.com/foo">foo</a>
913+ </div>
914+ </div>
915+ EOF ;
916+ $ output = Mf2 \parse ($ input );
917+
918+ # `properties` should be empty
919+ $ this ->assertEquals (0 , count ($ output ['items ' ][0 ]['properties ' ]));
920+
921+ # `children` should have length=2
922+ $ this ->assertArrayHasKey ('children ' , $ output ['items ' ][0 ]);
923+ $ this ->assertEquals (2 , count ($ output ['items ' ][0 ]['children ' ]));
924+
925+ # each child should be an h-entry
926+ $ this ->assertEquals ('h-entry ' , $ output ['items ' ][0 ]['children ' ][0 ]['type ' ][0 ]);
927+ $ this ->assertEquals ('h-entry ' , $ output ['items ' ][0 ]['children ' ][1 ]['type ' ][0 ]);
928+ }
929+
930+ /**
931+ * @see https://github.com/microformats/php-mf2/issues/246
932+ */
933+ public function testInvalidNestedPropertiesIgnored2 () {
934+ $ input = <<<EOF
935+ <article class="h-card">
936+ <h1> TITLE </h1>
937+ <img class="h-36 photo u-logo"
938+ alt="An example alt title"
939+ src="https://example.com/img.png"
940+ />
941+ <p class="h-21 u-nickname"> John Doe </p>
942+ </article>
943+ EOF ;
944+ $ output = Mf2 \parse ($ input );
945+
946+ # `properties` should have length=3
947+ $ this ->assertEquals (3 , count ($ output ['items ' ][0 ]['properties ' ]));
948+
949+ # should have these properties
950+ $ this ->assertArrayHasKey ('logo ' , $ output ['items ' ][0 ]['properties ' ]);
951+ $ this ->assertArrayHasKey ('nickname ' , $ output ['items ' ][0 ]['properties ' ]);
952+ $ this ->assertArrayHasKey ('name ' , $ output ['items ' ][0 ]['properties ' ]);
953+ }
901954}
902955
0 commit comments