Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions STEPS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2399,6 +2399,10 @@ Assert that a response is valid XML
```gherkin
Then the response should be in XML format

# Content set by a fixture step is validated instead of the page content.
Given the response content from the file "xml_valid.xml"
Then the response should be in XML format

```

</details>
Expand All @@ -2413,6 +2417,10 @@ Assert that a response is not valid XML
```gherkin
Then the response should not be in XML format

# Content set by a fixture step is validated instead of the page content.
Given the response content from the file "xml_invalid.xml"
Then the response should not be in XML format

```

</details>
Expand Down
15 changes: 12 additions & 3 deletions src/XmlTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,24 +124,33 @@ public function xmlSetResponseContentDirect(PyStringNode $content): void {
*
* @code
* Then the response should be in XML format
*
* # Content set by a fixture step is validated instead of the page content.
* Given the response content from the file "xml_valid.xml"
* Then the response should be in XML format
* @endcode
*/
#[Then('the response should be in XML format')]
public function xmlAssertResponseIsXml(): void {
$content = $this->getSession()->getPage()->getContent();
$this->xmlLoadDocument($content);
$this->xmlEnsureDocument();
}

/**
* Assert that a response is not valid XML.
*
* @code
* Then the response should not be in XML format
*
* # Content set by a fixture step is validated instead of the page content.
* Given the response content from the file "xml_invalid.xml"
* Then the response should not be in XML format
* @endcode
*/
#[Then('the response should not be in XML format')]
public function xmlAssertResponseIsNotXml(): void {
$content = $this->getSession()->getPage()->getContent();
// Resolve content the same way as xmlEnsureDocument(): prefer content set
// by the fixture steps, falling back to the live page content.
$content = $this->xmlTestContent ?? $this->getSession()->getPage()->getContent();

$doc = new \DOMDocument();
libxml_clear_errors();
Expand Down
21 changes: 21 additions & 0 deletions tests/behat/features/xml.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@ Feature: Check that XmlTrait works
When I go to "/sites/default/files/xml_with_warnings.xml"
Then the response should be in XML format

Scenario: Assert "Then the response should be in XML format" honours content set from a fixture file over the page content
When I go to "/sites/default/files/xml_invalid.xml"
And the response content from the file "xml_valid.xml"
Then the response should be in XML format

Scenario: Assert "Then the response should be in XML format" honours content set from a PyString over the page content
When I go to "/sites/default/files/xml_invalid.xml"
And the response content is the following:
"""
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<product id="p1">Blue Widget</product>
</catalog>
"""
Then the response should be in XML format

@trait:XmlTrait
Scenario: Assert that negative assertion for "Then the response should be in XML format" fails with an exception
Given some behat configuration
Expand All @@ -29,6 +45,11 @@ Feature: Check that XmlTrait works
When I go to "/sites/default/files/xml_invalid.xml"
Then the response should not be in XML format

Scenario: Assert "Then the response should not be in XML format" honours content set from a fixture file over the page content
When I go to "/sites/default/files/xml_valid.xml"
And the response content from the file "xml_invalid.xml"
Then the response should not be in XML format

@trait:XmlTrait
Scenario: Assert that negative assertion for "Then the response should not be in XML format" fails with an error
Given some behat configuration
Expand Down