Commit 54d20837 authored by Barnaby Walters's avatar Barnaby Walters

Wrote failing test cases for #53

parent aaa1fc57
......@@ -191,7 +191,7 @@ function convertTimeFormat($time) {
preg_match('/(\d{1,2}):?(\d{2})?:?(\d{2})?(a\.?m\.?|p\.?m\.?)?/i', $time, $matches);
// if no am/pm specified
if ( empty($matches[4]) ) {
if (empty($matches[4])) {
return $time;
}
// else am/pm specified
......@@ -202,31 +202,27 @@ function convertTimeFormat($time) {
$hh = $matches[1];
// add 12 to the pm hours
if ( $meridiem == 'pm' && ($hh < 12) )
{
if ($meridiem == 'pm' && ($hh < 12)) {
$hh += 12;
}
$hh = str_pad($hh, 2, '0', STR_PAD_LEFT);
// minutes
$mm = ( empty($matches[2]) ) ? '00' : $matches[2];
$mm = (empty($matches[2]) ) ? '00' : $matches[2];
// seconds, only if supplied
if ( !empty($matches[3]) )
{
if (!empty($matches[3])) {
$ss = $matches[3];
}
if ( empty($ss) ) {
if (empty($ss)) {
return sprintf('%s:%s', $hh, $mm);
}
else {
return sprintf('%s:%s:%s', $hh, $mm, $ss);
}
}
}
/**
......
......@@ -86,4 +86,20 @@ class ParsePTest extends PHPUnit_Framework_TestCase {
$this->assertEquals('http://example.com', $result['items'][0]['properties']['url'][0]);
}
/**
* @see https://github.com/indieweb/php-mf2/issues/53
* @see http://microformats.org/wiki/microformats2-parsing#parsing_an_e-_property
*/
public function testConvertsNestedImgElementToAltOrSrc() {
$input = <<<EOT
<div class="h-entry">
<p class="p-name">The day I saw a <img alt="five legged elephant" src="/photos/five-legged-elephant.jpg" /></p>
<p class="p-summary">Blah blah <img alt="" src="/photos/five-legged-elephant.jpg" /></p>
</div>
EOT;
$result = Mf2\parse($input, 'http://waterpigs.co.uk/articles/five-legged-elephant');
$this->assertEquals('The day I saw a five legged elephant', $result['items'][0]['properties']['name'][0]);
$this->assertEquals('Blah blah blah http://waterpigs.co.uk/photos/five-legged-elephant.jpg', $result['items'][0]['properties']['summary'][0]);
}
}
......@@ -243,4 +243,18 @@ EOT;
$result = Mf2\parse('<template class="h-card"><span class="p-name">Tom Morris</span></template>');
$this->assertCount(0, $result['items']);
}
/**
* @see https://github.com/indieweb/php-mf2/issues/53
* @see http://microformats.org/wiki/microformats2-parsing#parsing_an_e-_property
*/
public function testConvertsNestedImgElementToAltOrSrc() {
$input = <<<EOT
<div class="h-entry">
<p class="e-content">It is a strange thing to see a <img alt="five legged elephant" src="/photos/five-legged-elephant.jpg" /></p>
</div>
EOT;
$result = Mf2\parse($input, 'http://waterpigs.co.uk/articles/five-legged-elephant');
$this->assertEquals('It is a strange thing to see a five legged elephant', $result['items'][0]['properties']['content'][0]['value']);
}
}
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