Browse Source

Improve coverage

master
J. King 11 months ago
parent
commit
f7c0574d0d
  1. 8
      lib/Microformats/Parser.php
  2. 10
      tests/cases/mensbeam/default-settings/implied.html
  3. 19
      tests/cases/mensbeam/default-settings/implied.json
  4. 17
      tests/cases/mensbeam/default-settings/u-property.html
  5. 58
      tests/cases/mensbeam/default-settings/u-property.json
  6. 84
      tests/cases/third-party/phpmf2/implied.html
  7. 593
      tests/cases/third-party/phpmf2/implied.json

8
lib/Microformats/Parser.php

@ -875,10 +875,8 @@ class Parser {
// we have encountered a tag relation during backcompat processing
// https://microformats.org/wiki/rel-tag#Abstract
// we are required to retrieve the last component of the URL path and use that
if (preg_match('#([^/]*)/?$#', URL::fromString($this->normalizeUrl($node->getAttribute("href")))->getPath(), $match)) {
return urldecode($match[1]);
}
return "";
preg_match('#([^/]*)/?$#', URL::fromString($this->normalizeUrl($node->getAttribute("href")))->getPath(), $match);
return urldecode($match[1]);
}
# else return the textContent of the element after [cleaning]
return $this->getCleanText($node, $prefix);
@ -974,7 +972,7 @@ class Parser {
}
return $out;
default:
throw new \Exception("Unimplemented prefix $prefix");
throw new \Exception("Unimplemented prefix $prefix"); // @codeCoverageIgnore
}
}

10
tests/cases/mensbeam/default-settings/implied.html

@ -0,0 +1,10 @@
<!--
Despite two corpuses having tests for implied properties, one case is still
not covered except by this test.
-->
<div class="h-card">
<span>
<a href="me.html">C'est moi!</a>
</span>
</div>

19
tests/cases/mensbeam/default-settings/implied.json

@ -0,0 +1,19 @@
{
"items": [
{
"type": [
"h-card"
],
"properties": {
"name": [
"C'est moi!"
],
"url": [
"http://example.com/me.html"
]
}
}
],
"rels": {},
"rel-urls": {}
}

17
tests/cases/mensbeam/default-settings/u-property.html

@ -0,0 +1,17 @@
<div class="h-entry">
<video class="u-url" src="audio.flac"></video>
</div>
<div class="h-entry">
<video class="u-url" src="video.mkv"></video>
</div>
<div class="h-entry">
<video>
<source class="u-url" src="video.mkv"></source
</video>
</div>
<div class="h-entry">
<iframe class="u-url" src="content.html"></iframe>
</div>

58
tests/cases/mensbeam/default-settings/u-property.json

@ -0,0 +1,58 @@
{
"rels": {},
"rel-urls": {},
"items": [
{
"type": [
"h-entry"
],
"properties": {
"url": [
"http://example.com/audio.flac"
],
"name": [
""
]
}
},
{
"type": [
"h-entry"
],
"properties": {
"url": [
"http://example.com/video.mkv"
],
"name": [
""
]
}
},
{
"type": [
"h-entry"
],
"properties": {
"url": [
"http://example.com/video.mkv"
],
"name": [
""
]
}
},
{
"type": [
"h-entry"
],
"properties": {
"url": [
"http://example.com/content.html"
],
"name": [
""
]
}
}
]
}

84
tests/cases/third-party/phpmf2/implied.html

@ -0,0 +1,84 @@
<!--
This collects all of php-mf2's ParseImpliedTest.php into one test.
-->
<span class="h-card">The Name</span>
<img class="h-card" src="" alt="The Name" />
<div class="h-card"><img src="" alt="The Name" /></div>
<div class="h-card"><span><img src="" alt="The Name" /></span></div>
<img class="h-card" src="http://example.com/img.png" />
<img class="h-card" src="http://example.com/img.png" alt="" />
<img class="h-card" src="http://example.com/img.png" alt="Example" />
<div class="h-card"><img src="http://example.com/img.png" alt="" /></div>
<div class="h-card"><span><img src="http://example.com/img.png" alt="" /></span></div>
<a class="h-card" href="http://example.com/">Some Name</a>
<span class="h-card"><a href="http://example.com/">Some Name</a></span>
<span class="h-card"><a href="http://example.com/" class="p-name">Some Name</a></span>
<span class="h-card"><a href="http://example.com/" class="u-url">Some Name</a></span>
<span class="h-card">Frances Berriman</span>
<a class="h-card" href="http://benward.me">Ben Ward</a>
<img class="h-card" alt="Sally Ride"
src="http://upload.wikimedia.org/wikipedia/commons/a/a4/Ride-s.jpg"/>
<a class="h-card" href="http://tantek.com">
<img alt="Tantek Çelik" src="http://ttk.me/logo.jpg"/>
</a>
<span class="h-card"> Name
and more </span><span class="h-card"><span class="p-name"> Name
and more </span></span>
<abbr class="h-card" title="Barnaby Walters">BJW</abbr>
<object class="h-card" data="http://example/photo1.jpg">John Doe</object>
<span class="h-card"><a href="http://tantek.com/" class="external text" style="border: 0px none;"><img src="https://pbs.twimg.com/profile_images/423350922408767488/nlA_m2WH.jpeg" style="width:128px;float:right;margin-left:1em"><b><span style="font-size:2em">Tantek Çelik</span></b></a></span>
<!-- php-mf2 gets this one wrong -->
<div class="h-card"><img src="http://example/photo2.jpg" /> <img src="http://example/photo3.jpg" /> </div>
<div class="h-card"><object data="http://example/photo3.jpg">John Doe</object> <p>Moar text</p></div>
<div class="h-card"><object data="http://example/photo3.jpg">John Doe</object> <object data="http://example/photo4.jpg"></object> </div>
<div class="h-entry"> <img src="http://example/photo2.jpg" class="h-card" /> </div>
<div class="h-entry"> <img src="http://example/photo2.jpg" alt="John Doe" class="h-card" /> </div>
<div class="h-entry"> <object data="http://example/photo3.jpg" class="h-card">John Doe</object> </div>
<!-- php-mf2 gets this one wrong -->
<div class="h-entry"> <div class="u-comment h-cite"> <img src="/image.jpg"> </div> </div>
<div class="h-entry"> <div class="u-comment h-cite"> <object data="/image2.jpg">John Doe</object> </div> </div>
<div class="h-card"> <a href="https://example.com"><img src="https://example.com/photo.jpg"></a> <span class="p-name"><a href="/User:Example.com">Max Mustermann</a></span> </div>
<div class="h-card"> <a href="https://example.com"><object data="https://example.com/photo.jpg"></object></a> <span class="p-name"><a href="/User:Example.com">Max Mustermann</a></span> </div>
<div class="hentry"> <div class="entry-content"> <p> blah blah blah </p> </div> </div>
<div class="hentry"> <img src="https://example.com/photo.jpg" alt="photo" /> </div>
<div class="hentry"> <a href="https://example.com/this-post" class="entry-title">Title</a> <div class="entry-content"> <p> blah blah blah </p> </div> </div>
<div class="h-entry"> <h1 class="p-name"><a href="https://example.com/this-post">Title</a></h1> <div class="e-content"> <p> blah blah blah </p> </div> <a href="https://example.org/syndicate" class="u-syndication"></a> </div>
<!-- php-mf2 gets this one wrong -->
<p class="h-card">My Name <img src="http://xyz" /></p>
<div class="h-card"> <span class="p-org">Organization Name</span> <img src="/logo.png" class="u-logo" alt=""> </div>
<div class="h-entry"> <img src="/photo.jpg" alt=""> <div class="p-author h-card"> <span class="p-name">Alice</span> <span class="p-org">Organization Name</span> <img src="/logo.png" class="u-logo" alt=""> </div> </div>

593
tests/cases/third-party/phpmf2/implied.json

@ -0,0 +1,593 @@
{
"items": [
{
"type": [
"h-card"
],
"properties": {
"name": [
"The Name"
]
}
},
{
"type": [
"h-card"
],
"properties": {
"name": [
"The Name"
],
"photo": [
{
"value": "http://example.com/",
"alt": "The Name"
}
]
}
},
{
"type": [
"h-card"
],
"properties": {
"name": [
"The Name"
],
"photo": [
{
"value": "http://example.com/",
"alt": "The Name"
}
]
}
},
{
"type": [
"h-card"
],
"properties": {
"name": [
"The Name"
],
"photo": [
{
"value": "http://example.com/",
"alt": "The Name"
}
]
}
},
{
"type": [
"h-card"
],
"properties": {
"name": [
""
],
"photo": [
"http://example.com/img.png"
]
}
},
{
"type": [
"h-card"
],
"properties": {
"name": [
""
],
"photo": [
{
"value": "http://example.com/img.png",
"alt": ""
}
]
}
},
{
"type": [
"h-card"
],
"properties": {
"name": [
"Example"
],
"photo": [
{
"value": "http://example.com/img.png",
"alt": "Example"
}
]
}
},
{
"type": [
"h-card"
],
"properties": {
"name": [
""
],
"photo": [
{
"value": "http://example.com/img.png",
"alt": ""
}
]
}
},
{
"type": [
"h-card"
],
"properties": {
"name": [
""
],
"photo": [
{
"value": "http://example.com/img.png",
"alt": ""
}
]
}
},
{
"type": [
"h-card"
],
"properties": {
"name": [
"Some Name"
],
"url": [
"http://example.com/"
]
}
},
{
"type": [
"h-card"
],
"properties": {
"name": [
"Some Name"
],
"url": [
"http://example.com/"
]
}
},
{
"type": [
"h-card"
],
"properties": {
"name": [
"Some Name"
],
"url": [
"http://example.com/"
]
}
},
{
"type": [
"h-card"
],
"properties": {
"url": [
"http://example.com/"
],
"name": [
"Some Name"
]
}
},
{
"type": [
"h-card"
],
"properties": {
"name": [
"Frances Berriman"
]
}
},
{
"type": [
"h-card"
],
"properties": {
"name": [
"Ben Ward"
],
"url": [
"http://benward.me"
]
}
},
{
"type": [
"h-card"
],
"properties": {
"name": [
"Sally Ride"
],
"photo": [
{
"value": "http://upload.wikimedia.org/wikipedia/commons/a/a4/Ride-s.jpg",
"alt": "Sally Ride"
}
]
}
},
{
"type": [
"h-card"
],
"properties": {
"name": [
"Tantek \u00c7elik"
],
"photo": [
{
"value": "http://ttk.me/logo.jpg",
"alt": "Tantek \u00c7elik"
}
],
"url": [
"http://tantek.com"
]
}
},
{
"type": [
"h-card"
],
"properties": {
"name": [
"Name and more"
]
}
},
{
"type": [
"h-card"
],
"properties": {
"name": [
"Name and more"
]
}
},
{
"type": [
"h-card"
],
"properties": {
"name": [
"Barnaby Walters"
]
}
},
{
"type": [
"h-card"
],
"properties": {
"name": [
"John Doe"
],
"photo": [
"http://example/photo1.jpg"
]
}
},
{
"type": [
"h-card"
],
"properties": {
"name": [
"https://pbs.twimg.com/profile_images/423350922408767488/nlA_m2WH.jpeg Tantek \u00c7elik"
],
"photo": [
"https://pbs.twimg.com/profile_images/423350922408767488/nlA_m2WH.jpeg"
],
"url": [
"http://tantek.com/"
]
}
},
{
"type": [
"h-card"
],
"properties": {
"name": [
"http://example/photo2.jpg http://example/photo3.jpg"
]
}
},
{
"type": [
"h-card"
],
"properties": {
"name": [
"John Doe\nMoar text"
],
"photo": [
"http://example/photo3.jpg"
]
}
},
{
"type": [
"h-card"
],
"properties": {
"name": [
"John Doe"
]
}
},
{
"type": [
"h-entry"
],
"properties": {},
"children": [
{
"type": [
"h-card"
],
"properties": {
"name": [
""
],
"photo": [
"http://example/photo2.jpg"
]
}
}
]
},
{
"type": [
"h-entry"
],
"properties": {},
"children": [
{
"type": [
"h-card"
],
"properties": {
"name": [
"John Doe"
],
"photo": [
{
"value": "http://example/photo2.jpg",
"alt": "John Doe"
}
]
}
}
]
},
{
"type": [
"h-entry"
],
"properties": {},
"children": [
{
"type": [
"h-card"
],
"properties": {
"name": [
"John Doe"
],
"photo": [
"http://example/photo3.jpg"
]
}
}
]
},
{
"type": [
"h-entry"
],
"properties": {
"comment": [
{
"type": [
"h-cite"
],
"properties": {
"name": [
"http://example.com/image.jpg"
],
"photo": [
"http://example.com/image.jpg"
]
},
"value": "http://example.com/image.jpg"
}
]
}
},
{
"type": [
"h-entry"
],
"properties": {
"comment": [
{
"type": [
"h-cite"
],
"properties": {
"name": [
"John Doe"
],
"photo": [
"http://example.com/image2.jpg"
]
},
"value": "http://example.com/John%20Doe"
}
]
}
},
{
"type": [
"h-card"
],
"properties": {
"name": [
"Max Mustermann"
],
"url": [
"https://example.com"
]
}
},
{
"type": [
"h-card"
],
"properties": {
"name": [
"Max Mustermann"
],
"url": [
"https://example.com"
]
}
},
{
"type": [
"h-entry"
],
"properties": {
"content": [
{
"html": "<p> blah blah blah </p>",
"value": "blah blah blah"
}
]
}
},
{
"type": [
"h-entry"
],
"properties": {}
},
{
"type": [
"h-entry"
],
"properties": {
"name": [
"Title"
],
"content": [
{
"html": "<p> blah blah blah </p>",
"value": "blah blah blah"
}
]
}
},
{
"type": [
"h-entry"
],
"properties": {
"name": [
"Title"
],
"syndication": [
"https://example.org/syndicate"
],
"content": [
{
"html": "<p> blah blah blah </p>",
"value": "blah blah blah"
}
]
}
},
{
"type": [
"h-card"
],
"properties": {
"name": [
"My Name http://xyz/"
],
"photo": [
"http://xyz/"
]
}
},
{
"type": [
"h-card"
],
"properties": {
"org": [
"Organization Name"
],
"logo": [
{
"value": "http://example.com/logo.png",
"alt": ""
}
]
}
},
{
"type": [
"h-entry"
],
"properties": {
"author": [
{
"type": [
"h-card"
],
"properties": {
"name": [
"Alice"
],
"org": [
"Organization Name"
],
"logo": [
{
"value": "http://example.com/logo.png",
"alt": ""
}
]
},
"value": "Alice"
}
]
}
}
],
"rels": {},
"rel-urls": {}
}
Loading…
Cancel
Save