Commit 6bceeb49 authored by Barnaby Walters's avatar Barnaby Walters

Multiple-property nested microformats parsed correctly. Closes #42 (insert...

Multiple-property nested microformats parsed correctly. Closes #42 (insert obilgatory HGTTG reference here)

* Fixed implementation and tests for nestedMfPropertyNamesForClass()
* Both regression tests now passing
parent 28bd4d50
......@@ -106,19 +106,21 @@ function mfNamesFromClass($class, $prefix = 'h-') {
* space-separated string.
*
* @param string $class
* @return string|null
* @return array
*/
function nestedMfPropertyNamesFromClass($class) {
$prefixes = array(' p-', ' u-', ' dt-', ' e-');
$propertyNames = array();
foreach (explode(' ', $class) as $classname) {
foreach ($prefixes as $prefix) {
if (stristr(' ' . $classname, $prefix))
return mfNamesFromClass($classname, ltrim($prefix));
if (stristr(' ' . $classname, $prefix)) {
$propertyNames = array_merge($propertyNames, mfNamesFromClass($classname, ltrim($prefix)));
}
}
}
return null;
return $propertyNames;
}
/**
......
......@@ -3,6 +3,7 @@
namespace Mf2\Parser\Test;
use Mf2\Parser;
use Mf2;
use PHPUnit_Framework_TestCase;
/**
......@@ -199,7 +200,7 @@ class CombinedMicroformatsTest extends PHPUnit_Framework_TestCase {
},
"value": "Mozilla Foundation"
}]
}]
}]
}';
$parser = new Parser($input, '', true);
......@@ -207,5 +208,18 @@ class CombinedMicroformatsTest extends PHPUnit_Framework_TestCase {
$this->assertJsonStringEqualsJsonString(json_encode($output), $expected);
}
/**
* Regression test for https://github.com/indieweb/php-mf2/issues/42
*
* This was occurring because mfPropertyNamesFromClass was only ever returning the first property name
* rather than all of them.
*/
public function testNestedMicroformatUnderMultipleProperties() {
$input = '<article class="h-entry"><div class="p-like-of p-in-reply-to h-cite"></div></article>';
$mf = Mf2\parse($input);
$this->assertCount(1, $mf['items'][0]['properties']['like-of']);
$this->assertCount(1, $mf['items'][0]['properties']['in-reply-to']);
}
}
......@@ -48,8 +48,8 @@ class ParserTest extends PHPUnit_Framework_TestCase {
}
public function testNestedMicroformatPropertyNameWorks() {
$expected = array('location');
$test = 'someclass p-location someotherclass';
$expected = array('location', 'author');
$test = 'someclass p-location someotherclass u-author';
$actual = Mf2\nestedMfPropertyNamesFromClass($test);
$this->assertEquals($actual, $expected);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment