@@ -56,7 +56,7 @@ public function testNestedMicroformatPropertyNameWorks() {
56
56
$ test = 'someclass p-location someotherclass u-author p-author ' ;
57
57
$ actual = Mf2 \nestedMfPropertyNamesFromClass ($ test );
58
58
59
- $ this ->assertEquals ($ expected , $ actual );
59
+ $ this ->assertEqualsCanonicalizing ($ expected , $ actual );
60
60
}
61
61
62
62
public function testMicroformatNamesFromClassIgnoresPrefixesWithoutNames () {
@@ -914,5 +914,109 @@ public function testNewlineBeforePrefix() {
914
914
$ this ->assertEquals ('Page Title ' , $ result ['items ' ][0 ]['properties ' ]['name ' ][0 ]);
915
915
$ this ->assertEquals ('A summary so the p-name won \'t be implied. This test demonstrates p-name is not being parsed. ' , $ result ['items ' ][0 ]['properties ' ]['summary ' ][0 ]);
916
916
}
917
+
918
+ /**
919
+ * @see https://github.com/microformats/php-mf2/issues/249
920
+ */
921
+ public function testInvalidRootsIgnored () {
922
+ $ input = <<<EOF
923
+ <div class=" h-5 pt-2">
924
+ <div class="p-4 h-entry">
925
+ <a class="u-url" href="https://example.com/bar">bar </a>
926
+ </div>
927
+ <div class="p-4 h-entry">
928
+ <a class="u-url" href="https://example.com/foo">foo</a>
929
+ </div>
930
+ </div>
931
+ EOF ;
932
+ $ output = Mf2 \parse ($ input );
933
+
934
+ # `items` should have length=2
935
+ $ this ->assertEquals (2 , count ($ output ['items ' ]));
936
+
937
+ # each should be an h-entry
938
+ $ this ->assertEquals ('h-entry ' , $ output ['items ' ][0 ]['type ' ][0 ]);
939
+ $ this ->assertEquals ('h-entry ' , $ output ['items ' ][1 ]['type ' ][0 ]);
940
+ }
941
+
942
+ /**
943
+ * @see https://github.com/microformats/php-mf2/issues/249
944
+ */
945
+ public function testInvalidNestedRootsIgnored () {
946
+ $ input = <<<EOF
947
+ <div class=" h-5 pt-2">
948
+ <div class="p-4 h-entry">
949
+ <a class="u-url" href="https://example.com/bar">bar </a>
950
+ </div>
951
+ <div class="p-4 h-entry">
952
+ <a class="u-url" href="https://example.com/foo">foo</a>
953
+ </div>
954
+ <div class="p-4 h-5">
955
+ <a class="u-url" href="https://example.com/baz">baz</a>
956
+ </div>
957
+ </div>
958
+ EOF ;
959
+ $ output = Mf2 \parse ($ input );
960
+
961
+ # `items` should have length=2
962
+ $ this ->assertEquals (2 , count ($ output ['items ' ]));
963
+
964
+ # each should be an h-entry
965
+ $ this ->assertEquals ('h-entry ' , $ output ['items ' ][0 ]['type ' ][0 ]);
966
+ $ this ->assertEquals ('h-entry ' , $ output ['items ' ][1 ]['type ' ][0 ]);
967
+ }
968
+
969
+ /**
970
+ * @see https://github.com/microformats/php-mf2/issues/249
971
+ */
972
+ public function testInvalidNestedPropertiesIgnored1 () {
973
+ $ input = <<<EOF
974
+ <div class=" h-feed pt-2">
975
+ <div class="p-4 h-entry">
976
+ <a class="u-url" href="https://example.com/bar">bar </a>
977
+ </div>
978
+ <div class="p-4 h-entry">
979
+ <a class="u-url" href="https://example.com/foo">foo</a>
980
+ </div>
981
+ </div>
982
+ EOF ;
983
+ $ output = Mf2 \parse ($ input );
984
+
985
+ # `properties` should be empty
986
+ $ this ->assertEquals (0 , count ($ output ['items ' ][0 ]['properties ' ]));
987
+
988
+ # `children` should have length=2
989
+ $ this ->assertArrayHasKey ('children ' , $ output ['items ' ][0 ]);
990
+ $ this ->assertEquals (2 , count ($ output ['items ' ][0 ]['children ' ]));
991
+
992
+ # each child should be an h-entry
993
+ $ this ->assertEquals ('h-entry ' , $ output ['items ' ][0 ]['children ' ][0 ]['type ' ][0 ]);
994
+ $ this ->assertEquals ('h-entry ' , $ output ['items ' ][0 ]['children ' ][1 ]['type ' ][0 ]);
995
+ }
996
+
997
+ /**
998
+ * @see https://github.com/microformats/php-mf2/issues/246
999
+ */
1000
+ public function testInvalidNestedPropertiesIgnored2 () {
1001
+ $ input = <<<EOF
1002
+ <article class="h-card">
1003
+ <h1> TITLE </h1>
1004
+ <img class="h-36 photo u-logo"
1005
+ alt="An example alt title"
1006
+ src="https://example.com/img.png"
1007
+ />
1008
+ <p class="h-21 u-nickname"> John Doe </p>
1009
+ </article>
1010
+ EOF ;
1011
+ $ output = Mf2 \parse ($ input );
1012
+
1013
+ # `properties` should have length=3
1014
+ $ this ->assertEquals (3 , count ($ output ['items ' ][0 ]['properties ' ]));
1015
+
1016
+ # should have these properties
1017
+ $ this ->assertArrayHasKey ('logo ' , $ output ['items ' ][0 ]['properties ' ]);
1018
+ $ this ->assertArrayHasKey ('nickname ' , $ output ['items ' ][0 ]['properties ' ]);
1019
+ $ this ->assertArrayHasKey ('name ' , $ output ['items ' ][0 ]['properties ' ]);
1020
+ }
917
1021
}
918
1022
0 commit comments