Skip to content

Commit 5cbfdd4

Browse files
committed
add another test for multi-level recursive parsing
for #143
1 parent eaef6e7 commit 5cbfdd4

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

tests/Mf2/ParserTest.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,5 +642,59 @@ public function testChildObjects() {
642642
$this->assertEquals('Four', $output['items'][0]['children'][3]['properties']['name'][0]);
643643
}
644644

645+
646+
public function testMultiLevelRecursion() {
647+
$input = <<<END
648+
<html>
649+
<head>
650+
<title>Test</title>
651+
</head>
652+
<body>
653+
654+
<div class="h-feed">
655+
<a href="/author" class="p-author h-card">Author Name</a>
656+
657+
<ul>
658+
<li class="h-entry">
659+
<a href="/1" class="u-url p-name">One</a>
660+
</li>
661+
<li class="h-entry">
662+
<a href="/2" class="u-url p-name">Two</a>
663+
<ul>
664+
<li class="p-comment h-entry"><a href="/a" class="u-url p-name">Comment A</a></li>
665+
<li class="p-comment h-entry"><a href="/b" class="u-url p-name">Comment B</a></li>
666+
</ul>
667+
</li>
668+
<li class="h-entry">
669+
<a href="/3" class="u-url p-name">Three</a>
670+
<ul>
671+
<li class="h-entry"><a href="/c" class="u-url p-name">Comment C</a></li>
672+
<li class="h-entry"><a href="/d" class="u-url p-name">Comment D</a></li>
673+
</ul>
674+
</li>
675+
<li class="h-entry">
676+
<a href="/4" class="u-url p-name">Four</a>
677+
</li>
678+
</ul>
679+
</div>
680+
681+
</body>
682+
</html>
683+
END;
684+
$output = Mf2\parse($input);
685+
686+
$this->assertArrayHasKey('author', $output['items'][0]['properties']);
687+
$this->assertEquals('Author Name', $output['items'][0]['properties']['author'][0]['properties']['name'][0]);
688+
$this->assertCount(4, $output['items'][0]['children']);
689+
$this->assertEquals('One', $output['items'][0]['children'][0]['properties']['name'][0]);
690+
$this->assertEquals('Two', $output['items'][0]['children'][1]['properties']['name'][0]);
691+
$this->assertEquals('Comment A', $output['items'][0]['children'][1]['properties']['comment'][0]['properties']['name'][0]);
692+
$this->assertEquals('Comment B', $output['items'][0]['children'][1]['properties']['comment'][1]['properties']['name'][0]);
693+
$three = $output['items'][0]['children'][2];
694+
$this->assertEquals('Three', $three['properties']['name'][0]);
695+
$this->assertEquals('Comment C', $three['children'][0]['properties']['name'][0]);
696+
$this->assertEquals('Comment D', $three['children'][1]['properties']['name'][0]);
697+
$this->assertEquals('Four', $output['items'][0]['children'][3]['properties']['name'][0]);
698+
}
645699
}
646700

0 commit comments

Comments
 (0)