forked from php-embed/Embed
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDocumentTest.php
More file actions
57 lines (41 loc) · 2.09 KB
/
DocumentTest.php
File metadata and controls
57 lines (41 loc) · 2.09 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
<?php
declare(strict_types = 1);
namespace Embed\Tests;
use Embed\Embed;
use Embed\Http\Crawler;
use PHPUnit\Framework\TestCase;
class DocumentTest extends TestCase
{
private static Embed $embed;
private static function getEmbed(): Embed
{
if (isset(self::$embed)) {
return self::$embed;
}
$dispatcher = new FileClient(__DIR__.'/cache');
$dispatcher->setMode(0);
return self::$embed = new Embed(new Crawler($dispatcher));
}
public function testSelectors()
{
$extractor = self::getEmbed()->get('http://www.wired.com/?p=2064839');
$document = $extractor->getDocument();
$expected = 3;
$this->assertCount($expected, $document->select('.//p')->nodes());
$this->assertCount($expected, $document->selectCss('p')->nodes());
$document->remove('.//p');
$this->assertCount(0, $document->select('.//p')->nodes());
$this->assertCount(0, $document->selectCss('p')->nodes());
}
public function testMultipleSelectors()
{
$extractor = self::getEmbed()->get('https://css-tricks.com/css-scrollbar-with-progress-meter/');
$document = $extractor->getDocument();
$expected = 113;
$this->assertCount($expected, $document->selectCss('[aria-hidden],[hidden],meta,style,canvas,svg,form,script,template,link,.hidden')->nodes());
$this->assertCount($expected, $document->select('.//*[@aria-hidden]|.//*[@hidden]|.//meta|.//style|.//canvas|.//svg|.//form|.//script|.//template|.//link|.//*[contains(concat(" ",normalize-space(@class)," ")," hidden ")]')->nodes());
$document->removeCss('[aria-hidden],[hidden],meta,style,canvas,svg,form,script,template,link,.hidden');
$this->assertCount(0, $document->selectCss('[aria-hidden],[hidden],meta,style,canvas,svg,form,script,template,link,.hidden')->nodes());
$this->assertCount(0, $document->select('.//*[@aria-hidden]|.//*[@hidden]|.//meta|.//style|.//canvas|.//svg|.//form|.//script|.//template|.//link|.//*[contains(concat(" ",normalize-space(@class)," ")," hidden ")]')->nodes());
}
}