Skip to content

Commit

Permalink
Merge pull request #4070 from michalsn/fix/assertSee-fix
Browse files Browse the repository at this point in the history
Fix DOMParser rules to search also outside the body tag
  • Loading branch information
paulbalandan authored Jan 7, 2021
2 parents 440ca29 + d0df601 commit 02725d8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 3 additions & 3 deletions system/Test/DOMParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,19 +237,19 @@ protected function doXPath(?string $search, string $element, array $paths = [])
{
$path = empty($selector['tag'])
? "id(\"{$selector['id']}\")"
: "//body//{$selector['tag']}[@id=\"{$selector['id']}\"]";
: "//{$selector['tag']}[@id=\"{$selector['id']}\"]";
}
// By Class
elseif (! empty($selector['class']))
{
$path = empty($selector['tag'])
? "//*[@class=\"{$selector['class']}\"]"
: "//body//{$selector['tag']}[@class=\"{$selector['class']}\"]";
: "//{$selector['tag']}[@class=\"{$selector['class']}\"]";
}
// By tag only
elseif (! empty($selector['tag']))
{
$path = "//body//{$selector['tag']}";
$path = "//{$selector['tag']}";
}

if (! empty($selector['attr']))
Expand Down
13 changes: 13 additions & 0 deletions tests/system/Test/DOMParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@ public function testSeeHTML()
$this->assertTrue($dom->see('<h1>'));
}

/**
* @see https://github.com/codeigniter4/CodeIgniter4/issues/3984
*/
public function testSeeHTMLOutsideBodyTag()
{
$dom = new DOMParser();

$html = '<html><head><title>My Title</title></head><body><h1>Hello World</h1></body></html>';
$dom->withString($html);

$this->assertTrue($dom->see('My Title', 'title'));
}

public function testSeeFail()
{
$dom = new DOMParser();
Expand Down

0 comments on commit 02725d8

Please sign in to comment.