/
HasSource.php
47 lines (41 loc) · 945 Bytes
/
HasSource.php
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
<?php
namespace Illuminate\Foundation\Testing\Constraints;
class HasSource extends PageConstraint
{
/**
* The expected HTML source.
*
* @var string
*/
protected $source;
/**
* Create a new constraint instance.
*
* @param string $source
* @return void
*/
public function __construct($source)
{
$this->source = $source;
}
/**
* Check if the source is found in the given crawler.
*
* @param \Symfony\Component\DomCrawler\Crawler|string $crawler
* @return bool
*/
protected function matches($crawler)
{
$pattern = $this->getEscapedPattern($this->source);
return preg_match("/{$pattern}/i", $this->html($crawler));
}
/**
* Returns a string representation of the object.
*
* @return string
*/
public function toString()
{
return "the HTML [{$this->source}]";
}
}