| @@ 11-32 (lines=22) @@ | ||
| 8 | /** |
|
| 9 | * This rule will analyze any html document and checks if a given string is contained. |
|
| 10 | */ |
|
| 11 | class RegExExistsRule extends StandardRule |
|
| 12 | { |
|
| 13 | private $regExs; |
|
| 14 | ||
| 15 | protected $contentTypes = array('text/html'); |
|
| 16 | ||
| 17 | /** |
|
| 18 | * @param int $string The string that the document must contain |
|
| 19 | */ |
|
| 20 | public function init(array $regExs) |
|
| 21 | { |
|
| 22 | $this->regExs = $regExs; |
|
| 23 | } |
|
| 24 | ||
| 25 | protected function doValidation(Response $response) |
|
| 26 | { |
|
| 27 | foreach ($this->regExs as $regEx) { |
|
| 28 | $this->assert(preg_match('^' . $regEx . '^', (string) $response->getBody()) > 0, |
|
| 29 | 'The given regular expression (' . $regEx . ') was not found in this document.'); |
|
| 30 | } |
|
| 31 | } |
|
| 32 | } |
|
| 33 | ||
| @@ 11-32 (lines=22) @@ | ||
| 8 | /** |
|
| 9 | * This rule will analyze any html document and checks if a given string is contained. |
|
| 10 | */ |
|
| 11 | class RegExNotExistsRule extends StandardRule |
|
| 12 | { |
|
| 13 | private $regExs; |
|
| 14 | ||
| 15 | protected $contentTypes = array('text/html'); |
|
| 16 | ||
| 17 | /** |
|
| 18 | * @param int $string The string that the document must contain |
|
| 19 | */ |
|
| 20 | public function init(array $regExs) |
|
| 21 | { |
|
| 22 | $this->regExs = $regExs; |
|
| 23 | } |
|
| 24 | ||
| 25 | protected function doValidation(Response $response) |
|
| 26 | { |
|
| 27 | foreach ($this->regExs as $regEx) { |
|
| 28 | $this->assert(preg_match('^' . $regEx . '^', (string) $response->getBody()) == 0, |
|
| 29 | 'The given regular expression (' . $regEx . ') was found in this document.'); |
|
| 30 | } |
|
| 31 | } |
|
| 32 | } |
|
| 33 | ||