@@ -899,6 +899,57 @@ public function testGetRootMfOnlyFindsValidElements() {
899899 $ this ->assertEquals ('h-vendor123-name ' , $ rootEls ->item (0 )->getAttribute ('class ' ));
900900 }
901901
902+ /**
903+ * @see https://github.com/microformats/php-mf2/issues/249
904+ */
905+ public function testInvalidRootsIgnored () {
906+ $ input = <<<EOF
907+ <div class=" h-5 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+ # `items` should have length=2
919+ $ this ->assertEquals (2 , count ($ output ['items ' ]));
920+
921+ # each should be an h-entry
922+ $ this ->assertEquals ('h-entry ' , $ output ['items ' ][0 ]['type ' ][0 ]);
923+ $ this ->assertEquals ('h-entry ' , $ output ['items ' ][1 ]['type ' ][0 ]);
924+ }
925+
926+ /**
927+ * @see https://github.com/microformats/php-mf2/issues/249
928+ */
929+ public function testInvalidNestedRootsIgnored () {
930+ $ input = <<<EOF
931+ <div class=" h-5 pt-2">
932+ <div class="p-4 h-entry">
933+ <a class="u-url" href="https://example.com/bar">bar </a>
934+ </div>
935+ <div class="p-4 h-entry">
936+ <a class="u-url" href="https://example.com/foo">foo</a>
937+ </div>
938+ <div class="p-4 h-5">
939+ <a class="u-url" href="https://example.com/baz">baz</a>
940+ </div>
941+ </div>
942+ EOF ;
943+ $ output = Mf2 \parse ($ input );
944+
945+ # `items` should have length=2
946+ $ this ->assertEquals (2 , count ($ output ['items ' ]));
947+
948+ # each should be an h-entry
949+ $ this ->assertEquals ('h-entry ' , $ output ['items ' ][0 ]['type ' ][0 ]);
950+ $ this ->assertEquals ('h-entry ' , $ output ['items ' ][1 ]['type ' ][0 ]);
951+ }
952+
902953 /**
903954 * @see https://github.com/microformats/php-mf2/issues/249
904955 */
0 commit comments