1
|
|
|
<?php |
2
|
|
|
namespace VDB\Spider\Tests; |
3
|
|
|
|
4
|
|
|
use Guzzle\Http\Message\Response; |
5
|
|
|
use VDB\Spider\Resource; |
6
|
|
|
use VDB\Uri\Uri; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
*/ |
10
|
|
|
class ResourceTest extends TestCase |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var Resource |
14
|
|
|
*/ |
15
|
|
|
protected $resource; |
16
|
|
|
|
17
|
|
|
protected function setUp() |
18
|
|
|
{ |
19
|
|
|
$html = file_get_contents(__DIR__ . '/Fixtures/ResourceTestHTMLResource.html'); |
20
|
|
|
$this->resource = new Resource( |
21
|
|
|
new Uri('/domains/special', 'http://example.org'), |
22
|
|
|
new Response(200, null, $html) |
23
|
|
|
); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @covers VDB\Spider\Resource::getCrawler |
28
|
|
|
*/ |
29
|
|
|
public function testGetCrawler() |
30
|
|
|
{ |
31
|
|
|
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $this->resource->getCrawler()); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @covers VDB\Spider\Resource::getUri |
36
|
|
|
*/ |
37
|
|
|
public function testGetUri() |
38
|
|
|
{ |
39
|
|
|
$this->assertInstanceOf('VDB\\URI\Uri', $this->resource->getUri()); |
40
|
|
|
$this->assertEquals('http://example.org/domains/special', $this->resource->getUri()->toString()); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @covers VDB\Spider\Resource::getResponse |
45
|
|
|
*/ |
46
|
|
|
public function testGetResponse() |
47
|
|
|
{ |
48
|
|
|
$this->assertInstanceOf('Guzzle\\Http\\Message\\Response', $this->resource->getResponse()); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @covers VDB\Spider\Resource::setFiltered |
53
|
|
|
* @covers VDB\Spider\Resource::isFiltered |
54
|
|
|
* @covers VDB\Spider\Resource::getFilterReason |
55
|
|
|
*/ |
56
|
|
|
public function testSetFiltered() |
57
|
|
|
{ |
58
|
|
|
$this->resource->setFiltered(true, 'goodReason'); |
59
|
|
|
$this->assertTrue($this->resource->isFiltered()); |
60
|
|
|
$this->assertEquals('goodReason', $this->resource->getFilterReason()); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @covers VDB\Spider\Resource::getIdentifier |
65
|
|
|
*/ |
66
|
|
|
public function testGetIdentifier() |
67
|
|
|
{ |
68
|
|
|
$this->assertEquals('http://example.org/domains/special', $this->resource->getIdentifier()); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|