phpfui / html-unit-tester
PHPUnit Testing extensions for HMTL and CSS insures valid HTML and CSS via v.Nu validator
Installs: 3 250
Dependents: 2
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: >=8.0 <8.5
- rexxars/html-validator: >=2.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.2
- phpfui/phpunit-syntax-coverage: >=1.0
- phpstan/phpstan: ^1.8
- phpunit/phpunit: <12.0
- roave/security-advisories: dev-latest
README
PHPUnit 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.
This package will check detect errors and warnings in HTML and CSS in stand alone strings, files, entire directories or urls.
For the best performanance, a local install of https://github.com/validator/validator is recommended.
Installation
composer require phpfui/html-unit-tester
Configuration
It is recommended you run https://github.com/validator/validator locally. Install Java and download the .jar file. Run with the following command:
java -Xss1024k -Dnu.validator.servlet.bind-address=127.0.0.1 -cp .\vnu.jar nu.validator.servlet.Main 8888
To run unit tests with GitHub Actions, add the following lines to you workflows test yml file:
- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '11'
- name: Download vnu checker
run: wget https://github.com/validator/validator/releases/download/latest/vnu.jar
- name: Run Nu Html Checker (v.Nu)
run: java -cp vnu.jar -Xss1024k -Dnu.validator.servlet.bind-address=127.0.0.1 nu.validator.servlet.Main 8888 &
Usage
Extend your unit tests from \PHPFUI\HTMLUnitTester\Extensions
class UnitTest extends \PHPFUI\HTMLUnitTester\Extensions { public function testValidHtml() { $this->assertValidHtml('<h1>Header</h1>'); $this->assertValidHtmlPage('<!DOCTYPE html><html><head><meta charset="utf-8"/><title>Title</title></head><body><div>This is a test</div></body></html>'); } }
You can use any of the following asserts:
- assertNotWarningCss
- assertNotWarningCssFile
- assertNotWarningCssUrl
- assertNotWarningFile
- assertNotWarningHtml
- assertNotWarningHtmlPage
- assertNotWarningUrl
- assertValidCss
- assertValidCssFile
- assertValidCssUrl
- assertValidFile
- assertValidHtml
- assertValidHtmlPage
- assertValidUrl
Directory Testing
Instead of file by file testing, use assertDirectory to test an entire directory. Any files added to the directory will be automatically tested.
$this->assertDirectory('ValidCSS', 'cssDirectory', 'Invalid CSS'); $this->assertDirectory('NotWarningCSS', 'cssDirectory', 'CSS has warnings');
The error message will include the offending file name.
Examples
See examples
Documentation
Full documentation at PHPFUI\HTMLUnitTester
License
PHPFUI\HTMLUnitTester is distributed under the MIT License.
PHP Versions
This library only supports modern versions of PHP which still receive security updates. While we would love to support PHP from the late Ming Dynasty, the advantages of modern PHP versions far out weigh quaint notions of backward compatibility. Time to upgrade.