Permalink
Browse files

Added test for hfeed hentry hAtom conversion, fixed bug in which erro…

…rs are caused by non-replaced classnames
  • Loading branch information...
1 parent 46589a5 commit 20e87852547175999e19784c97f547ac4c3f1866 @barnabywalters barnabywalters committed Jan 21, 2013
Showing with 59 additions and 22 deletions.
  1. +2 −2 mf2/Parser.php
  2. +57 −20 tests/mf2/ClassicMicroformatsTest.php
View
@@ -556,8 +556,8 @@ public function convertClassic($text) {
foreach ($classnames as $key => $class) {
// If there’s a replacement, replace it
- if (($mf2Class = $map[$class]) != '')
- $classnames[$key] = $mf2Class;
+ if (isset($map[$class]))
+ $classnames[$key] = $map[$class];
}
// Rebuild and return
@@ -1,4 +1,5 @@
<?php
+
/**
* Tests of the parsing methods within mf2\Parser
*/
@@ -8,9 +9,9 @@
// Include Parser.php
$autoloader = require_once dirname(__DIR__) . '/../mf2/Parser.php';
-use mf2\Parser,
- PHPUnit_Framework_TestCase,
- DateTime;
+use mf2\Parser;
+use PHPUnit_Framework_TestCase;
+use DateTime;
/**
* Classic Microformats Test
@@ -19,25 +20,61 @@
*
* Mainly based off BC tables on http://microformats.org/wiki/microformats2#v2_vocabularies
*/
-class ClassicMicroformatsTest extends PHPUnit_Framework_TestCase
-{
- public function setUp()
- {
- date_default_timezone_set('Europe/London');
- }
-
- public function testConvertClassic()
- {
- $input = '<div class="vcard">
+class ClassicMicroformatsTest extends PHPUnit_Framework_TestCase {
+
+ public function setUp() {
+ date_default_timezone_set('Europe/London');
+ }
+
+ public function testConvertClassicVCard() {
+ $input = '<div class="vcard">
<a class="url fn" href="http://tantek.com/">Tantek Çelik</a>
</div>';
- $expected = '<div class="h-card">
+ $expected = '<div class="h-card">
<a class="u-url p-name" href="http://tantek.com/">Tantek Çelik</a>
</div>';
-
- $parser = new Parser('');
- $converted = $parser->convertClassic($input);
-
- $this -> assertEquals($expected, $converted);
- }
+
+ $parser = new Parser('');
+ $converted = $parser->convertClassic($input);
+
+ $this->assertEquals($expected, $converted);
+ }
+
+ public function testConvertsClassicHAtom() {
+ $input = '<div class="hfeed">
+ <p class="p-name">problem preventer</p>
+ <div class="hentry">
+ <h1 class="entry-title">The Title</h1>
+ <p class="entry-summary">This is the summary</p>
+ <div class="entry-content"><p>Some content</p></div>
+ </div>
+</div>';
+
+ $expected = [
+ 'items' => [
+ [
+ 'type' => ['h-feed'],
+ 'properties' => [
+ 'name' => ['problem preventer']
+ ],
+ 'children' => [
+ [
+ 'type' => ['h-entry'],
+ 'properties' => [
+ 'name' => ['The Title'],
+ 'summary' => ['This is the summary'],
+ 'content' => ['<p>Some content</p>']
+ ]
+ ]
+ ]
+ ]
+ ]
+ ];
+
+ $parser = new Parser($input, null, true);
+ $parsed = $parser->parse();
+
+ $this->assertEquals($expected, $parsed);
+ }
+
}

0 comments on commit 20e8785

Please sign in to comment.