From 98fea9b4d28a4d048ebaaa9016390eb9f70f5e64 Mon Sep 17 00:00:00 2001 From: Jay Oswald Date: Fri, 23 Feb 2024 16:38:59 +1100 Subject: [PATCH 1/2] update deprecated and broken tests --- tests/filter_test.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/filter_test.php b/tests/filter_test.php index 205fb11..f1ce1cb 100644 --- a/tests/filter_test.php +++ b/tests/filter_test.php @@ -96,7 +96,7 @@ public function test_empty_image() { ]; foreach ($sizes as $size) { $emptyimage = phpunit_util::call_internal_method($filter, 'empty_image', $size, get_class($filter)); - $this->assertContains('width="'.$size[0].'" height="'.$size[1].'"', $emptyimage); + $this->assertStringContainsString('width="'.$size[0].'" height="'.$size[1].'"', $emptyimage); } } @@ -270,8 +270,8 @@ public function test_apply_loadonvisible() { // Test filter plugin img, lazy load. $regex = '/img data-loadonvisible="'.str_replace('~pathid~', '(?:[0-9]*)', preg_quote($loadonvisibleurl, '/')).'/'; - $this->assertRegExp($regex, $str); - $this->assertContains('src="data:image/svg+xml;utf8,', $str); + $this->assertMatchesRegularExpression($regex, $str); + $this->assertStringContainsString('src="data:image/svg+xml;utf8,', $str); } @@ -318,7 +318,7 @@ public function test_apply_img_tag() { $postfilterurl = $this->filter_imageopt_url_from_file($file, $maxwidth); $regex = '/'.str_replace('~pathid~', '(?:[0-9]*)', preg_quote($postfilterurl, '/')).'/'; - $this->assertRegExp($regex, $processed); + $this->assertMatchesRegularExpression($regex, $processed); } @@ -346,29 +346,29 @@ public function test_filter() { $filter = new filter_imageopt($context, []); $filtered = $filter->filter($labeltxt); $prefilterurl = $CFG->wwwroot.'/pluginfile.php/'.$context->id.'/mod_label/intro/0/testpng_2880x1800.png'; - $this->assertContains($prefilterurl, $labeltxt); + $this->assertStringContainsString($prefilterurl, $labeltxt); $postfilterurl = $this->filter_imageopt_url_from_file($file, $maxwidth); $regex = '/src="'.str_replace('~pathid~', '(?:[0-9]*)', preg_quote($postfilterurl, '/')).'/'; - $this->assertRegExp($regex, $filtered); + $this->assertMatchesRegularExpression($regex, $filtered); // We need a space before src so it doesn't trigger on original-src. - $this->assertNotContains(' src="'.$prefilterurl, $filtered); - $this->assertNotContains('data-loadonvisible="'.$postfilterurl, $filtered); - $this->assertNotContains('data-loadonvisible="'.$prefilterurl, $filtered); + $this->assertStringNotContainsString(' src="'.$prefilterurl, $filtered); + $this->assertStringNotContainsString('data-loadonvisible="'.$postfilterurl, $filtered); + $this->assertStringNotContainsString('data-loadonvisible="'.$prefilterurl, $filtered); // Test filter plugin img, lazy load. set_config('loadonvisible', '0', 'filter_imageopt'); $filter = new filter_imageopt($context, []); $filtered = $filter->filter($labeltxt); $prefilterurl = $CFG->wwwroot.'/pluginfile.php/'.$context->id.'/mod_label/intro/0/testpng_2880x1800.png'; - $this->assertContains($prefilterurl, $labeltxt); + $this->assertStringContainsString($prefilterurl, $labeltxt); $postfilterurl = $this->filter_imageopt_url_from_file($file, $maxwidth); $regex = '/data-loadonvisible="'.str_replace('~pathid~', '(?:[0-9]*)', preg_quote($postfilterurl, '/')).'/'; - $this->assertRegExp($regex, $filtered); + $this->assertMatchesRegularExpression($regex, $filtered); - $this->assertNotContains('data-loadonvisible="'.$prefilterurl, $filtered); - $this->assertNotContains('src="'.$postfilterurl, $filtered); - $this->assertNotContains('src="'.$prefilterurl, $filtered); + $this->assertStringNotContainsString('data-loadonvisible="'.$prefilterurl, $filtered); + $this->assertStringNotContainsString('src="'.$postfilterurl, $filtered); + $this->assertStringNotContainsString('src="'.$prefilterurl, $filtered); } } From 9ba3bd81a4af6bdc1d9fc326506797044604b819 Mon Sep 17 00:00:00 2001 From: Jay Oswald Date: Fri, 23 Feb 2024 16:54:56 +1100 Subject: [PATCH 2/2] remove regex, not 3.9 compadable --- tests/filter_test.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/filter_test.php b/tests/filter_test.php index f1ce1cb..b43d359 100644 --- a/tests/filter_test.php +++ b/tests/filter_test.php @@ -270,7 +270,7 @@ public function test_apply_loadonvisible() { // Test filter plugin img, lazy load. $regex = '/img data-loadonvisible="'.str_replace('~pathid~', '(?:[0-9]*)', preg_quote($loadonvisibleurl, '/')).'/'; - $this->assertMatchesRegularExpression($regex, $str); + $this->assertRegExp($regex, $str); $this->assertStringContainsString('src="data:image/svg+xml;utf8,', $str); } @@ -318,7 +318,7 @@ public function test_apply_img_tag() { $postfilterurl = $this->filter_imageopt_url_from_file($file, $maxwidth); $regex = '/'.str_replace('~pathid~', '(?:[0-9]*)', preg_quote($postfilterurl, '/')).'/'; - $this->assertMatchesRegularExpression($regex, $processed); + $this->assertRegExp($regex, $processed); } @@ -349,7 +349,7 @@ public function test_filter() { $this->assertStringContainsString($prefilterurl, $labeltxt); $postfilterurl = $this->filter_imageopt_url_from_file($file, $maxwidth); $regex = '/src="'.str_replace('~pathid~', '(?:[0-9]*)', preg_quote($postfilterurl, '/')).'/'; - $this->assertMatchesRegularExpression($regex, $filtered); + $this->assertRegExp($regex, $filtered); // We need a space before src so it doesn't trigger on original-src. $this->assertStringNotContainsString(' src="'.$prefilterurl, $filtered); @@ -365,7 +365,7 @@ public function test_filter() { $postfilterurl = $this->filter_imageopt_url_from_file($file, $maxwidth); $regex = '/data-loadonvisible="'.str_replace('~pathid~', '(?:[0-9]*)', preg_quote($postfilterurl, '/')).'/'; - $this->assertMatchesRegularExpression($regex, $filtered); + $this->assertRegExp($regex, $filtered); $this->assertStringNotContainsString('data-loadonvisible="'.$prefilterurl, $filtered); $this->assertStringNotContainsString('src="'.$postfilterurl, $filtered);