Archive for September 29th, 2007

Unit Tests for HTML Validation

September 29th, 2007

It is now very easy to integrate testing for valid HTML into your web application’s test environment using the W3C’s validator and PHPUnit. I just committed a sample unit test for PHPUnit which will checks your html markup.

The test cases or suites are very easy to integrate into your existing environment with the Services_W3C_HTMLValidator package.

First you’ll need the PEAR package for html validation:
pear install Services_W3C_HTMLValidator-beta

And then you should copy down the two sample PHPUnit files ValidationSuite.php and URIValidationTest.php.

Within the ValidationSuite.php file, modify the array of URLs to check and simply run the tests with php ValidationSuite.php

A validation test will be automatically added for each URI you wish to validate.

– NOTE: If you plan on validating many pages, consider installing a local copy of the W3C validator – which isn’t that complicated and you’ll get faster results.

RoR has a similar plugin for html validation called ResponsibleMarkup, and I think the title is appropriately named.

Happy validating!