-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnalyzerTest.php
More file actions
63 lines (54 loc) · 1.94 KB
/
AnalyzerTest.php
File metadata and controls
63 lines (54 loc) · 1.94 KB
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
<?php declare(strict_types=1);
namespace Tests\HtmlAnalyzer;
use PHPUnit\Framework\TestCase;
/**
* 测试 php-html-analyzer\HtmlAnalyzer\Analyzer
*
* @author fdipzone
*/
final class AnalyzerTest extends TestCase
{
/**
* @covers \HtmlAnalyzer\Analyzer::__construct
*/
public function testConstruct()
{
$url = 'https://www.fdipzone.com';
$doc = '<p>fdipzone</p>';
$document = new \HtmlAnalyzer\Document($url, $doc);
$analyzer = new \HtmlAnalyzer\Analyzer($document);
$this->assertEquals('HtmlAnalyzer\Analyzer', get_class($analyzer));
}
/**
* @covers \HtmlAnalyzer\Analyzer::getResource
*/
public function testGetResource()
{
$url = 'https://www.sina.com.cn';
$doc = file_get_contents(dirname(__FILE__).'/test_data/test.html');
$document = new \HtmlAnalyzer\Document($url, $doc);
$analyzer = new \HtmlAnalyzer\Analyzer($document);
$emails = $analyzer->getResource(\HtmlAnalyzer\Type::EMAIL);
$urls = $analyzer->getResource(\HtmlAnalyzer\Type::URL);
$images = $analyzer->getResource(\HtmlAnalyzer\Type::IMAGE);
$css = $analyzer->getResource(\HtmlAnalyzer\Type::CSS);
$this->assertTrue(count($emails)>0);
$this->assertTrue(count($urls)>0);
$this->assertTrue(count($images)>0);
$this->assertTrue(count($css)>0);
}
/**
* @covers \HtmlAnalyzer\Analyzer::getResource
*/
public function testGetResourceException()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('html analyzer: type not_exists_type not exists');
$url = 'https://www.sina.com.cn';
$doc = file_get_contents(dirname(__FILE__).'/test_data/test.html');
$document = new \HtmlAnalyzer\Document($url, $doc);
$analyzer = new \HtmlAnalyzer\Analyzer($document);
$type = 'not_exists_type';
$analyzer->getResource($type);
}
}