1
|
|
|
<?php declare( strict_types = 1 ); |
2
|
|
|
|
3
|
|
|
namespace Coco\SourceWatcher\Tests\Watcher\Handler; |
4
|
|
|
|
5
|
|
|
use Coco\SourceWatcher\Core\SourceWatcherException; |
6
|
|
|
use Coco\SourceWatcher\Watcher\Handler\WebPageHandler; |
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class WebPageHandlerTest |
11
|
|
|
* @package Coco\SourceWatcher\Tests\Watcher\Handler |
12
|
|
|
*/ |
13
|
|
|
class WebPageHandlerTest extends TestCase |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* |
17
|
|
|
*/ |
18
|
|
|
public function testSetGetURL () : void |
19
|
|
|
{ |
20
|
|
|
$givenURL = "https://stackoverflow.com/jobs?q=Java&l=Florida+USA&d=100&u=Miles"; |
21
|
|
|
$expectedURL = "https://stackoverflow.com/jobs?q=Java&l=Florida+USA&d=100&u=Miles"; |
22
|
|
|
|
23
|
|
|
$webPageHandler = new WebPageHandler( $givenURL ); |
24
|
|
|
|
25
|
|
|
$this->assertNotNull( $webPageHandler->getUrl() ); |
26
|
|
|
$this->assertEquals( $expectedURL, $webPageHandler->getUrl() ); |
27
|
|
|
|
28
|
|
|
$givenURL = "https://stackoverflow.com/jobs?q=PHP&l=Florida+USA&d=100&u=Miles"; |
29
|
|
|
$expectedURL = "https://stackoverflow.com/jobs?q=PHP&l=Florida+USA&d=100&u=Miles"; |
30
|
|
|
|
31
|
|
|
$webPageHandler->setUrl( $givenURL ); |
32
|
|
|
|
33
|
|
|
$this->assertNotNull( $webPageHandler->getUrl() ); |
34
|
|
|
$this->assertEquals( $expectedURL, $webPageHandler->getUrl() ); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @throws SourceWatcherException |
39
|
|
|
*/ |
40
|
|
|
public function testReadWithNoURL () : void |
41
|
|
|
{ |
42
|
|
|
$this->expectException( SourceWatcherException::class ); |
43
|
|
|
|
44
|
|
|
$webPageHandler = new WebPageHandler( "" ); |
45
|
|
|
$webPageHandler->read(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @throws SourceWatcherException |
50
|
|
|
*/ |
51
|
|
|
public function testReadWithBadURL () : void |
52
|
|
|
{ |
53
|
|
|
$webPageHandler = new WebPageHandler( "this is not a URL" ); |
54
|
|
|
$webPageHandler->read(); |
55
|
|
|
|
56
|
|
|
$this->assertEmpty( $webPageHandler->getHtml() ); |
57
|
|
|
|
58
|
|
|
$this->assertNotEmpty( $webPageHandler->getDom() ); |
59
|
|
|
$this->assertEquals( 0, $webPageHandler->getDom()->childNodes->length ); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @throws SourceWatcherException |
64
|
|
|
*/ |
65
|
|
|
public function testReadWithGoodURL () : void |
66
|
|
|
{ |
67
|
|
|
$webPageHandler = new WebPageHandler( "https://stackoverflow.com/jobs?q=Java&l=Florida+USA&d=100&u=Miles" ); |
68
|
|
|
$webPageHandler->read(); |
69
|
|
|
|
70
|
|
|
$this->assertNotEmpty( $webPageHandler->getHtml() ); |
71
|
|
|
|
72
|
|
|
$this->assertNotEmpty( $webPageHandler->getDom() ); |
73
|
|
|
$this->assertGreaterThan( 0, $webPageHandler->getDom()->childNodes->length ); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|