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 Sep 29, 2020
1 parent bc393d2 commit 7bc14f8
Show file tree
Hide file tree
Showing 112 changed files with 721 additions and 721 deletions.
28 changes: 14 additions & 14 deletions admin/tool/behat/tests/manager_util_test.php
Expand Up @@ -165,7 +165,7 @@ public function test_get_config_file_contents_with_single_run() {
$this->assertCount(count($paths), $suites[$themename]['paths']);

foreach ($paths as $key => $feature) {
$this->assertContains($feature, $suites[$themename]['paths'][$key]);
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}

Expand Down Expand Up @@ -219,7 +219,7 @@ public function test_get_config_file_contents_with_single_run_no_theme() {
$this->assertCount(count($paths), $suites[$themename]['paths']);

foreach ($paths as $key => $feature) {
$this->assertContains($feature, $suites[$themename]['paths'][$key]);
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}

Expand Down Expand Up @@ -264,7 +264,7 @@ public function test_get_config_file_contents_with_parallel_run() {
$this->assertCount(count($paths), $suites[$themename]['paths']);

foreach ($paths as $key => $feature) {
$this->assertContains($feature, $suites[$themename]['paths'][$key]);
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}

Expand Down Expand Up @@ -295,7 +295,7 @@ public function test_get_config_file_contents_with_parallel_run() {
$this->assertCount(count($paths), $suites[$themename]['paths']);

foreach ($paths as $key => $feature) {
$this->assertContains($feature, $suites[$themename]['paths'][$key]);
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}
// Check contexts.
Expand Down Expand Up @@ -324,7 +324,7 @@ public function test_get_config_file_contents_with_parallel_run() {
$this->assertCount(count($paths), $suites[$themename]['paths']);

foreach ($paths as $key => $feature) {
$this->assertContains($feature, $suites[$themename]['paths'][$key]);
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}
// Check contexts.
Expand Down Expand Up @@ -368,7 +368,7 @@ public function test_get_config_file_contents_with_parallel_run_optimize_tags()
$this->assertCount(count($paths), $suites[$themename]['paths']);

foreach ($paths as $key => $feature) {
$this->assertContains($feature, $suites[$themename]['paths'][$key]);
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}
// Check contexts.
Expand Down Expand Up @@ -399,7 +399,7 @@ public function test_get_config_file_contents_with_parallel_run_optimize_tags()
$this->assertCount(count($paths), $suites[$themename]['paths']);

foreach ($paths as $key => $feature) {
$this->assertContains($feature, $suites[$themename]['paths'][$key]);
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}
// Check contexts.
Expand Down Expand Up @@ -428,7 +428,7 @@ public function test_get_config_file_contents_with_parallel_run_optimize_tags()
$this->assertCount(count($paths), $suites[$themename]['paths']);

foreach ($paths as $key => $feature) {
$this->assertContains($feature, $suites[$themename]['paths'][$key]);
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}
// Check contexts.
Expand Down Expand Up @@ -532,7 +532,7 @@ public function test_get_config_file_contents_with_blacklisted_tags() {
$this->assertCount(count($paths), $suites[$themename]['paths']);

foreach ($paths as $key => $feature) {
$this->assertContains($feature, $suites[$themename]['paths'][$key]);
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}
// Check contexts.
Expand Down Expand Up @@ -611,7 +611,7 @@ public function test_get_config_file_contents_with_blacklisted_features_contexts
$this->assertCount(count($paths), $suites[$themename]['paths']);

foreach ($paths as $key => $feature) {
$this->assertContains($feature, $suites[$themename]['paths'][$key]);
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}
// Check contexts.
Expand Down Expand Up @@ -646,7 +646,7 @@ public function test_core_features_to_include_in_specified_theme() {
$this->assertCount(count($paths), $suites[$themename]['paths']);

foreach ($paths as $key => $feature) {
$this->assertContains($feature, $suites[$themename]['paths'][$key]);
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}

Expand All @@ -662,7 +662,7 @@ public function test_core_features_to_include_in_specified_theme() {
$this->assertCount(count($paths), $suites[$themename]['paths']);

foreach ($paths as $key => $feature) {
$this->assertContains($feature, $suites[$themename]['paths'][$key]);
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}

Expand All @@ -678,7 +678,7 @@ public function test_core_features_to_include_in_specified_theme() {
$this->assertCount(count($paths), $suites[$themename]['paths']);

foreach ($paths as $key => $feature) {
$this->assertContains($feature, $suites[$themename]['paths'][$key]);
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}

Expand All @@ -693,7 +693,7 @@ public function test_core_features_to_include_in_specified_theme() {
$this->assertCount(count($paths), $suites[$themename]['paths']);

foreach ($paths as $key => $feature) {
$this->assertContains($feature, $suites[$themename]['paths'][$key]);
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions admin/tool/dataprivacy/tests/api_test.php
Expand Up @@ -997,8 +997,8 @@ public function test_notify_dpo($byadmin, $type, $typestringid, $comments) {
$this->assertEquals($subject, $message->subject);
$this->assertEquals('tool_dataprivacy', $message->component);
$this->assertEquals('contactdataprotectionofficer', $message->eventtype);
$this->assertContains(fullname($dpo), $message->fullmessage);
$this->assertContains(fullname($user1), $message->fullmessage);
$this->assertStringContainsString(fullname($dpo), $message->fullmessage);
$this->assertStringContainsString(fullname($user1), $message->fullmessage);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions admin/tool/dataprivacy/tests/privacy_provider_test.php
Expand Up @@ -142,7 +142,7 @@ public function test_export_user_data() {
$this->assertEquals($strs->statusrejected, $data[1]->status);
$this->assertEquals($strs->creationmanual, $data[1]->creationmethod);
$this->assertEmpty($data[1]->comments);
$this->assertContains('Nope', $data[1]->dpocomment);
$this->assertStringContainsString('Nope', $data[1]->dpocomment);
$this->assertNotEmpty($data[1]->timecreated);
}

Expand Down Expand Up @@ -184,4 +184,4 @@ public function test_export_user_preferences() {

$this->assertEquals(6, $preferences[helper::PREF_REQUEST_PERPAGE]->value);
}
}
}
24 changes: 12 additions & 12 deletions admin/tool/httpsreplace/tests/httpsreplace_test.php
Expand Up @@ -155,7 +155,7 @@ public function test_upgrade_http_links($content, $ouputregex, $expectedcontent)
$finder->upgrade_http_links();

$summary = $DB->get_field('course', 'summary', ['id' => $course->id]);
$this->assertContains($expectedcontent, $summary);
$this->assertStringContainsString($expectedcontent, $summary);
}

/**
Expand Down Expand Up @@ -253,10 +253,10 @@ public function test_links_and_text() {
$this->assertCount(0, $results);

$summary = $DB->get_field('course', 'summary', ['id' => $course->id]);
$this->assertContains('http://intentionally.unavailable/page.php', $summary);
$this->assertContains('http://other.unavailable/page.php', $summary);
$this->assertNotContains('https://intentionally.unavailable', $summary);
$this->assertNotContains('https://other.unavailable', $summary);
$this->assertStringContainsString('http://intentionally.unavailable/page.php', $summary);
$this->assertStringContainsString('http://other.unavailable/page.php', $summary);
$this->assertStringNotContainsString('https://intentionally.unavailable', $summary);
$this->assertStringNotContainsString('https://other.unavailable', $summary);
}

/**
Expand All @@ -281,7 +281,7 @@ public function test_httpwwwroot() {

$finder->upgrade_http_links();
$summary = $DB->get_field('course', 'summary', ['id' => $course->id]);
$this->assertContains($CFG->wwwroot, $summary);
$this->assertStringContainsString($CFG->wwwroot, $summary);
}

/**
Expand All @@ -298,10 +298,10 @@ public function test_upgrade_http_links_excluded_tables() {
$output = ob_get_contents();
ob_end_clean();
$this->assertTrue($results);
$this->assertNotContains('https://somesite', $output);
$this->assertStringNotContainsString('https://somesite', $output);
$testconf = get_config('core', 'test_upgrade_http_links');
$this->assertContains('http://somesite', $testconf);
$this->assertNotContains('https://somesite', $testconf);
$this->assertStringContainsString('http://somesite', $testconf);
$this->assertStringNotContainsString('https://somesite', $testconf);
}

/**
Expand Down Expand Up @@ -331,8 +331,8 @@ public function test_renames() {
$finder->upgrade_http_links();

$summary = $DB->get_field('course', 'summary', ['id' => $course->id]);
$this->assertContains('https://secure.example.com', $summary);
$this->assertNotContains('http://example.com', $summary);
$this->assertStringContainsString('https://secure.example.com', $summary);
$this->assertStringNotContainsString('http://example.com', $summary);
$this->assertEquals('<script src="https://secure.example.com/test.js">' .
'<img src="https://secure.example.com/someimage.png">', $summary);
}
Expand Down Expand Up @@ -401,7 +401,7 @@ public function test_reserved_words() {
$finder->upgrade_http_links();

$record = $DB->get_record('reserved_words_temp', []);
$this->assertContains($expectedcontent, $record->where);
$this->assertStringContainsString($expectedcontent, $record->where);

$dbman->drop_table($table);
}
Expand Down
6 changes: 3 additions & 3 deletions admin/tool/mobile/tests/api_test.php
Expand Up @@ -132,7 +132,7 @@ public function test_pre_processor_message_send_callback() {
$email = reset($emails);

// Check we got the promotion text.
$this->assertContains($mobileappdownloadpage, quoted_printable_decode($email->body));
$this->assertStringContainsString($mobileappdownloadpage, quoted_printable_decode($email->body));
$sink->clear();

// Disable mobile so we don't get mobile promotions.
Expand All @@ -142,7 +142,7 @@ public function test_pre_processor_message_send_callback() {
$this->assertCount(1, $emails);
$email = reset($emails);
// Check we don't get the promotion text.
$this->assertNotContains($mobileappdownloadpage, quoted_printable_decode($email->body));
$this->assertStringNotContainsString($mobileappdownloadpage, quoted_printable_decode($email->body));
$sink->clear();

// Enable mobile again and set current user mobile token so we don't get mobile promotions.
Expand All @@ -158,7 +158,7 @@ public function test_pre_processor_message_send_callback() {
$this->assertCount(1, $emails);
$email = reset($emails);
// Check we don't get the promotion text.
$this->assertNotContains($mobileappdownloadpage, quoted_printable_decode($email->body));
$this->assertStringNotContainsString($mobileappdownloadpage, quoted_printable_decode($email->body));
$sink->clear();
$sink->close();
}
Expand Down
6 changes: 3 additions & 3 deletions admin/tool/mobile/tests/externallib_test.php
Expand Up @@ -158,11 +158,11 @@ public function test_get_public_config() {

$this->assertEquals('Google', $identityproviders[0]['name']);
$this->assertEquals($irecord->image, $identityproviders[0]['iconurl']);
$this->assertContains($CFG->wwwroot, $identityproviders[0]['url']);
$this->assertStringContainsString($CFG->wwwroot, $identityproviders[0]['url']);

$this->assertEquals('CAS', $identityproviders[1]['name']);
$this->assertEmpty($identityproviders[1]['iconurl']);
$this->assertContains($CFG->wwwroot, $identityproviders[1]['url']);
$this->assertStringContainsString($CFG->wwwroot, $identityproviders[1]['url']);

$this->assertEquals($expected, $result);

Expand All @@ -171,7 +171,7 @@ public function test_get_public_config() {
set_config('auth_logo', $newurl, 'auth_cas');
$result = external::get_public_config();
$result = external_api::clean_returnvalue(external::get_public_config_returns(), $result);
$this->assertContains($newurl, $result['identityproviders'][1]['iconurl']);
$this->assertStringContainsString($newurl, $result['identityproviders'][1]['iconurl']);
}

/**
Expand Down
20 changes: 10 additions & 10 deletions admin/tool/monitor/tests/eventobservers_test.php
Expand Up @@ -500,18 +500,18 @@ public function test_replace_placeholders() {

$this->assertRegExp('~<h2>.*' . preg_quote($event->get_url()->out(), '~') . '.*</h2>~', $msg->fullmessagehtml);
$this->assertRegExp('~<li>.*' . preg_quote($modurl->out(), '~') . '.*</li>~', $msg->fullmessagehtml);
$this->assertContains('<li><strong>'.$rule->get_name($context).'</strong></li>', $msg->fullmessagehtml);
$this->assertContains('<li>'.$rule->get_description($context).'</li>', $msg->fullmessagehtml);
$this->assertContains('<li>'.$rule->get_event_name().'</li>', $msg->fullmessagehtml);
$this->assertStringContainsString('<li><strong>'.$rule->get_name($context).'</strong></li>', $msg->fullmessagehtml);
$this->assertStringContainsString('<li>'.$rule->get_description($context).'</li>', $msg->fullmessagehtml);
$this->assertStringContainsString('<li>'.$rule->get_event_name().'</li>', $msg->fullmessagehtml);

$this->assertEquals(FORMAT_PLAIN, $msg->fullmessageformat);
$this->assertNotContains('<h2>', $msg->fullmessage);
$this->assertNotContains('##', $msg->fullmessage);
$this->assertContains(strtoupper($event->get_url()->out()), $msg->fullmessage);
$this->assertContains('* '.$modurl->out(), $msg->fullmessage);
$this->assertContains('* '.strtoupper($rule->get_name($context)), $msg->fullmessage);
$this->assertContains('* '.$rule->get_description($context), $msg->fullmessage);
$this->assertContains('* '.$rule->get_event_name(), $msg->fullmessage);
$this->assertStringNotContainsString('<h2>', $msg->fullmessage);
$this->assertStringNotContainsString('##', $msg->fullmessage);
$this->assertStringContainsString(strtoupper($event->get_url()->out()), $msg->fullmessage);
$this->assertStringContainsString('* '.$modurl->out(), $msg->fullmessage);
$this->assertStringContainsString('* '.strtoupper($rule->get_name($context)), $msg->fullmessage);
$this->assertStringContainsString('* '.$rule->get_description($context), $msg->fullmessage);
$this->assertStringContainsString('* '.$rule->get_event_name(), $msg->fullmessage);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/templatelibrary/tests/externallib_test.php
Expand Up @@ -75,7 +75,7 @@ public function test_load_canonical_template() {
$template = external::load_canonical_template('core', 'notification_error');

// Only the base template should contain the docs.
$this->assertContains('@template core/notification_error', $template);
$this->assertStringContainsString('@template core/notification_error', $template);

// Restore the original theme.
$CFG->theme = $originaltheme;
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/uploadcourse/tests/course_test.php
Expand Up @@ -1230,7 +1230,7 @@ public function test_custom_fields_data() {
$data = \core_course\customfield\course_handler::create()->export_instance_data_object($course->id);
$this->assertEquals('Wednesday, 1 April 2020, 4:00 PM', $data->mydatefield, '', 0.0, 10, false, true);
$this->assertEquals($dataupload['customfield_mytextfield'], $data->mytextfield);
$this->assertContains($dataupload['customfield_mytextareafield'], $data->mytextareafield);
$this->assertStringContainsString($dataupload['customfield_mytextareafield'], $data->mytextareafield);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/usertours/tests/privacy_provider_test.php
Expand Up @@ -149,6 +149,6 @@ public function test_export_user_preferences_deleted_tour() {
$this->assertCount(1, (array) $prefs);

// The preference should be related to the first tour.
$this->assertContains($tour1->get_name(), reset($prefs)->description);
$this->assertStringContainsString($tour1->get_name(), reset($prefs)->description);
}
}
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
4 changes: 2 additions & 2 deletions auth/oauth2/tests/auth_test.php
Expand Up @@ -46,8 +46,8 @@ public function test_get_password_change_info() {
['subject', 'message'],
array_keys($info),
'', 0.0, 10, true);
$this->assertContains(
$this->assertStringContainsString(
'your password cannot be reset because you are using your account on another site to log in',
$info['message']);
}
}
}

0 comments on commit 7bc14f8

Please sign in to comment.