Added itemref support and test

The test also tests "src based tags" as can be seen in dataset name
This commit is contained in:
Yusuf Kandemir 2018-11-12 19:11:52 +03:00
parent e17ceac9ea
commit a5bfeb5ec5
4 changed files with 51 additions and 1 deletions

View File

@ -14,7 +14,11 @@ class MicrodataDOMElement extends \DOMElement
$tokens = $this->tokenizeAttribute('itemref');
foreach ($tokens as $token) {
// @todo Implement xpath query and get the first item
$references = $this->ownerDocument->xpath->query('//*[@id="'.$token.'"]');
if ($first = $references->item(0)) {
$pending[] = $first;
}
}
}

View File

@ -67,6 +67,9 @@ class MicrodataParserTest extends \PHPUnit\Framework\TestCase
'W3C Example' => [
$this->getTestData('W3C', 'source.html', 'result.json')
],
'Itemref & src based tags' => [
$this->getTestData('Itemref', 'source.html', 'result.json')
],
];
}

View File

@ -0,0 +1,20 @@
{
"items": [
{
"type": [ "http://n.whatwg.org/work" ],
"properties": {
"work": [ "http://blog.example.com/gallery/images/house.jpeg" ],
"title": [ "The house I found." ],
"license": [ "http://www.opensource.org/licenses/mit-license.php" ]
}
},
{
"type": [ "http://n.whatwg.org/work" ],
"properties": {
"work": [ "http://blog.example.com/gallery/images/mailbox.jpeg" ],
"title": [ "The mailbox." ],
"license": [ "http://www.opensource.org/licenses/mit-license.php" ]
}
}
]
}

View File

@ -0,0 +1,23 @@
<!-- URI: http://blog.example.com/gallery/ -->
<!DOCTYPE HTML>
<html>
<head>
<title>Photo gallery</title>
</head>
<body>
<h1>My photos</h1>
<figure itemscope itemtype="http://n.whatwg.org/work" itemref="licenses">
<img itemprop="work" src="images/house.jpeg" alt="A white house, boarded up, sits in a forest.">
<figcaption itemprop="title">The house I found.</figcaption>
</figure>
<figure itemscope itemtype="http://n.whatwg.org/work" itemref="licenses">
<img itemprop="work" src="images/mailbox.jpeg" alt="Outside the house is a mailbox. It has a leaflet inside.">
<figcaption itemprop="title">The mailbox.</figcaption>
</figure>
<footer>
<p id="licenses">All images licensed under the
<a itemprop="license" href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.
</p>
</footer>
</body>
</html>