diff --git a/lib/Microformats/Parser.php b/lib/Microformats/Parser.php index 2c7edff..7ca02c4 100644 --- a/lib/Microformats/Parser.php +++ b/lib/Microformats/Parser.php @@ -281,7 +281,7 @@ class Parser { } } # parse all hyperlink ( ) elements for rel microformats, adding to the JSON rels & rel-urls hashes accordingly - foreach ($this->xpath->query(".//a[@rel][@href]|.//area[@rel][@href]|.//link[@rel][@href]", $root) as $link) { + foreach ($this->xpath->query(".//a[@rel and @href and not(ancestor::template)]|.//area[@rel and @href and not(ancestor::template)]|.//link[@rel and @href and not(ancestor::template)]", $root) as $link) { # To parse a hyperlink element (e.g. a or link) for rel # microformats: use the following algorithm or an algorithm that # produces equivalent results: @@ -600,10 +600,6 @@ class Parser { if ($this->options['lang'] && ($lang = $this->getLang($root))) { $out['lang'] = $lang; } - // stop here if the root is a template, as all children of templates must be ignored - if ($root->localName === "template") { - return $out; - } // keep track of deferred properties ("use Y if X is not defined") $deferred = []; // keep track of the implied date diff --git a/tests/cases/StandardTest.php b/tests/cases/StandardTest.php index 2bf7f4e..6b2a7e1 100644 --- a/tests/cases/StandardTest.php +++ b/tests/cases/StandardTest.php @@ -65,24 +65,26 @@ class StandardTest extends \PHPUnit\Framework\TestCase { public function provideStandardTests(): \Generator { // the standard tests - yield from $this->provideTestList([\MensBeam\Microformats\BASE."vendor-bin/phpunit/vendor/mf2/tests/tests/"], ['simpleTrim' => true]); + yield from $this->provideTestList(\MensBeam\Microformats\BASE."vendor-bin/phpunit/vendor/mf2/tests/tests/", ['simpleTrim' => true]); // tests from php-mf2 - yield from $this->provideTestList([\MensBeam\Microformats\BASE."tests/cases/third-party/"], []); + yield from $this->provideTestList(\MensBeam\Microformats\BASE."tests/cases/third-party/", []); // tests from our own corpus - yield from $this->provideTestList([\MensBeam\Microformats\BASE."tests/cases/mensbeam/default-settings/"], []); - yield from $this->provideTestList([\MensBeam\Microformats\BASE."tests/cases/mensbeam/lang-true/"], ['lang' => true]); + yield from $this->provideTestList(\MensBeam\Microformats\BASE."tests/cases/mensbeam/default-settings/", []); + yield from $this->provideTestList(\MensBeam\Microformats\BASE."tests/cases/mensbeam/lang-true/", ['lang' => true]); + yield from $this->provideTestList(\MensBeam\Microformats\BASE."tests/cases/mensbeam/simpletrim-true/", ['simpleTrim' => true]); } - protected function provideTestList(array $tests, ?array $options = null): \Generator { - foreach ($tests as $base) { - $base = strtr($base, "\\", "/"); - foreach (new \RegexIterator(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($base )), '/\.json$/') as $file) { - $path = $file->getPathname(); - $path = preg_replace('/\.json$/', '', $path); - $name = strtr($path, "\\", "/"); - $name = str_replace(strtr($base, "\\", "/"), "", $name); - yield $name => [$name, $path, $options]; - } + protected function provideTestList(string $set, ?array $options = null): \Generator { + $base = strtr(\MensBeam\Microformats\BASE."tests/cases/", "\\", "/"); + if (strpos(strtr($set, "\\", "/"), $base,) !== 0) { + $base = strtr($set, "\\", "/"); + } + foreach (new \RegexIterator(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($set)), '/\.json$/') as $file) { + $path = $file->getPathname(); + $path = preg_replace('/\.json$/', '', $path); + $name = strtr($path, "\\", "/"); + $name = str_replace($base, "", $name); + yield $name => [$name, $path, $options]; } } @@ -118,9 +120,9 @@ class StandardTest extends \PHPUnit\Framework\TestCase { $this->fixDates($exp['items'][0]['properties']['bday']); $this->fixDates($exp['items'][0]['properties']['rev']); break; - case "phpmf2/classic/fberriman": - case "phpmf2/classic/mixedroots2": - case "phpmf2/classic/hentry-tag": + case "third-party/phpmf2/classic/fberriman": + case "third-party/phpmf2/classic/mixedroots2": + case "third-party/phpmf2/classic/hentry-tag": $this->fixDates($exp['items'][0]['properties']['published']); break; diff --git a/tests/cases/mensbeam/default-settings/template.html b/tests/cases/mensbeam/default-settings/template.html index cb1df8b..5cce343 100644 --- a/tests/cases/mensbeam/default-settings/template.html +++ b/tests/cases/mensbeam/default-settings/template.html @@ -46,14 +46,33 @@ - + - + + + +
+ TEST + +
+ + +
+ + I am + + the King! + +
diff --git a/tests/cases/mensbeam/default-settings/template.json b/tests/cases/mensbeam/default-settings/template.json index bca8804..488b4a7 100644 --- a/tests/cases/mensbeam/default-settings/template.json +++ b/tests/cases/mensbeam/default-settings/template.json @@ -69,6 +69,26 @@ "" ] } + }, + { + "type": [ + "h-test" + ], + "properties": { + "name": [ + "TEST" + ] + } + }, + { + "type": [ + "h-test" + ], + "properties": { + "name": [ + "I am the King!" + ] + } } ], "rels": {}, diff --git a/tests/cases/mensbeam/simpletrim-true/template.html b/tests/cases/mensbeam/simpletrim-true/template.html new file mode 100644 index 0000000..7c6ab1c --- /dev/null +++ b/tests/cases/mensbeam/simpletrim-true/template.html @@ -0,0 +1,6 @@ + +
+ + I am the King! + +
diff --git a/tests/cases/mensbeam/simpletrim-true/template.json b/tests/cases/mensbeam/simpletrim-true/template.json new file mode 100644 index 0000000..98fffbf --- /dev/null +++ b/tests/cases/mensbeam/simpletrim-true/template.json @@ -0,0 +1,16 @@ +{ + "items": [ + { + "type": [ + "h-test" + ], + "properties": { + "name": [ + "I am the King!" + ] + } + } + ], + "rels": {}, + "rel-urls": {} +}