Skip to content

Commit

Permalink
Merge pull request #3324 from samsonasik/support-multibyte-search-on-…
Browse files Browse the repository at this point in the history
…domparser-see

Fixes #3319 add multibyte support on DOMParser::see()
  • Loading branch information
lonnieezell authored Jul 16, 2020
2 parents 6e5ffa3 + d8e6ea3 commit 1ebffe7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
4 changes: 2 additions & 2 deletions system/Test/DOMParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ public function see(string $search = null, string $element = null): bool
// If Element is null, we're just scanning for text
if (is_null($element))
{
$content = $this->dom->saveHTML();
return strpos($content, $search) !== false;
$content = $this->dom->saveHTML($this->dom->documentElement);
return mb_strpos($content, $search) !== false;
}

$result = $this->doXPath($search, $element);
Expand Down
26 changes: 20 additions & 6 deletions tests/system/Test/DOMParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,25 @@ public function testParseSelectorWithAttribute()
$this->assertEquals(['href' => 'http://example.com'], $selector['attr']);
}

public function testSeeText()
public function provideText()
{
return [
['Hello World'],
['Hellö Wörld'],
];
}

/**
* @dataProvider provideText
*/
public function testSeeText($text)
{
$dom = new DOMParser();

$html = '<html><body><h1>Hello World</h1></body></html>';
$html = '<html><body><h1>' . $text . '</h1></body></html>';
$dom->withString($html);

$this->assertTrue($dom->see('Hello World'));
$this->assertTrue($dom->see($text));
}

public function testSeeHTML()
Expand All @@ -96,14 +107,17 @@ public function testSeeFail()
$this->assertFalse($dom->see('Hello Worlds'));
}

public function testSeeElement()
/**
* @dataProvider provideText
*/
public function testSeeElement($text)
{
$dom = new DOMParser();

$html = '<html><body><h1>Hello World</h1></body></html>';
$html = '<html><body><h1> ' . $text . '</h1></body></html>';
$dom->withString($html);

$this->assertTrue($dom->see('Hello World', 'h1'));
$this->assertTrue($dom->see($text, 'h1'));
}

public function testSeeElementPartialText()
Expand Down

0 comments on commit 1ebffe7

Please sign in to comment.