Skip to content

Commit

Permalink
MDL-67673 phpunit: Remove deprecated assertContains() uses on strings
Browse files Browse the repository at this point in the history
Both assertContains() and assertNotContains() are deprecated in PHPUnit 8
for operations on strings. Also the optional case parameter is. All uses
must be changed to one of:

- assertStringContainsString()
- assertStringContainsStringIgnoringCase()
- assertStringNotContainsString()
- assertStringNotContainsStringIgnoringCase()

More info: sebastianbergmann/phpunit#3422

Regexp to find all uses:

ag 'assert(Not)?Contains\('
  • Loading branch information
stronk7 committed Aug 31, 2020
1 parent 8968342 commit f235d93
Show file tree
Hide file tree
Showing 11 changed files with 285 additions and 285 deletions.
18 changes: 9 additions & 9 deletions analytics/tests/dataset_manager_test.php
Expand Up @@ -60,10 +60,10 @@ public function test_create_dataset() {
$f1 = $dataset1->store($dataset1data);

$f1contents = $f1->get_content();
$this->assertContains('yeah', $f1contents);
$this->assertContains('var1', $f1contents);
$this->assertContains('value1', $f1contents);
$this->assertContains('header1', $f1contents);
$this->assertStringContainsString('yeah', $f1contents);
$this->assertStringContainsString('var1', $f1contents);
$this->assertStringContainsString('value1', $f1contents);
$this->assertStringContainsString('header1', $f1contents);
}

/**
Expand All @@ -86,11 +86,11 @@ public function test_merge_datasets() {
\core_analytics\dataset_manager::LABELLED_FILEAREA);

$mergedfilecontents = $merged->get_content();
$this->assertContains('yeah', $mergedfilecontents);
$this->assertContains('no', $mergedfilecontents);
$this->assertContains('var1', $mergedfilecontents);
$this->assertContains('value1', $mergedfilecontents);
$this->assertContains('header1', $mergedfilecontents);
$this->assertStringContainsString('yeah', $mergedfilecontents);
$this->assertStringContainsString('no', $mergedfilecontents);
$this->assertStringContainsString('var1', $mergedfilecontents);
$this->assertStringContainsString('value1', $mergedfilecontents);
$this->assertStringContainsString('header1', $mergedfilecontents);
}

/**
Expand Down
14 changes: 7 additions & 7 deletions lib/form/tests/filetypes_util_test.php
Expand Up @@ -129,9 +129,9 @@ public function test_describe_file_types() {
$this->assertEquals('.mudrd8mz', $desc[0]->extensions);

$this->assertEquals('Image (JPEG)', $desc[2]->description);
$this->assertContains('.jpg', $desc[2]->extensions);
$this->assertContains('.jpeg', $desc[2]->extensions);
$this->assertContains('.jpe', $desc[2]->extensions);
$this->assertStringContainsString('.jpg', $desc[2]->extensions);
$this->assertStringContainsString('.jpeg', $desc[2]->extensions);
$this->assertStringContainsString('.jpe', $desc[2]->extensions);

// Check that it can describe groups and mimetypes too.
$desc = $util->describe_file_types('audio text/plain');
Expand All @@ -141,12 +141,12 @@ public function test_describe_file_types() {
$this->assertEquals(2, count($desc));

$this->assertEquals('Audio files', $desc[0]->description);
$this->assertContains('.mp3', $desc[0]->extensions);
$this->assertContains('.wav', $desc[0]->extensions);
$this->assertContains('.ogg', $desc[0]->extensions);
$this->assertStringContainsString('.mp3', $desc[0]->extensions);
$this->assertStringContainsString('.wav', $desc[0]->extensions);
$this->assertStringContainsString('.ogg', $desc[0]->extensions);

$this->assertEquals('Text file', $desc[1]->description);
$this->assertContains('.txt', $desc[1]->extensions);
$this->assertStringContainsString('.txt', $desc[1]->extensions);

// Empty.
$desc = $util->describe_file_types('');
Expand Down
16 changes: 8 additions & 8 deletions lib/tests/grouplib_test.php
Expand Up @@ -994,29 +994,29 @@ public function test_groups_allgroups_course_menu() {
// Now user can access one of the group. We can't assert an exact match here because of random ids generated by yui. So do
// partial match to see if all groups are listed or not.
$html = groups_allgroups_course_menu($course, 'someurl.php');
$this->assertContains(format_string($group1->name), $html);
$this->assertNotContains(format_string($group2->name), $html);
$this->assertStringContainsString(format_string($group1->name), $html);
$this->assertStringNotContainsString(format_string($group2->name), $html);

$this->setAdminUser();

// Now user can access everything.
$html = groups_allgroups_course_menu($course, 'someurl.php');
$this->assertContains(format_string($group1->name), $html);
$this->assertContains(format_string($group2->name), $html);
$this->assertStringContainsString(format_string($group1->name), $html);
$this->assertStringContainsString(format_string($group2->name), $html);

// Make sure separate groups mode, doesn't change anything.
$course->groupmode = SEPARATEGROUPS;
update_course($course);
$html = groups_allgroups_course_menu($course, 'someurl.php');
$this->assertContains(format_string($group1->name), $html);
$this->assertContains(format_string($group2->name), $html);
$this->assertStringContainsString(format_string($group1->name), $html);
$this->assertStringContainsString(format_string($group2->name), $html);

// Make sure Visible groups mode, doesn't change anything.
$course->groupmode = VISIBLEGROUPS;
update_course($course);
$html = groups_allgroups_course_menu($course, 'someurl.php');
$this->assertContains(format_string($group1->name), $html);
$this->assertContains(format_string($group2->name), $html);
$this->assertStringContainsString(format_string($group1->name), $html);
$this->assertStringContainsString(format_string($group2->name), $html);

// Let us test activegroup changes now.
$this->setUser($user);
Expand Down
88 changes: 44 additions & 44 deletions lib/tests/medialib_test.php
Expand Up @@ -215,7 +215,7 @@ public function test_embed_url_fallbacks() {
\core\plugininfo\media::set_enabled_plugins('');
$manager = core_media_manager::instance();
$t = $manager->embed_url($url);
$this->assertContains($link, $t);
$this->assertStringContainsString($link, $t);

// Enable media players that can play the same media formats. (ie. test & html5audio for mp3 files, etc.)
\core\plugininfo\media::set_enabled_plugins('test,html5video,html5audio,swf');
Expand All @@ -231,31 +231,31 @@ public function test_embed_url_fallbacks() {

switch ($format) {
case 'mp3':
$this->assertContains($test, $textwithlink);
$this->assertNotContains($html5video, $textwithlink);
$this->assertContains($html5audio, $textwithlink);
$this->assertNotContains($swf, $textwithlink);
$this->assertContains($link, $textwithlink);

$this->assertContains($test, $textwithoutlink);
$this->assertNotContains($html5video, $textwithoutlink);
$this->assertContains($html5audio, $textwithoutlink);
$this->assertNotContains($swf, $textwithoutlink);
$this->assertNotContains($link, $textwithoutlink);
$this->assertStringContainsString($test, $textwithlink);
$this->assertStringNotContainsString($html5video, $textwithlink);
$this->assertStringContainsString($html5audio, $textwithlink);
$this->assertStringNotContainsString($swf, $textwithlink);
$this->assertStringContainsString($link, $textwithlink);

$this->assertStringContainsString($test, $textwithoutlink);
$this->assertStringNotContainsString($html5video, $textwithoutlink);
$this->assertStringContainsString($html5audio, $textwithoutlink);
$this->assertStringNotContainsString($swf, $textwithoutlink);
$this->assertStringNotContainsString($link, $textwithoutlink);
break;

case 'mp4':
$this->assertContains($test, $textwithlink);
$this->assertContains($html5video, $textwithlink);
$this->assertNotContains($html5audio, $textwithlink);
$this->assertNotContains($swf, $textwithlink);
$this->assertContains($link, $textwithlink);

$this->assertContains($test, $textwithoutlink);
$this->assertContains($html5video, $textwithoutlink);
$this->assertNotContains($html5audio, $textwithoutlink);
$this->assertNotContains($swf, $textwithoutlink);
$this->assertNotContains($link, $textwithoutlink);
$this->assertStringContainsString($test, $textwithlink);
$this->assertStringContainsString($html5video, $textwithlink);
$this->assertStringNotContainsString($html5audio, $textwithlink);
$this->assertStringNotContainsString($swf, $textwithlink);
$this->assertStringContainsString($link, $textwithlink);

$this->assertStringContainsString($test, $textwithoutlink);
$this->assertStringContainsString($html5video, $textwithoutlink);
$this->assertStringNotContainsString($html5audio, $textwithoutlink);
$this->assertStringNotContainsString($swf, $textwithoutlink);
$this->assertStringNotContainsString($link, $textwithoutlink);
break;

default:
Expand All @@ -275,12 +275,12 @@ public function test_embed_url_swf() {
// Without any options...
$url = new moodle_url('http://example.org/test.swf');
$t = $manager->embed_url($url);
$this->assertNotContains('</object>', $t);
$this->assertStringNotContainsString('</object>', $t);

// ...and with the 'no it's safe, I checked it' option.
$url = new moodle_url('http://example.org/test.swf');
$t = $manager->embed_url($url, '', 0, 0, array(core_media_manager::OPTION_TRUSTED => true));
$this->assertContains('</object>', $t);
$this->assertStringContainsString('</object>', $t);
}

/**
Expand All @@ -299,7 +299,7 @@ public function test_slash_arguments() {
// Format: mp3.
$url = new moodle_url('http://example.org/pluginfile.php?file=x/y/z/test.mp3');
$t = $manager->embed_url($url);
$this->assertContains('</audio>', $t);
$this->assertStringContainsString('</audio>', $t);
}

/**
Expand All @@ -316,8 +316,8 @@ public function test_embed_or_blank() {
// Embed that does match something should still include the link too.
$url = new moodle_url('http://example.org/test.ogg');
$t = $manager->embed_url($url, '', 0, 0, $options);
$this->assertContains('</audio>', $t);
$this->assertContains('mediafallbacklink', $t);
$this->assertStringContainsString('</audio>', $t);
$this->assertStringContainsString('mediafallbacklink', $t);

// Embed that doesn't match something should be totally blank.
$url = new moodle_url('http://example.org/test.mp4');
Expand All @@ -343,19 +343,19 @@ public function test_embed_url_size() {

// HTML5 default size - specifies core width and does not specify height.
$t = $manager->embed_url($url);
$this->assertContains('width="' . $CFG->media_default_width . '"', $t);
$this->assertNotContains('height', $t);
$this->assertStringContainsString('width="' . $CFG->media_default_width . '"', $t);
$this->assertStringNotContainsString('height', $t);

// HTML5 specified size - specifies both.
$t = $manager->embed_url($url, '', '666', '101');
$this->assertContains('width="666"', $t);
$this->assertContains('height="101"', $t);
$this->assertStringContainsString('width="666"', $t);
$this->assertStringContainsString('height="101"', $t);

// HTML5 size specified in url, overrides call.
$url = new moodle_url('http://example.org/test.mp4?d=123x456');
$t = $manager->embed_url($url, '', '666', '101');
$this->assertContains('width="123"', $t);
$this->assertContains('height="456"', $t);
$this->assertStringContainsString('width="123"', $t);
$this->assertStringContainsString('height="456"', $t);
}

/**
Expand All @@ -372,11 +372,11 @@ public function test_embed_url_name() {

// HTML5 default name - use filename.
$t = $manager->embed_url($url);
$this->assertContains('title="test.mp4"', $t);
$this->assertStringContainsString('title="test.mp4"', $t);

// HTML5 specified name - check escaping.
$t = $manager->embed_url($url, 'frog & toad');
$this->assertContains('title="frog &amp; toad"', $t);
$this->assertStringContainsString('title="frog &amp; toad"', $t);
}

/**
Expand Down Expand Up @@ -439,10 +439,10 @@ public function test_embed_alternatives() {
$t = $manager->embed_alternatives($urls);

// HTML5 sources - mp4, but not ogv, flv or webm (not supported in Safari).
$this->assertContains('<source src="http://example.org/test.mp4"', $t);
$this->assertNotContains('<source src="http://example.org/test.ogv"', $t);
$this->assertNotContains('<source src="http://example.org/test.webm"', $t);
$this->assertNotContains('<source src="http://example.org/test.flv"', $t);
$this->assertStringContainsString('<source src="http://example.org/test.mp4"', $t);
$this->assertStringNotContainsString('<source src="http://example.org/test.ogv"', $t);
$this->assertStringNotContainsString('<source src="http://example.org/test.webm"', $t);
$this->assertStringNotContainsString('<source src="http://example.org/test.flv"', $t);

// FLV is before the video tag (indicating html5 is used as fallback to flv
// and not vice versa).
Expand All @@ -453,10 +453,10 @@ public function test_embed_alternatives() {
$t = $manager->embed_alternatives($urls);

// HTML5 sources - mp4, ogv and webm, but not flv.
$this->assertContains('<source src="http://example.org/test.mp4"', $t);
$this->assertContains('<source src="http://example.org/test.ogv"', $t);
$this->assertContains('<source src="http://example.org/test.webm"', $t);
$this->assertNotContains('<source src="http://example.org/test.flv"', $t);
$this->assertStringContainsString('<source src="http://example.org/test.mp4"', $t);
$this->assertStringContainsString('<source src="http://example.org/test.ogv"', $t);
$this->assertStringContainsString('<source src="http://example.org/test.webm"', $t);
$this->assertStringNotContainsString('<source src="http://example.org/test.flv"', $t);
}

/**
Expand Down
24 changes: 12 additions & 12 deletions media/player/videojs/tests/player_test.php
Expand Up @@ -246,8 +246,8 @@ public function test_embed_media() {
* @param string $t output of core_media_manager::embed_url.
*/
protected function youtube_plugin_engaged($t) {
$this->assertContains('mediaplugin_videojs', $t);
$this->assertContains('data-setup-lazy="{&quot;techOrder&quot;: [&quot;youtube&quot;]', $t);
$this->assertStringContainsString('mediaplugin_videojs', $t);
$this->assertStringContainsString('data-setup-lazy="{&quot;techOrder&quot;: [&quot;youtube&quot;]', $t);
}

/**
Expand All @@ -271,18 +271,18 @@ public function test_youtube() {
$url = new moodle_url('https://www.youtube.com/watch?v=dv2f_xfmbD8&index=4&list=PLxcO_MFWQBDcyn9xpbmx601YSDlDcTcr0');
$t = $manager->embed_url($url);
$this->youtube_plugin_engaged($t);
$this->assertContains('list=PLxcO_MFWQBDcyn9xpbmx601YSDlDcTcr0', $t);
$this->assertStringContainsString('list=PLxcO_MFWQBDcyn9xpbmx601YSDlDcTcr0', $t);

// Format: youtube playlist - not supported.
$url = new moodle_url('http://www.youtube.com/view_play_list?p=PL6E18E2927047B662');
$t = $manager->embed_url($url);
$this->assertNotContains('mediaplugin_videojs', $t);
$this->assertStringNotContainsString('mediaplugin_videojs', $t);
$url = new moodle_url('http://www.youtube.com/playlist?list=PL6E18E2927047B662');
$t = $manager->embed_url($url);
$this->assertNotContains('mediaplugin_videojs', $t);
$this->assertStringNotContainsString('mediaplugin_videojs', $t);
$url = new moodle_url('http://www.youtube.com/p/PL6E18E2927047B662');
$t = $manager->embed_url($url);
$this->assertNotContains('mediaplugin_videojs', $t);
$this->assertStringNotContainsString('mediaplugin_videojs', $t);
}

/**
Expand Down Expand Up @@ -317,7 +317,7 @@ public function test_youtube_start_time(string $url, int $expectedstart) {
$embedcode = core_media_manager::instance()->embed_url(new moodle_url($url));

$this->youtube_plugin_engaged($embedcode);
$this->assertContains("&quot;youtube&quot;: {&quot;start&quot;: &quot;{$expectedstart}&quot;}", $embedcode);
$this->assertStringContainsString("&quot;youtube&quot;: {&quot;start&quot;: &quot;{$expectedstart}&quot;}", $embedcode);
}

/**
Expand All @@ -326,8 +326,8 @@ public function test_youtube_start_time(string $url, int $expectedstart) {
* @param string $t output of core_media_manager::embed_url.
*/
protected function flash_plugin_engaged($t) {
$this->assertContains('mediaplugin_videojs', $t);
$this->assertContains('data-setup-lazy="{&quot;techOrder&quot;: [&quot;flash&quot;, &quot;html5&quot;]', $t);
$this->assertStringContainsString('mediaplugin_videojs', $t);
$this->assertStringContainsString('data-setup-lazy="{&quot;techOrder&quot;: [&quot;flash&quot;, &quot;html5&quot;]', $t);
}

/**
Expand All @@ -349,7 +349,7 @@ public function test_flash() {
set_config('useflash', 0, 'media_videojs');
$url = new moodle_url('http://example.org/some_filename.flv');
$t = $manager->embed_url($url);
$this->assertNotContains('mediaplugin_videojs', $t);
$this->assertStringNotContainsString('mediaplugin_videojs', $t);
$this->assertRegExp('~<a class="mediafallbacklink" href="http://example.org/some_filename.flv">some_filename.flv</a>~', $t);
}

Expand All @@ -364,15 +364,15 @@ public function test_rtmp() {
set_config('rtmp', 0, 'media_videojs');
$url = new moodle_url('rtmp://example.com/fms&mp4:path/to/file.mp4');
$t = $manager->embed_url($url);
$this->assertNotContains('mediaplugin_videojs', $t);
$this->assertStringNotContainsString('mediaplugin_videojs', $t);
$this->assertRegExp('~<a class="mediafallbacklink" href="rtmp://example.com/fms&mp4:path/to/file.mp4">file.mp4</a>~', $t);

// RTMP enabled, flash disabled.
set_config('useflash', 0, 'media_videojs');
set_config('rtmp', 1, 'media_videojs');
$url = new moodle_url('rtmp://example.com/fms&mp4:path/to/file.mp4');
$t = $manager->embed_url($url);
$this->assertNotContains('mediaplugin_videojs', $t);
$this->assertStringNotContainsString('mediaplugin_videojs', $t);
$this->assertRegExp('~<a class="mediafallbacklink" href="rtmp://example.com/fms&mp4:path/to/file.mp4">file.mp4</a>~', $t);

// RTMP enabled, flash enabled, rtmp/mp4 type expected.
Expand Down

0 comments on commit f235d93

Please sign in to comment.