-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAssertsHtmlTest.php
More file actions
64 lines (56 loc) · 2.15 KB
/
AssertsHtmlTest.php
File metadata and controls
64 lines (56 loc) · 2.15 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
64
<?php
declare(strict_types=1);
namespace Ziadoz\AssertableHtml\Tests\Unit\Traits;
use PHPUnit\Framework\TestCase;
use Ziadoz\AssertableHtml\Dom\AssertableDocument;
use Ziadoz\AssertableHtml\Dom\AssertableElement;
use Ziadoz\AssertableHtml\Traits\AssertsHtml;
class AssertsHtmlTest extends TestCase
{
public function test_trait(): void
{
$html = $this->getTestHtml();
$case = $this->getTestClass();
$case->assertableHtml($html)->with(function (AssertableDocument $assertable) {
$this->assertInstanceOf(AssertableDocument::class, $assertable);
});
$case->assertHtml($html, function (AssertableDocument $assertable): void {
$this->assertInstanceOf(AssertableDocument::class, $assertable);
$assertable->assertTitleEquals('Test Page Title');
})->assertHead($html, function (AssertableElement $assertable): void {
$this->assertInstanceOf(AssertableElement::class, $assertable);
$assertable->assertTagEquals('head');
$assertable->querySelector('meta[name="description"]')->assertAttributeEquals('content', 'Foo Bar');
})->assertBody($html, function (AssertableElement $assertable): void {
$this->assertInstanceOf(AssertableElement::class, $assertable);
$assertable->assertTagEquals('body');
$assertable->querySelector('p')->assertTextEquals('Foo');
})->assertElement($html, 'p', function (AssertableElement $assertable): void {
$this->assertInstanceOf(AssertableElement::class, $assertable);
$assertable->assertTagEquals('p');
$assertable->assertTextEquals('Foo');
});
}
private function getTestClass(): object
{
return new class
{
use AssertsHtml;
};
}
private function getTestHtml(): string
{
return <<<'HTML'
<!DOCTYPE html>
<html>
<head>
<title>Test Page Title</title>
<meta name="description" content="Foo Bar">
</head>
<body>
<p>Foo</p>
</body>
</html>
HTML;
}
}