Skip to content

Commit 1c2270a

Browse files
committed
Added tests and updated README
1 parent 82aaf55 commit 1c2270a

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,12 @@ $dom->load('http://google.com', [
110110
$dom->load('http://gmail.com'); // will not have whitespaceTextNode set to false.
111111
```
112112

113-
At the moment we support 2 options, strict and whitespaceTextNode. Strict, by default false, will throw a `StrickException` if it find that the html is not strict complient (all tags must have a clossing tag, no attribute with out a value, etc.).
113+
At the moment we support 3 options, strict, whitespaceTextNode and enforceEncoding. Strict, by default false, will throw a `StrickException` if it find that the html is not strict complient (all tags must have a clossing tag, no attribute with out a value, etc.).
114114

115115
The whitespaceTextNode, by default true, option tells the parser to save textnodes even if the content of the node is empty (only whitespace). Setting it to false will ignore all whitespace only text node found in the document.
116116

117+
The enforceEncoding, by default null, option will enforce an charater set to be used for reading the content and returning the content in that encoding. Setting it to null will trigger an attempt to figure out the encoding from within the content of the string given instead.
118+
117119
Static Facade
118120
------------
119121

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
"paquettg/string-encode": "0.1.0"
1919
},
2020
"require-dev": {
21-
"phpunit/phpunit": "3.7.*",
22-
"satooshi/php-coveralls": "0.6.*"
21+
"phpunit/phpunit": "4.4.*",
22+
"satooshi/php-coveralls": "0.6.*",
23+
"mockery/mockery": "0.9.*"
2324
},
2425
"autoload": {
2526
"psr-0": {

tests/DomTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
class DomTest extends PHPUnit_Framework_TestCase {
66

7+
public function tearDown()
8+
{
9+
Mockery::close();
10+
}
11+
712
public function testLoad()
813
{
914
$dom = new Dom;
@@ -168,6 +173,19 @@ public function testLoadFileBigTwice()
168173
$this->assertEquals(' <p>Журчанье воды<br /> Черно-белые тени<br /> Вновь на фонтане</p> ', $post->find('.post-message', 0)->innerHtml);
169174
}
170175

176+
public function testLoadFromUrl()
177+
{
178+
$curl = Mockery::mock('PHPHtmlParser\CurlInterface');
179+
$curl->shouldReceive('get')
180+
->once()
181+
->with('http://google.com')
182+
->andReturn(file_get_contents('tests/files/small.html'));
183+
184+
$dom = new Dom;
185+
$dom->loadFromUrl('http://google.com', [], $curl);
186+
$this->assertEquals('VonBurgermeister', $dom->find('.post-row div .post-user font', 0)->text);
187+
}
188+
171189
public function testToStringMagic()
172190
{
173191
$dom = new Dom;
@@ -216,4 +234,13 @@ public function testGetElementsByClass()
216234
$dom->load('<div class="all"><p>Hey bro, <a href="google.com" id="78">click here</a></div><br />');
217235
$this->assertEquals('<p>Hey bro, <a href="google.com" id="78">click here</a></p>', $dom->getElementsByClass('all')[0]->innerHtml);
218236
}
237+
238+
public function testEnforceEncoding()
239+
{
240+
$dom = new Dom;
241+
$dom->load('tests/files/horrible.html', [
242+
'enforceEncoding' => 'UTF-8',
243+
]);
244+
$this->assertNotEquals('<input type="submit" tabindex="0" name="submit" value="Информации" />', $dom->find('table input', 1)->outerHtml);
245+
}
219246
}

0 commit comments

Comments
 (0)