Skip to content

Commit 1ebffe7

Browse files
authored
Merge pull request #3324 from samsonasik/support-multibyte-search-on-domparser-see
Fixes #3319 add multibyte support on DOMParser::see()
2 parents 6e5ffa3 + d8e6ea3 commit 1ebffe7

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

system/Test/DOMParser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ public function see(string $search = null, string $element = null): bool
142142
// If Element is null, we're just scanning for text
143143
if (is_null($element))
144144
{
145-
$content = $this->dom->saveHTML();
146-
return strpos($content, $search) !== false;
145+
$content = $this->dom->saveHTML($this->dom->documentElement);
146+
return mb_strpos($content, $search) !== false;
147147
}
148148

149149
$result = $this->doXPath($search, $element);

tests/system/Test/DOMParserTest.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,25 @@ public function testParseSelectorWithAttribute()
6666
$this->assertEquals(['href' => 'http://example.com'], $selector['attr']);
6767
}
6868

69-
public function testSeeText()
69+
public function provideText()
70+
{
71+
return [
72+
['Hello World'],
73+
['Hellö Wörld'],
74+
];
75+
}
76+
77+
/**
78+
* @dataProvider provideText
79+
*/
80+
public function testSeeText($text)
7081
{
7182
$dom = new DOMParser();
7283

73-
$html = '<html><body><h1>Hello World</h1></body></html>';
84+
$html = '<html><body><h1>' . $text . '</h1></body></html>';
7485
$dom->withString($html);
7586

76-
$this->assertTrue($dom->see('Hello World'));
87+
$this->assertTrue($dom->see($text));
7788
}
7889

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

99-
public function testSeeElement()
110+
/**
111+
* @dataProvider provideText
112+
*/
113+
public function testSeeElement($text)
100114
{
101115
$dom = new DOMParser();
102116

103-
$html = '<html><body><h1>Hello World</h1></body></html>';
117+
$html = '<html><body><h1> ' . $text . '</h1></body></html>';
104118
$dom->withString($html);
105119

106-
$this->assertTrue($dom->see('Hello World', 'h1'));
120+
$this->assertTrue($dom->see($text, 'h1'));
107121
}
108122

109123
public function testSeeElementPartialText()

0 commit comments

Comments
 (0)