MDL-82702 filter_emailprotect: Fix broken unit test

This commit is contained in:
Andrew Nicols 2024-08-05 09:31:28 +08:00
parent ceca66c6e9
commit 7e50e55a46
No known key found for this signature in database
GPG Key ID: 6D1E3157C8CFBF14
2 changed files with 26 additions and 5 deletions

View File

@ -55,7 +55,7 @@ class text_filter extends \core_filters\text_filter {
* @return string
*/
private function alter_email($matches) {
return $matches[1].obfuscate_text($matches[2]).$matches[3];
return $matches[1] . obfuscate_text($matches[2]) . $matches[3];
}
/**

View File

@ -36,9 +36,18 @@ final class text_filter_test extends \advanced_testcase {
public function test_filter(
string $expression,
string $text,
bool $exactmatch,
): void {
$filter = new text_filter(\core\context\system::instance(), []);
$this->assertMatchesRegularExpression($expression, $text);
$result = $filter->filter($text);
$this->assertMatchesRegularExpression($expression, $result);
if ($exactmatch) {
$this->assertEquals($text, $result);
} else {
$this->assertNotEquals($text, $result);
}
}
/**
@ -50,11 +59,23 @@ final class text_filter_test extends \advanced_testcase {
$email = 'chaise@example.com';
return [
// No email address found.
['/Hello, world!/', 'Hello, world!'],
[
'/Hello, world!/',
'Hello, world!',
true,
],
// Email addresses present.
// Note: The obfuscation randomly choose which chars to obfuscate.
['/.*@.*/', $email],
["~<a href='mailto:.*@.*'>.*@.*</a>~", "<a href='mailto:$email'>$email</a>"],
[
'/.*(@|&#64;).*/',
$email,
false,
],
[
"~<a href=\".*:.*(@|&#64;).*\">.*(@|&#64;).*</a>~",
"<a href='mailto:$email'>$email</a>",
false,
],
];
}
}