/var/www/hkosl.com/b2b2c/webadmin/libraies/paquettg/php-html-parser/tests/StaticDomTest.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php

use PHPHtmlParser\StaticDom;

class 
StaticDomTest extends PHPUnit_Framework_TestCase {

    public function 
setUp()
    {
        
StaticDom::mount();
    }

    public function 
tearDown()
    {
        
StaticDom::unload();
    }

    public function 
testMountWithDom()
    {
        
$dom = new PHPHtmlParser\Dom;
        
StaticDom::unload();
        
$status StaticDom::mount('newDom'$dom);
        
$this->assertTrue($status);
    }

    public function 
testLoad()
    {
        
$dom Dom::load('<div class="all"><p>Hey bro, <a href="google.com">click here</a><br /> :)</p></div>');
        
$div $dom->find('div'0);
        
$this->assertEquals('<div class="all"><p>Hey bro, <a href="google.com">click here</a><br /> :)</p></div>'$div->outerHtml);
    }

    public function 
testLoadWithFile()
    {
        
$dom Dom::load('tests/files/small.html');
        
$this->assertEquals('VonBurgermeister'$dom->find('.post-user font'0)->text);
    }

    public function 
testLoadFromFile()
    {
        
$dom Dom::loadFromFile('tests/files/small.html');
        
$this->assertEquals('VonBurgermeister'$dom->find('.post-user font'0)->text);
    }

    public function 
testFind()
    {
        
Dom::load('tests/files/horrible.html');
        
$this->assertEquals('<input type="submit" tabindex="0" name="submit" value="Информации" />'Dom::find('table input'1)->outerHtml);
    }

    
/**
     * @expectedException PHPHtmlParser\Exceptions\NotLoadedException
     */
    
public function testFindNoLoad()
    {
        
Dom::find('.post-user font'0);
    }

    public function 
testFindI()
    {
        
Dom::load('tests/files/horrible.html');
        
$this->assertEquals('[ Досие бр:12928 ]'Dom::find('i')[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::loadFromUrl('http://google.com', [], $curl);
        
$this->assertEquals('VonBurgermeister'Dom::find('.post-row div .post-user font'0)->text);
    }

}