PHP HTML Test Case: Extends PHPUnit to test HTML output

Recommend this page to a friend!
  Info   View files Documentation   Screenshots Screenshots   View files View files (8)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Last Updated Ratings Unique User Downloads Download Rankings
2021-08-04 (2 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 82 This week: 1All time: 9,728 This week: 267Up
Version License PHP version Categories
htmltestcase 1.0GNU General Publi...7HTML, Testing, PHP 7
Description Author

This package provides PHPUnit to test HTML output.

It provides a sub-class of PHPUnit that can perform several tests to validate the HTML output generated by PHP code. Currently, it can:

- Validate whole HTML documents using the validation services at html5.validator.nu
- Checks if a string contains HTML tags
- Checks if a string contains a specific HTML tag
- Checks if a string contains a specific HTML tag and value
- Checks if a string contains a specific HTML tag and attribute
- Checks if a string contains a specific HTML tag with a given ID value
- Etc...

Innovation Award
PHP Programming Innovation award winner
July 2021
Winner
PHPUnit is a popular PHP package to create test suites. It helps developing code that tests the quality of PHP projects.

This package provides classes that use PHPUnit testing features to test the HTML output of PHP projects.

This way, it simplifies the control of the quality of PHP projects that need to generate HTML output.

Manuel Lemos
Picture of Stefan Kientzler
  Performance   Level  
Name: Stefan Kientzler is available for providing paid consulting. Contact Stefan Kientzler .
Classes: 16 packages by
Country: Germany Germany
Age: 54
All time rank: 118476 in Germany Germany
Week rank: 5 Up1 in Germany Germany Up
Innovation award
Innovation award
Nominee: 9x

Winner: 6x

Details

Extension of PHPUnit Testcase for HTML testing.

Latest Stable Version License Donate Minimum PHP Version

Overview

Very often the main purpose of a PHP package is to generate any specific HTML code. This extension of the existing base class can mainly be used for the automated testing of such packages with PHPUnit.

In addition to numerous methods with which the presence or the content of certain tags, elements or attributes within an HTML block can be checked, the package also offers the possibility of checking an HTML document or block as a whole for its validity. (validates for W3C - HTML5)

This validation is done with a cURL request to the REST API from The Nu Html Checker that is reachable at https://html5.validator.nu.

As a small addition, a text can be checked to ensure that it does not contain any HTML tags

Available tests

This package contains a class that extends the PHPUnit TestCase class to perform HTML test for multiple purposes:

It supports several methods to test/assert for - valid HTML5 document/block - existing HTML tag/element/attribute - HTML tag/element/attribute value equals expected - HTML tag/element/attribute contains expected part - HTML tag/element has requested style set to expected value - given text is plain text (means, text doesn't contain any HTML tags)

A full class reference can be found here.

Requirements

The class is designed for use with the Version 9 of PHPUnit and to do the cURL request for HTML validation, the PHP libraries cURL and OpenSSL are required.

Usage

You can integrate the source file HtmlTestCase.php into your own PHPUnit Test-infrastructure (you may have to rename or change the namespace) or use it as it is.

The only change to your own test code is to use the HtmlTestCase class instead of TestCase as the base class for your test cases. The phpunit.xml is an example configuration that calls the tests from the ExampleTest directory.

This testcase contains two tests for each assertion-method of the package. The first of each is passed successful, the second one fails so you can see the generated error messages.

HtmlTestCaseFailures

Screenshots  
  • ExampleTest/HtmlTestCaseFailures.png
  Files folder image Files  
File Role Description
Files folder imageExampleTest (1 file)
Files folder imageSKien (1 directory)
Accessible without login Plain text file autoloader.php Aux. Auxiliary script
Accessible without login Plain text file HtmlTestCase.md Doc. Documentation of a test case
Accessible without login HTML file HtmlTestCaseReference.html Doc. Documentation
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file readme.md Doc. Documentation

  Files folder image Files  /  ExampleTest  
File Role Description
  Plain text file HtmlExampleTest.php Class Class source

  Files folder image Files  /  SKien  
File Role Description
Files folder imageTest (1 file)

  Files folder image Files  /  SKien  /  Test  
File Role Description
  Plain text file HtmlTestCase.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:82
This week:1
All time:9,728
This week:267Up
For more information send a message to info at phpclasses dot org.