PHP Classes

File: HtmlTestCase.md

Recommend this page to a friend!
  Classes of Stefan Kientzler   PHP HTML Test Case   HtmlTestCase.md   Download  
File: HtmlTestCase.md
Role: Documentation
Content type: text/markdown
Description: Documentation of a test case
Class: PHP HTML Test Case
Extends PHPUnit to test HTML output
Author: By
Last change: Added HTML class reference
Date: 2 years ago
Size: 13,339 bytes
 

Contents

Class file image Download

<a name="htmltestcase"></a>

Class HtmlTestCase

Full name:??? \SKien\Test\HtmlTestCase Base class:??? \PHPUnit\Framework\TestCase

Extension of PHPUnit Testcase for HTML testing.

This class 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 - given text is plain text (means, text doesn't contain any HTML tags)

<b>To test for valid HTML5 doc/block the PHP libraries cURL and OpenSSL required.</b>

Overview

| Method | Description | |:--- |:--- | | assertContainsNoHtmlTag |Assert that the given text don't contain any HTML tags (-> contains plain text).| | assertHtmlElementAttribContains |Assert that the given HTML string contains element with requested ID and specified attrib containing expected part.| | assertHtmlElementAttribEquals |Assert that the given HTML string contains element with requested ID and specified attrib having expected value.| | assertHtmlElementContains |Assert that the given HTML string contains element with requested ID containing expected part.| | assertHtmlElementEquals |Assert that the given HTML string contains element with requested ID and expected value.| | assertHtmlElementHasAttrib |Assert that the given HTML string contains element with requested ID and specified attrib.| | assertHtmlElementHasStyle |Assert that the given HTML string contains element with requested ID and specified style having expected value.| | assertHtmlHasElement |Assert that the given HTML string contains element with requested ID.| | assertHtmlHasTag |Assert that the given HTML string contains the requested tag.| | assertHtmlTagAttribContains |Assert that the given HTML string contains the requested tag with specified attrib containing expected part.| | assertHtmlTagAttribEquals |Assert that the given HTML string contains the requested tag with specified attrib having expected value.| | assertHtmlTagContains |Assert that the given HTML string contains the requested tag containing expected part.| | assertHtmlTagEquals |Assert that the given HTML string contains the requested tag with expected value.| | assertHtmlTagHasAttrib |Assert that the given HTML string contains the requested tag with specified attrib.| | assertHtmlTagHasStyle |Assert that the given HTML string contains the requested tag with specified style having expected value.| | assertValidHtml |Assert that the given string is a valid HTML5 document.| | assertValidHtmlBlock |Assert that the given string is a valid HTML5 block.|

Methods

assertContainsNoHtmlTag

Assert that the given text don't contain any HTML tags (-> contains plain text).

public HtmlTestCase::assertContainsNoHtmlTag(string $text, string $strMessage = null) : void

Parameters:

| Parameter | Type | Description | |-----------|------|-------------| | text | string | The text to test | | strMessage | string | Optional Message |

[[go to top]](#htmltestcase)

assertHtmlElementAttribContains

Assert that the given HTML string contains element with requested ID and specified attrib containing expected part.

public HtmlTestCase::assertHtmlElementAttribContains(string $strHTML, string $strID, string $strAttrib, string $strContains, string $strMessage = null) : void

Parameters:

| Parameter | Type | Description | |-----------|------|-------------| | strHTML | string | The HTML string | | strID | string | ID of the element we are locking for | | strAttrib | string | Attrib to test | | strContains | string | Part the attrib value must contain | | strMessage | string | Optional Message |

[[go to top]](#htmltestcase)

assertHtmlElementAttribEquals

Assert that the given HTML string contains element with requested ID and specified attrib having expected value.

public HtmlTestCase::assertHtmlElementAttribEquals(string $strHTML, string $strID, string $strAttrib, string $strExpect, string $strMessage = null) : void

Parameters:

| Parameter | Type | Description | |-----------|------|-------------| | strHTML | string | The HTML to validate | | strID | string | ID of the element we are locking for | | strAttrib | string | Attrib to test | | strExpect | string | Expected attribute value | | strMessage | string | Optional Message |

[[go to top]](#htmltestcase)

assertHtmlElementContains

Assert that the given HTML string contains element with requested ID containing expected part.

public HtmlTestCase::assertHtmlElementContains(string $strHTML, string $strID, string $strContains, string $strMessage = null) : void

Parameters:

| Parameter | Type | Description | |-----------|------|-------------| | strHTML | string | The HTML to validate | | strID | string | ID of the element we are locking for | | strContains | string | Part the node value must contain | | strMessage | string | Optional Message |

[[go to top]](#htmltestcase)

assertHtmlElementEquals

Assert that the given HTML string contains element with requested ID and expected value.

public HtmlTestCase::assertHtmlElementEquals(string $strHTML, string $strID, string $strExpect, string $strMessage = null) : void

Parameters:

| Parameter | Type | Description | |-----------|------|-------------| | strHTML | string | The HTML to validate | | strID | string | ID of the element we are locking for | | strExpect | string | Expected node value | | strMessage | string | Optional Message |

[[go to top]](#htmltestcase)

assertHtmlElementHasAttrib

Assert that the given HTML string contains element with requested ID and specified attrib.

public HtmlTestCase::assertHtmlElementHasAttrib(string $strHTML, string $strID, string $strAttrib, string $strMessage = null) : void

Parameters:

| Parameter | Type | Description | |-----------|------|-------------| | strHTML | string | The HTML to validate | | strID | string | ID of the element we are locking for | | strAttrib | string | Attrib to test | | strMessage | string | Optional Message |

[[go to top]](#htmltestcase)

assertHtmlElementHasStyle

Assert that the given HTML string contains element with requested ID and specified style having expected value.

public HtmlTestCase::assertHtmlElementHasStyle(string $strHTML, string $strID, string $strStyle, string $strExpect, string $strMessage = null) : void

Parameters:

| Parameter | Type | Description | |-----------|------|-------------| | strHTML | string | The HTML string | | strID | string | ID of the element we are locking for | | strStyle | string | The style to test | | strExpect | string | The expected value | | strMessage | string | Optional Message |

[[go to top]](#htmltestcase)

assertHtmlHasElement

Assert that the given HTML string contains element with requested ID.

public HtmlTestCase::assertHtmlHasElement(string $strHTML, string $strID, string $strMessage = null) : void

Parameters:

| Parameter | Type | Description | |-----------|------|-------------| | strHTML | string | The HTML to validate | | strID | string | ID of the element we are locking for | | strMessage | string | Optional Message |

[[go to top]](#htmltestcase)

assertHtmlHasTag

Assert that the given HTML string contains the requested tag.

public HtmlTestCase::assertHtmlHasTag(string $strHTML, string $strTag, string $strMessage = null) : void

Parameters:

| Parameter | Type | Description | |-----------|------|-------------| | strHTML | string | The HTML to validate | | strTag | string | The Tag we are locking for | | strMessage | string | Optional Message |

[[go to top]](#htmltestcase)

assertHtmlTagAttribContains

Assert that the given HTML string contains the requested tag with specified attrib containing expected part.

public HtmlTestCase::assertHtmlTagAttribContains(string $strHTML, string $strTag, string $strAttrib, string $strContains, string $strMessage = null) : void

Parameters:

| Parameter | Type | Description | |-----------|------|-------------| | strHTML | string | The HTML string | | strTag | string | The Tag we are locking for | | strAttrib | string | Attrib to test | | strContains | string | Part the attrib value must contain | | strMessage | string | Optional Message |

[[go to top]](#htmltestcase)

assertHtmlTagAttribEquals

Assert that the given HTML string contains the requested tag with specified attrib having expected value.

public HtmlTestCase::assertHtmlTagAttribEquals(string $strHTML, string $strTag, string $strAttrib, string $strExpect, string $strMessage = null) : void

Parameters:

| Parameter | Type | Description | |-----------|------|-------------| | strHTML | string | The HTML to validate | | strTag | string | The Tag we are locking for | | strAttrib | string | Attrib to test | | strExpect | string | Expected attribute value | | strMessage | string | Optional Message |

[[go to top]](#htmltestcase)

assertHtmlTagContains

Assert that the given HTML string contains the requested tag containing expected part.

public HtmlTestCase::assertHtmlTagContains(string $strHTML, string $strTag, string $strContains, string $strMessage = null) : void

Parameters:

| Parameter | Type | Description | |-----------|------|-------------| | strHTML | string | The HTML to validate | | strTag | string | The Tag we are locking for | | strContains | string | Part the node value must contain | | strMessage | string | Optional Message |

[[go to top]](#htmltestcase)

assertHtmlTagEquals

Assert that the given HTML string contains the requested tag with expected value.

public HtmlTestCase::assertHtmlTagEquals(string $strHTML, string $strTag, string $strExpect, string $strMessage = null) : void

Parameters:

| Parameter | Type | Description | |-----------|------|-------------| | strHTML | string | The HTML to validate | | strTag | string | The Tag we are locking for | | strExpect | string | Expected node value | | strMessage | string | Optional Message |

[[go to top]](#htmltestcase)

assertHtmlTagHasAttrib

Assert that the given HTML string contains the requested tag with specified attrib.

public HtmlTestCase::assertHtmlTagHasAttrib(string $strHTML, string $strTag, string $strAttrib, string $strMessage = null) : void

Parameters:

| Parameter | Type | Description | |-----------|------|-------------| | strHTML | string | The HTML to validate | | strTag | string | The Tag we are locking for | | strAttrib | string | Attrib to test | | strMessage | string | Optional Message |

[[go to top]](#htmltestcase)

assertHtmlTagHasStyle

Assert that the given HTML string contains the requested tag with specified style having expected value.

public HtmlTestCase::assertHtmlTagHasStyle(string $strHTML, string $strTag, string $strStyle, string $strExpect, string $strMessage = null) : void

Parameters:

| Parameter | Type | Description | |-----------|------|-------------| | strHTML | string | The HTML string | | strTag | string | The Tag we are locking for | | strStyle | string | The style to test | | strExpect | string | The expected value | | strMessage | string | Optional Message |

[[go to top]](#htmltestcase)

assertValidHtml

Assert that the given string is a valid HTML5 document.

public HtmlTestCase::assertValidHtml(string $strHTML, string $strMessage = null) : void

Calls https://html5.validator.nu through cURL request. More info can be found on https://github.com/validator/validator/wiki/Service-%C2%BB-HTTP-interface

Parameters:

| Parameter | Type | Description | |-----------|------|-------------| | strHTML | string | The HTML to validate | | strMessage | string | Optional Message |

[[go to top]](#htmltestcase)

assertValidHtmlBlock

Assert that the given string is a valid HTML5 block.

public HtmlTestCase::assertValidHtmlBlock(string $strHTML, string $strMessage = null) : void

The HTML block is enclosed in a valid HTML5 Document definition before validation.

Parameters:

| Parameter | Type | Description | |-----------|------|-------------| | strHTML | string | The HTML to validate | | strMessage | string | Optional Message |

[[go to top]](#htmltestcase)