bootpress/htmlunit

Enables you to thoroughly test the HTML output of your code.

v1.0 2016-09-01 21:56 UTC

This package is not auto-updated.

Last update: 2024-04-22 05:03:27 UTC


README

Packagist License MIT HHVM Tested PHP 7 Supported Build Status Code Climate Test Coverage

Extends PHPUnit and combines the assertEquals and assertRegExp assertions into one assertEqualsRegExp method that enables you to thoroughly test the HTML output of your code.

Installation

Add the following to your composer.json file.

{
    "require-dev": {
        "bootpress/htmlunit": "^1.0"
    }
}

Example Usage

<?php

class MyTest extends \BootPress\HTMLUnit\Component
{
    public function testOutput()
    {
        $html = <<<'EOT'
        
	<!doctype html>
<html lang="en-us">
<head><meta charset="UTF-8">

    <title>Title</title></head>
<body>            <p>Content</p>
    </body>     </html>
    
EOT;
        $this->assertEqualsRegExp(array(
            '<!doctype {{ [^>]+ }}>',
            '<html lang="{{ [a-z-]+ }}">',
            '<head>',
                '<meta charset="{{ [A-Z0-9-]+ }}">',
                '<title>Title</title>',
            '</head>',
            '<body>',
                '<p>Content</p>',
            '</body>',
            '</html>',
        ), $html);
    }
}

Notice that all of the whitespace surrounding the array values are ignored. Regular expressions are enclosed Twig style {{ ... }} with two curly braces and a space on both ends. Internally the regex is wrapped like so: /^...$/.

License

The MIT License (MIT). Please see License File for more information.