load('

Hey bro, click here
:)

'); $div = $dom->find('div', 0); $this->assertEquals('

Hey bro, click here
:)

', $div->outerHtml); } /** * @expectedException PHPHtmlParser\Exceptions\NotLoadedException */ public function testNotLoaded() { $dom = new Dom; $div = $dom->find('div', 0); } public function testIncorrectAccess() { $dom = new Dom; $dom->load('

Hey bro, click here
:)

'); $div = $dom->find('div', 0); $this->assertEquals(null, $div->foo); } public function testLoadSelfclosingAttr() { $dom = new Dom; $dom->load("

baz
"); $br = $dom->find('br', 0); $this->assertEquals('
', $br->outerHtml); } public function testLoadSelfclosingAttrToString() { $dom = new Dom; $dom->load("

baz
"); $br = $dom->find('br', 0); $this->assertEquals('
', (string) $br); } public function testLoadEscapeQuotes() { $dom = new Dom; $dom->load('

Hey bro, click here

'); $div = $dom->find('div', 0); $this->assertEquals('

Hey bro, click here

', $div->outerHtml); } public function testLoadNoOpeningTag() { $dom = new Dom; $dom->load('
PR Manager
content
'); $this->assertEquals('content', $dom->find('.content', 0)->text); } public function testLoadNoClosingTag() { $dom = new Dom; $dom->load('

Hey bro, click here


'); $root = $dom->find('div', 0)->getParent(); $this->assertEquals('

Hey bro, click here


', $root->outerHtml); } public function testLoadAttributeOnSelfClosing() { $dom = new Dom; $dom->load('

Hey bro, click here


'); $br = $dom->find('br', 0); $this->assertEquals('both', $br->getAttribute('class')); } public function testLoadClosingTagOnSelfClosing() { $dom = new Dom; $dom->load('

Hey bro, click here

'); $this->assertEquals('

Hey bro, click here

', $dom->find('div', 0)->innerHtml); } public function testLoadClosingTagAddSelfClosingTag() { $dom = new Dom; $dom->addSelfClosingTag('mytag'); $dom->load('

Hey bro, click here

'); $this->assertEquals('

Hey bro, click here

', $dom->find('div', 0)->innerHtml); } public function testLoadClosingTagAddSelfClosingTagArray() { $dom = new Dom; $dom->addSelfClosingTag([ 'mytag', 'othertag' ]); $dom->load('

Hey bro, click here

'); $this->assertEquals('

Hey bro, click here

', $dom->find('div', 0)->innerHtml); } public function testLoadClosingTagRemoveSelfClosingTag() { $dom = new Dom; $dom->removeSelfClosingTag('br'); $dom->load('

Hey bro, click here

'); $this->assertEquals('

Hey bro, click here


', $dom->find('div', 0)->innerHtml); } public function testLoadClosingTagClearSelfClosingTag() { $dom = new Dom; $dom->clearSelfClosingTags(); $dom->load('

Hey bro, click here

'); $this->assertEquals('

Hey bro, click here


', $dom->find('div', 0)->innerHtml); } public function testLoadNoValueAttribute() { $dom = new Dom; $dom->load('
Main content here
'); $this->assertEquals('
Main content here
', $dom->innerHtml); } public function testLoadNoValueAttributeBefore() { $dom = new Dom; $dom->load('
Main content here
'); $this->assertEquals('
Main content here
', $dom->innerHtml); } public function testLoadUpperCase() { $dom = new Dom; $dom->load('

hEY BRO, CLICK HERE

'); $this->assertEquals('

hEY BRO, CLICK HERE

', $dom->find('div', 0)->innerHtml); } public function testLoadWithFile() { $dom = new Dom; $dom->loadFromFile('tests/files/small.html'); $this->assertEquals('VonBurgermeister', $dom->find('.post-user font', 0)->text); } public function testLoadFromFile() { $dom = new Dom; $dom->loadFromFile('tests/files/small.html'); $this->assertEquals('VonBurgermeister', $dom->find('.post-user font', 0)->text); } public function testLoadFromFileFind() { $dom = new Dom; $dom->loadFromFile('tests/files/small.html'); $this->assertEquals('VonBurgermeister', $dom->find('.post-row div .post-user font', 0)->text); } public function testLoadUtf8() { $dom = new Dom; $dom->load('

Dzień

'); $this->assertEquals('Dzień', $dom->find('p', 0)->text); } public function testLoadFileBig() { $dom = new Dom; $dom->loadFromFile('tests/files/big.html'); $this->assertEquals(10, count($dom->find('.content-border'))); } public function testLoadFileBigTwice() { $dom = new Dom; $dom->loadFromFile('tests/files/big.html'); $post = $dom->find('.post-row', 0); $this->assertEquals('

Журчанье воды
Черно-белые тени
Вновь на фонтане

', $post->find('.post-message', 0)->innerHtml); } public function testLoadFileBigTwicePreserveOption() { $dom = new Dom; $dom->loadFromFile('tests/files/big.html', ['preserveLineBreaks' => true]); $post = $dom->find('.post-row', 0); $this->assertEquals('

Журчанье воды
Черно-белые тени
Вновь на фонтане

', trim($post->find('.post-message', 0)->innerHtml)); } public function testLoadFromUrl() { $curl = Mockery::mock('PHPHtmlParser\CurlInterface'); $curl->shouldReceive('get') ->once() ->with('http://google.com') ->andReturn(file_get_contents('tests/files/small.html')); $dom = new Dom; $dom->loadFromUrl('http://google.com', [], $curl); $this->assertEquals('VonBurgermeister', $dom->find('.post-row div .post-user font', 0)->text); } public function testToStringMagic() { $dom = new Dom; $dom->load('

Hey bro, click here
:)

'); $this->assertEquals('

Hey bro, click here
:)

', (string) $dom); } public function testGetMagic() { $dom = new Dom; $dom->load('

Hey bro, click here
:)

'); $this->assertEquals('

Hey bro, click here
:)

', $dom->innerHtml); } public function testFirstChild() { $dom = new Dom; $dom->load('

Hey bro, click here


'); $this->assertEquals('

Hey bro, click here

', $dom->firstChild()->outerHtml); } public function testLastChild() { $dom = new Dom; $dom->load('

Hey bro, click here


'); $this->assertEquals('
', $dom->lastChild()->outerHtml); } public function testGetElementById() { $dom = new Dom; $dom->load('

Hey bro, click here


'); $this->assertEquals('click here', $dom->getElementById('78')->outerHtml); } public function testGetElementsByTag() { $dom = new Dom; $dom->load('

Hey bro, click here


'); $this->assertEquals('

Hey bro, click here

', $dom->getElementsByTag('p')[0]->outerHtml); } public function testGetElementsByClass() { $dom = new Dom; $dom->load('

Hey bro, click here


'); $this->assertEquals('

Hey bro, click here

', $dom->getElementsByClass('all')[0]->innerHtml); } public function testEnforceEncoding() { $dom = new Dom; $dom->load('tests/files/horrible.html', [ 'enforceEncoding' => 'UTF-8', ]); $this->assertNotEquals('', $dom->find('table input', 1)->outerHtml); } public function testScriptCleanerScriptTag() { $dom = new Dom; $dom->load('

.....

....

'); $this->assertEquals('....', $dom->getElementsByTag('p')[1]->innerHtml); } public function testMultipleDoubleQuotes() { $dom = new Dom; $dom->load('Hello'); $this->assertEquals('This is a "test" of double quotes', $dom->getElementsByTag('a')[0]->title); } public function testMultipleSingleQuotes() { $dom = new Dom; $dom->load("Hello"); $this->assertEquals("Ain't this the best", $dom->getElementsByTag('a')[0]->title); } public function testBeforeClosingTag() { $dom = new Dom; $dom->load("
"); $this->assertEquals("
", (string) $dom); } public function testCodeTag() { $dom = new Dom; $dom->load('hello$foo = "bar";'); $this->assertEquals('hello$foo = "bar";', (string) $dom); } public function testDeleteNode() { $dom = new Dom; $dom->load('

Hey bro, click here
:)

'); $a = $dom->find('a')[0]; $a->delete(); unset($a); $this->assertEquals('

Hey bro,
:)

', (string) $dom); } }