You are here

public static function PHPUnit_Framework_Assert::assertEqualXMLStructure in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/phpunit/phpunit/src/Framework/Assert.php \PHPUnit_Framework_Assert::assertEqualXMLStructure()

Asserts that a hierarchy of DOMElements matches.

@since Method available since Release 3.3.0

Parameters

DOMElement $expectedElement:

DOMElement $actualElement:

bool $checkAttributes:

string $message:

7 calls to PHPUnit_Framework_Assert::assertEqualXMLStructure()
Framework_AssertTest::testXMLStructureAttributesAreSameButValuesAreNot in vendor/phpunit/phpunit/tests/Framework/AssertTest.php
@covers PHPUnit_Framework_Assert::assertEqualXMLStructure
Framework_AssertTest::testXMLStructureIgnoreTextNodes in vendor/phpunit/phpunit/tests/Framework/AssertTest.php
@covers PHPUnit_Framework_Assert::assertEqualXMLStructure
Framework_AssertTest::testXMLStructureIsSame in vendor/phpunit/phpunit/tests/Framework/AssertTest.php
@covers PHPUnit_Framework_Assert::assertEqualXMLStructure
Framework_AssertTest::testXMLStructureIsSameButDataIsNot in vendor/phpunit/phpunit/tests/Framework/AssertTest.php
@covers PHPUnit_Framework_Assert::assertEqualXMLStructure
Framework_AssertTest::testXMLStructureWrongNumberOfAttributes in vendor/phpunit/phpunit/tests/Framework/AssertTest.php
@covers PHPUnit_Framework_Assert::assertEqualXMLStructure @expectedException PHPUnit_Framework_ExpectationFailedException

... See full list

File

vendor/phpunit/phpunit/src/Framework/Assert.php, line 1796

Class

PHPUnit_Framework_Assert
A set of assert methods.

Code

public static function assertEqualXMLStructure(DOMElement $expectedElement, DOMElement $actualElement, $checkAttributes = false, $message = '') {
  $tmp = new DOMDocument();
  $expectedElement = $tmp
    ->importNode($expectedElement, true);
  $tmp = new DOMDocument();
  $actualElement = $tmp
    ->importNode($actualElement, true);
  unset($tmp);
  self::assertEquals($expectedElement->tagName, $actualElement->tagName, $message);
  if ($checkAttributes) {
    self::assertEquals($expectedElement->attributes->length, $actualElement->attributes->length, sprintf('%s%sNumber of attributes on node "%s" does not match', $message, !empty($message) ? "\n" : '', $expectedElement->tagName));
    for ($i = 0; $i < $expectedElement->attributes->length; $i++) {
      $expectedAttribute = $expectedElement->attributes
        ->item($i);
      $actualAttribute = $actualElement->attributes
        ->getNamedItem($expectedAttribute->name);
      if (!$actualAttribute) {
        self::fail(sprintf('%s%sCould not find attribute "%s" on node "%s"', $message, !empty($message) ? "\n" : '', $expectedAttribute->name, $expectedElement->tagName));
      }
    }
  }
  PHPUnit_Util_XML::removeCharacterDataNodes($expectedElement);
  PHPUnit_Util_XML::removeCharacterDataNodes($actualElement);
  self::assertEquals($expectedElement->childNodes->length, $actualElement->childNodes->length, sprintf('%s%sNumber of child nodes of "%s" differs', $message, !empty($message) ? "\n" : '', $expectedElement->tagName));
  for ($i = 0; $i < $expectedElement->childNodes->length; $i++) {
    self::assertEqualXMLStructure($expectedElement->childNodes
      ->item($i), $actualElement->childNodes
      ->item($i), $checkAttributes, $message);
  }
}