Skip to content

Commit

Permalink
Adding lots of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
phayes committed Apr 26, 2017
1 parent 36b2f48 commit 5a495ad
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 3 deletions.
15 changes: 15 additions & 0 deletions tests/CSSTest.php
@@ -0,0 +1,15 @@
<?php

use BetterDOMDocument\DOMDoc;

class CSSTest extends PHPUnit_Framework_TestCase {
public function testSelect() {
$dom = DOMDoc::loadFile("tests/testdata/helloworld.html");

$this->assertNotEmpty($dom->select('.image'));
$this->assertEmpty($dom->select('.asdf'));

$this->assertNotEmpty($dom->selectSingle('.image'));
$this->assertEmpty($dom->selectSingle('.asdf'));
}
}
7 changes: 7 additions & 0 deletions tests/LoadTest.php
Expand Up @@ -25,4 +25,11 @@ public function testEmptyLoad() {
$dom = new DOMDoc();
$this->assertEquals('', strval($dom));
}

public function testHTMLLoad() {
$dom = new DOMDoc();
$html = file_get_contents('tests/testdata/helloworld.xhtml');
$dom->loadHTML($html);
$this->assertEquals(['html' => 'http://www.w3.org/1999/xhtml'], $dom->getNamespaces());
}
}
2 changes: 1 addition & 1 deletion tests/MethodTest.php
Expand Up @@ -62,6 +62,6 @@ public function testHTML() {
$dom = DOMDoc::loadFile("tests/testdata/helloworld.html");

$extracted = $dom->out('//img');
$this->assertEquals('<img src="helloworld.jpg"/>', $extracted);
$this->assertEquals('<img class="image square" src="helloworld.jpg"/>', $extracted);
}
}
21 changes: 21 additions & 0 deletions tests/NamespaceTest.php
@@ -0,0 +1,21 @@
<?php

use BetterDOMDocument\DOMDoc;

class NamespaceTest extends PHPUnit_Framework_TestCase {
public function testLookup() {
$dom = DOMDoc::loadFile("tests/testdata/note.namespaced.xml");

$this->assertEquals("note", $dom->lookupPrefix('http://my-example-namespace'));
$this->assertEquals("http://my-example-namespace", $dom->lookupURL('note'));
}

public function testChange() {
$dom = DOMDoc::loadFile("tests/testdata/helloworld.xhtml");

$dom->changeNamespace('//html:img', 'img', 'http://www.w3.org/1998/Image');

$this->assertNotEmpty($dom->xpath('//img:img'));
}

}
3 changes: 1 addition & 2 deletions tests/testdata/helloworld.html
Expand Up @@ -6,8 +6,7 @@ <h1>Hellow World</h1>

<p>Hi there world.</p>

<!-- Note that this is not valid HTML since img must be self closed -->
<img src="helloworld.jpg"></img>
<img class="image square" src="helloworld.jpg" />

</body>
</html>
12 changes: 12 additions & 0 deletions tests/testdata/helloworld.xhtml
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<body>

<h1>Hellow World</h1>

<p>Hi there world.</p>

<img src="helloworld.jpg" />

</body>
</html>

0 comments on commit 5a495ad

Please sign in to comment.