Added itemref support and test
The test also tests "src based tags" as can be seen in dataset name
This commit is contained in:
parent
e17ceac9ea
commit
a5bfeb5ec5
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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')
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
20
tests/data/Itemref/result.json
Normal file
20
tests/data/Itemref/result.json
Normal 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" ]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
23
tests/data/Itemref/source.html
Normal file
23
tests/data/Itemref/source.html
Normal 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>
|
Loading…
Reference in New Issue
Block a user