| @@ 12-31 (lines=20) @@ | ||
| 9 | * This rule calculates the size of a html document. If the document is bigger than a given value |
|
| 10 | * the test will fail. |
|
| 11 | */ |
|
| 12 | class SizeRule extends StandardRule |
|
| 13 | { |
|
| 14 | private $maxSize; |
|
| 15 | ||
| 16 | protected $contentTypes = array('text/html'); |
|
| 17 | ||
| 18 | /** |
|
| 19 | * @param int $maxSize The maximum size of a html file in kilobytes. |
|
| 20 | */ |
|
| 21 | public function init($maxSize = 200) |
|
| 22 | { |
|
| 23 | $this->maxSize = $maxSize; |
|
| 24 | } |
|
| 25 | ||
| 26 | protected function doValidation(Response $response) |
|
| 27 | { |
|
| 28 | $size = strlen($response->getBody()) / 1000; |
|
| 29 | $this->assert($size <= $this->maxSize, 'The size of this html file is too big (' . $size . ' KB)'); |
|
| 30 | } |
|
| 31 | } |
|
| 32 | ||
| @@ 11-30 (lines=20) @@ | ||
| 8 | /** |
|
| 9 | * This rule checks if the size of an image is bigger than a given max value. |
|
| 10 | */ |
|
| 11 | class SizeRule extends StandardRule |
|
| 12 | { |
|
| 13 | private $maxSize; |
|
| 14 | ||
| 15 | protected $contentTypes = array('image'); |
|
| 16 | ||
| 17 | /** |
|
| 18 | * @param int $maxSize The maximum size of an image file in kilobytes. |
|
| 19 | */ |
|
| 20 | public function init($maxSize = 100) |
|
| 21 | { |
|
| 22 | $this->maxSize = $maxSize; |
|
| 23 | } |
|
| 24 | ||
| 25 | protected function doValidation(Response $response) |
|
| 26 | { |
|
| 27 | $size = strlen($response->getBody()) / 1000; |
|
| 28 | $this->assert($size <= $this->maxSize, 'The size of the file is too big (' . $size . ' KB)'); |
|
| 29 | } |
|
| 30 | } |
|
| 31 | ||