eZ\Publish\Core\REST\Common\Tests\AssertXmlTagTrait::assertXMLTag PHP Method

assertXMLTag() public static method

Simple re implementation of assertTag (deprecated in PHPUnit) for XML use.
public static assertXMLTag ( array $matcher, string $actualXml, string $message = '' )
$matcher array Hash with 'tag' (required), and optionally: 'attributes' & 'content' keys
$actualXml string
$message string
    public static function assertXMLTag($matcher, $actualXml, $message = '')
    {
        // Provide default values.
        $matcher += array('attributes' => array());
        // Create an XPath query that selects the xml tag.
        $query = '//' . $matcher['tag'];
        // Append XPath selectors for the attributes and content text.
        $selectors = array();
        foreach ($matcher['attributes'] as $attribute => $value) {
            $selectors[] = "@{$attribute}='{$value}'";
        }
        if (!empty($matcher['content'])) {
            $selectors[] = "contains(.,'{$matcher['content']}')";
        }
        if (!empty($selectors)) {
            $query .= '[' . implode(' and ', $selectors) . ']';
        }
        // Execute the query.
        $document = new DOMDocument();
        $document->loadXML($actualXml);
        $xpath = new DOMXPath($document);
        self::assertGreaterThanOrEqual(1, $xpath->query($query)->length, $message);
    }
AssertXmlTagTrait