|
1 |
| -# HTMLUnitTester |
2 |
| -PHPUnit Testing extensions for HMTL and CSS |
| 1 | +# PHPFUI\HTMLUnitTester |
| 2 | +[PHPUnit](https://phpunit.de/) Testing extensions for HMTL and CSS. **PHPFUI\HTMLUnitTester** allows you to unit test HTML and CSS for errors and warnings. Often simple errors in HTML or CSS create hard to debug issues where a simple check will reveal bad code. |
| 3 | + |
| 4 | +This package will check detect errors and warnings in HTML and CSS in stand alone strings, files or urls. |
| 5 | +# Requirements |
| 6 | +PHP 7.1 or higher |
| 7 | +PHPUnit 7 or higher |
| 8 | +For the best performanance, a local install of [https://github.com/validator/validator](https://github.com/validator/validator) is recommended. |
| 9 | +## Installation |
| 10 | +``` |
| 11 | +composer require PHPFUI\HTMLUnitTester |
| 12 | +``` |
| 13 | +## Configuration |
| 14 | +It is recommended you run [https://github.com/validator/validator](https://github.com/validator/validator) locally. Install [Java](https://www.java.com/ES/download/) and download the [.jar file](https://github.com/validator/validator/releases). Run with the following command: |
| 15 | +``` |
| 16 | +java -Xss512k -cp vnu.jar nu.validator.servlet.Main 8888 |
| 17 | +``` |
| 18 | +In your phpunit.xml.dist config file, add the following lines in the **phpunit** element: |
| 19 | +```xml |
| 20 | +<php> |
| 21 | + <env name="PHPFUI\HTMLUnitTester\Extensions_url" value="http://127.0.0.1:8888"/> |
| 22 | + <env name="PHPFUI\HTMLUnitTester\Extensions_delay" value="0"/> |
| 23 | +</php> |
| 24 | +``` |
| 25 | +You can run against the online version at (https://validator.w3.org/nu/), but is recomended to use a delay of 500000 or higher to avoid overloading the server. |
| 26 | + |
| 27 | +## Usage |
| 28 | +Extend your unit tests from \PHPFUI\HTMLUnitTester\Extensions |
| 29 | +```php |
| 30 | +class UnitTest extends \PHPFUI\HTMLUnitTester\Extensions |
| 31 | + { |
| 32 | + public function testValidHtml() |
| 33 | + { |
| 34 | + $this->assertValidHtml('<h1>Header</h1>'); |
| 35 | + $this->assertValidHtml('<!DOCTYPE html><html><head><meta charset="utf-8"/><title>Title</title></head><body><div>This is a test</div></body></html>'); |
| 36 | + } |
| 37 | + } |
| 38 | +``` |
| 39 | +You can use any of the following asserts: |
| 40 | +- assertNotWarningCss |
| 41 | +- assertNotWarningCssFile |
| 42 | +- assertNotWarningCssUrl |
| 43 | +- assertNotWarningFile |
| 44 | +- assertNotWarningHtml |
| 45 | +- assertNotWarningUrl |
| 46 | +- assertValidCss |
| 47 | +- assertValidCssFile |
| 48 | +- assertValidCssUrl |
| 49 | +- assertValidFile |
| 50 | +- assertValidHtml |
| 51 | +- assertValidUrl |
| 52 | + |
| 53 | +## Examples |
| 54 | +See [examples](https://github.com/phpfui/HTMLUnitTester/tree/master/src/PHPFUI/HTMLUnitTester/examples) |
| 55 | + |
0 commit comments