Skip to content

Commit dd21b26

Browse files
committed
Fixed a problem with handeling the unknown child exception
1 parent 61d093f commit dd21b26

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

src/PHPHtmlParser/Dom/HtmlNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
namespace PHPHtmlParser\Dom;
33

4-
use PHPHtmlParser\Exceptions\UnkownChildTypeException;
4+
use PHPHtmlParser\Exceptions\UnknownChildTypeException;
55
use PHPHtmlParser\Exceptions\ChildNotFoundException;
66

77
class HtmlNode extends AbstractNode {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?php
22
namespace PHPHtmlParser\Exceptions;
33

4-
final class UnkownChildTypeException extends \Exception {}
4+
final class UnknownChildTypeException extends \Exception {}

tests/Node/HtmlTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use PHPHtmlParser\Dom\HtmlNode;
44
use PHPHtmlParser\Dom\TextNode;
5+
use PHPHtmlParser\Dom\MockNode;
56
use PHPHtmlParser\Dom\Tag;
67

78
class NodeHtmlTest extends PHPUnit_Framework_TestCase {
@@ -65,6 +66,39 @@ public function testInnerHtmlTwice()
6566
$this->assertEquals($inner, $parent->innerHtml());
6667
}
6768

69+
/**
70+
* @expectedException PHPHtmlParser\Exceptions\UnknownChildTypeException
71+
*/
72+
public function testInnerHtmlUnkownChild()
73+
{
74+
$div = new Tag('div');
75+
$div->setAttributes([
76+
'class' => [
77+
'value' => 'all',
78+
'doubleQuote' => true,
79+
],
80+
]);
81+
$a = new Tag('a');
82+
$a->setAttributes([
83+
'href' => [
84+
'value' => 'http://google.com',
85+
'doubleQuote' => false,
86+
],
87+
]);
88+
$br = new Tag('br');
89+
$br->selfClosing();
90+
91+
$parent = new HtmlNode($div);
92+
$childa = new HtmlNode($a);
93+
$childbr = new MockNode($br);
94+
$parent->addChild($childa);
95+
$parent->addChild($childbr);
96+
$childa->addChild(new TextNode('link'));
97+
98+
$inner = $parent->innerHtml();
99+
$this->assertEquals($inner, $parent->innerHtml());
100+
}
101+
68102
public function testInnerHtmlMagic()
69103
{
70104
$parent = new HtmlNode('div');

0 commit comments

Comments
 (0)