-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAssertsHtml.php
More file actions
50 lines (38 loc) · 1.77 KB
/
AssertsHtml.php
File metadata and controls
50 lines (38 loc) · 1.77 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
<?php
declare(strict_types=1);
namespace Ziadoz\AssertableHtml\Traits;
use Ziadoz\AssertableHtml\Dom\AssertableDocument;
trait AssertsHtml
{
/** Return a configured assertable HTML document. */
public function assertableHtml(string $html, int $options = 0, ?string $overrideEncoding = null): AssertableDocument
{
return is_file($html)
? AssertableDocument::createFromFile($html, $options, $overrideEncoding)
: AssertableDocument::createFromString($html, $options, $overrideEncoding);
}
/** Return an assertable HTML document. */
public function assertHtml(string $html, callable $callback, int $options = 0, ?string $overrideEncoding = null): static
{
$this->assertableHtml($html, $options, $overrideEncoding)->with($callback);
return $this;
}
/** Return an assertable HTML document scoped to <head>. */
public function assertHead(string $html, callable $callback, int $options = 0, ?string $overrideEncoding = null): static
{
$this->assertableHtml($html, $options, $overrideEncoding)->one('head', $callback);
return $this;
}
/** Return an assertable HTML document scoped to <body>. */
public function assertBody(string $html, callable $callback, int $options = 0, ?string $overrideEncoding = null): static
{
$this->assertableHtml($html, $options, $overrideEncoding)->one('body', $callback);
return $this;
}
/** Return an assertable HTML document scoped to the given selector. */
public function assertElement(string $html, string $selector, callable $callback, int $options = 0, ?string $overrideEncoding = null): static
{
$this->assertableHtml($html, $options, $overrideEncoding)->one($selector, $callback);
return $this;
}
}