Class HtmlTestCase

Extension of PHPUnit Testcase for HTML testing.

This class supports several methods to test/assert for

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

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]


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]


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]


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]


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]


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]


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]


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]


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]


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]


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]


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]


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]


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]


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]


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]


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]