/** * Asserts that a hierarchy of DOMElements matches. * * @param DOMElement $expectedElement * @param DOMElement $actualElement * @param bool $checkAttributes * @param string $message * @author Mattis Stordalen Flister <*****@*****.**> * @since Method available since Release 3.3.0 */ public static function assertEqualXMLStructure(DOMElement $expectedElement, DOMElement $actualElement, $checkAttributes = false, $message = '') { $expectedElement = clone $expectedElement; $actualElement = clone $actualElement; 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); } }