Commit 3a5641cb authored by Eloy Lafuente's avatar Eloy Lafuente
Browse files

MDL-67673 phpunit: Remove deprecated assertEquals() params

The optional parameters of assertEquals() and assertNotEquals()
are deprecated in PHPUnit 8 (to be removed in PHPUnit 9):

- delta => use assertEqualsWithDelta()
- canonicalize => use assertEqualsCanonicalizing()
- ignoreCase => use assertEqualsIgnoringCase
- maxDepth => removed without replacement.

More info @ https://github.com/sebastianbergmann/phpunit/issues/3341

Initial search done with:

ag 'assert(Not)?Equals\(.*,.*,' --php

Then, running tests and fixing remaining cases.
parent 40de097e
......@@ -536,7 +536,7 @@ class core_role_privacy_testcase extends provider_testcase {
$user1->id,
$admin->id
];
$this->assertEquals($expected, $userlist2->get_userids(), '', 0.0, 10, true);
$this->assertEqualsCanonicalizing($expected, $userlist2->get_userids());
// The user list for coursecontext1 should user1, user2 and admin (role creator).
$userlist3 = new \core_privacy\local\request\userlist($coursecontext1, $component);
......@@ -547,7 +547,7 @@ class core_role_privacy_testcase extends provider_testcase {
$user2->id,
$admin->id
];
$this->assertEquals($expected, $userlist3->get_userids(), '', 0.0, 10, true);
$this->assertEqualsCanonicalizing($expected, $userlist3->get_userids());
// The user list for coursecatcontext should user2 and admin (role creator).
$userlist4 = new \core_privacy\local\request\userlist($coursecatcontext, $component);
......@@ -557,7 +557,7 @@ class core_role_privacy_testcase extends provider_testcase {
$user2->id,
$admin->id
];
$this->assertEquals($expected, $userlist4->get_userids(), '', 0.0, 10, true);
$this->assertEqualsCanonicalizing($expected, $userlist4->get_userids());
// The user list for systemcontext should user1 and admin (role creator).
$userlist6 = new \core_privacy\local\request\userlist($systemcontext, $component);
......@@ -567,7 +567,7 @@ class core_role_privacy_testcase extends provider_testcase {
$user1->id,
$admin->id
];
$this->assertEquals($expected, $userlist6->get_userids(), '', 0.0, 10, true);
$this->assertEqualsCanonicalizing($expected, $userlist6->get_userids());
// The user list for cmcontext should user1, user2 and admin (role creator).
$userlist7 = new \core_privacy\local\request\userlist($cmcontext, $component);
......@@ -578,7 +578,7 @@ class core_role_privacy_testcase extends provider_testcase {
$user2->id,
$admin->id
];
$this->assertEquals($expected, $userlist7->get_userids(), '', 0.0, 10, true);
$this->assertEqualsCanonicalizing($expected, $userlist7->get_userids());
// The user list for blockcontext should user1 and admin (role creator).
$userlist8 = new \core_privacy\local\request\userlist($blockcontext, $component);
......@@ -588,7 +588,7 @@ class core_role_privacy_testcase extends provider_testcase {
$user1->id,
$admin->id
];
$this->assertEquals($expected, $userlist8->get_userids(), '', 0.0, 10, true);
$this->assertEqualsCanonicalizing($expected, $userlist8->get_userids());
}
/**
......@@ -744,4 +744,4 @@ class core_role_privacy_testcase extends provider_testcase {
}
return $rolesnames;
}
}
\ No newline at end of file
}
......@@ -87,7 +87,7 @@ class tool_cohortroles_privacy_testcase extends \core_privacy\tests\provider_tes
CONTEXT_COURSECAT
];
// Test the User's contexts equal the system and course category context.
$this->assertEquals($expected, $contextlevels, '', 0, 10, true);
$this->assertEqualsCanonicalizing($expected, $contextlevels);
}
/**
......
......@@ -63,7 +63,7 @@ class tool_dataprivacy_manager_observer_testcase extends data_privacy_testcase {
return $message->useridto;
}, $messages);
$this->assertEquals(array_keys($dpos), $messageusers, '', 0.0, 0, true);
$this->assertEqualsCanonicalizing(array_keys($dpos), $messageusers);
}
/**
......
......@@ -274,13 +274,9 @@ class tool_policy_privacy_provider_testcase extends \core_privacy\tests\provider
// Request export for the manager.
$contextlist = provider::get_contexts_for_userid($this->manager->id);
$this->assertCount(3, $contextlist);
$this->assertEquals(
$this->assertEqualsCanonicalizing(
[$managercontext->id, $usercontext->id, $systemcontext->id],
$contextlist->get_contextids(),
'',
0.0,
1,
true
$contextlist->get_contextids()
);
$approvedcontextlist = new approved_contextlist($this->user, 'tool_policy', [$usercontext->id]);
......@@ -332,7 +328,7 @@ class tool_policy_privacy_provider_testcase extends \core_privacy\tests\provider
// Agree to the policies for oneself.
$contextlist = provider::get_contexts_for_userid($this->manager->id);
$this->assertCount(2, $contextlist);
$this->assertEquals([$managercontext->id, $systemcontext->id], $contextlist->get_contextids(), '', 0.0, 1, true);
$this->assertEqualsCanonicalizing([$managercontext->id, $systemcontext->id], $contextlist->get_contextids());
$approvedcontextlist = new approved_contextlist($this->manager, 'tool_policy', $contextlist->get_contextids());
provider::export_user_data($approvedcontextlist);
......
......@@ -1228,7 +1228,7 @@ class tool_uploadcourse_course_testcase extends advanced_testcase {
// Confirm presence of course custom fields.
$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->assertEqualsIgnoringCase('Wednesday, 1 April 2020, 4:00 PM', $data->mydatefield);
$this->assertEquals($dataupload['customfield_mytextfield'], $data->mytextfield);
$this->assertStringContainsString($dataupload['customfield_mytextareafield'], $data->mytextareafield);
}
......
......@@ -42,10 +42,7 @@ class auth_oauth2_auth_testcase extends advanced_testcase {
$auth = get_auth_plugin($user->auth);
$info = $auth->get_password_change_info($user);
$this->assertEquals(
['subject', 'message'],
array_keys($info),
'', 0.0, 10, true);
$this->assertEqualsCanonicalizing(['subject', 'message'], array_keys($info));
$this->assertStringContainsString(
'your password cannot be reset because you are using your account on another site to log in',
$info['message']);
......
......@@ -482,7 +482,7 @@ class core_backup_privacy_provider_testcase extends \core_privacy\tests\provider
$this->assertCount(2, $userlist1);
$expected = [$user1->id, $user2->id];
$actual = $userlist1->get_userids();
$this->assertEquals($expected, $actual, '', 0.0, 10, true);
$this->assertEqualsCanonicalizing($expected, $actual);
// The list of users for coursecontext2 should not return users.
$userlist2 = new \core_privacy\local\request\userlist($coursecontext2, $component);
......
......@@ -209,7 +209,7 @@ class block_comments_privacy_provider_testcase extends \core_privacy\tests\provi
$this->assertCount(2, $contextlist);
$contextids = $contextlist->get_contextids();
$this->assertEquals([$coursecontext1->id, $coursecontext2->id], $contextids, '', 0.0, 10, true);
$this->assertEqualsCanonicalizing([$coursecontext1->id, $coursecontext2->id], $contextids);
}
/**
......
......@@ -690,7 +690,7 @@ class core_blog_privacy_testcase extends provider_testcase {
$commentpath = array_merge($path, [get_string('commentsubcontext', 'core_comment')]);
if ($e->id == $e1->id) {
$tagdata = $writer->get_related_data($path, 'tags');
$this->assertEquals(['Beer', 'Golf'], $tagdata, '', 0, 10, true);
$this->assertEqualsCanonicalizing(['Beer', 'Golf'], $tagdata);
$comments = $writer->get_data($commentpath);
$this->assertCount(2, $comments->comments);
......
......@@ -116,10 +116,10 @@ abstract class cachestore_tests extends advanced_testcase {
// Test find and find with prefix if this class implements the searchable interface.
if ($instance->is_searchable()) {
// Extra settings here ignore the return order of the array.
$this->assertEquals(['test3', 'test1', 'test2', 'other3'], $instance->find_all(), '', 0, 1, true);
$this->assertEqualsCanonicalizing(['test3', 'test1', 'test2', 'other3'], $instance->find_all());
// Extra settings here ignore the return order of the array.
$this->assertEquals(['test2', 'test1', 'test3'], $instance->find_by_prefix('test'), '', 0, 1, true);
$this->assertEqualsCanonicalizing(['test2', 'test1', 'test3'], $instance->find_by_prefix('test'));
$this->assertEquals(['test2'], $instance->find_by_prefix('test2'));
$this->assertEquals(['other3'], $instance->find_by_prefix('other'));
$this->assertEquals([], $instance->find_by_prefix('nothere'));
......
......@@ -827,10 +827,9 @@ class core_calendar_lib_testcase extends advanced_testcase {
$defaultcourses = calendar_get_default_courses(null, '*', false, $users[0]->id);
list($courseids, $groupids, $userid) = calendar_set_filters($defaultcourses);
$this->assertEquals(
$this->assertEqualsCanonicalizing(
[$courses[0]->id, $courses[1]->id, $courses[2]->id, SITEID],
array_values($courseids),
'', 0.0, 10, true);
array_values($courseids));
$this->assertFalse($groupids);
$this->assertFalse($userid);
}
......@@ -853,10 +852,9 @@ class core_calendar_lib_testcase extends advanced_testcase {
$defaultcourses = calendar_get_default_courses(null, '*', false, $users[0]->id);
list($courseids, $groupids, $userid) = calendar_set_filters($defaultcourses, false, $users[0]);
$this->assertEquals(
$this->assertEqualsCanonicalizing(
[$courses[0]->id, $courses[1]->id, $courses[2]->id, SITEID],
array_values($courseids),
'', 0.0, 10, true);
array_values($courseids));
$this->assertEquals(array($coursegroups[$courses[0]->id][0]->id), $groupids);
$this->assertEquals($users[0]->id, $userid);
......@@ -873,8 +871,7 @@ class core_calendar_lib_testcase extends advanced_testcase {
$this->setUser($users[0]);
$defaultcourses = calendar_get_default_courses(null, '*', false, $users[0]->id);
list($courseids, $groupids, $userid) = calendar_set_filters($defaultcourses, false);
$this->assertEquals([$courses[0]->id, $courses[1]->id, $courses[2]->id, SITEID], array_values($courseids), '', 0.0, 10,
true);
$this->assertEqualsCanonicalizing([$courses[0]->id, $courses[1]->id, $courses[2]->id, SITEID], array_values($courseids));
$this->assertEquals(array($coursegroups[$courses[0]->id][0]->id), $groupids);
$this->assertEquals($users[0]->id, $userid);
}
......
......@@ -402,10 +402,9 @@ class core_calendar_raw_event_retrieval_strategy_testcase extends advanced_testc
// Get all events.
$events = $retrievalstrategy->get_raw_events([$user1->id, $user2->id]);
$this->assertCount(2, $events);
$this->assertEquals(
$this->assertEqualsCanonicalizing(
['User1 Event', 'User2 Event'],
array_column($events, 'name'),
'', 0.0, 10, true);
array_column($events, 'name'));
}
public function test_get_raw_events_for_groups_with_no_members() {
......@@ -442,10 +441,9 @@ class core_calendar_raw_event_retrieval_strategy_testcase extends advanced_testc
// Get group eventsl.
$events = $retrievalstrategy->get_raw_events(null, [$group1->id, $group2->id]);
$this->assertCount(2, $events);
$this->assertEquals(
$this->assertEqualsCanonicalizing(
['Group 1 Event', 'Group 2 Event'],
array_column($events, 'name'),
'', 0.0, 10, true);
array_column($events, 'name'));
}
/**
......
......@@ -240,7 +240,7 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
$returnedids[] = $category['id'];
}
// Sort the arrays upon comparision.
$this->assertEquals(array_keys($generatedcats), $returnedids, '', 0.0, 10, true);
$this->assertEqualsCanonicalizing(array_keys($generatedcats), $returnedids);
// Check different params.
$categories = core_course_external::get_categories(array(
......
......@@ -116,9 +116,9 @@ class core_customfield_privacy_testcase extends provider_testcase {
list($sql, $params) = $DB->get_in_or_equal([$courses[1]->id, $courses[2]->id], SQL_PARAMS_NAMED);
$r = provider::get_customfields_data_contexts('core_course', 'course', '=0',
$sql, $params);
$this->assertEquals([context_course::instance($courses[1]->id)->id,
$this->assertEqualsCanonicalizing([context_course::instance($courses[1]->id)->id,
context_course::instance($courses[2]->id)->id],
$r->get_contextids(), '', 0, 10, true);
$r->get_contextids());
}
/**
......
......@@ -218,11 +218,9 @@ class enrol_flatfile_privacy_testcase extends provider_testcase {
// We expect to see 3 entries for course1, and that's user1, user3 and user4.
$userlist = new \core_privacy\local\request\userlist($this->coursecontext1, 'enrol_flatfile');
provider::get_users_in_context($userlist);
$this->assertEquals(
$this->assertEqualsCanonicalizing(
[$this->user1->id, $this->user3->id, $this->user4->id],
$userlist->get_userids(),
'', 0.0, 10, true
);
$userlist->get_userids());
// And 1 for course2 which is for user2.
$userlist = new \core_privacy\local\request\userlist($this->coursecontext2, 'enrol_flatfile');
......@@ -247,11 +245,9 @@ class enrol_flatfile_privacy_testcase extends provider_testcase {
// Verify we have 3 future enrolment for user 1, user 3 and user 4.
$userlist = new \core_privacy\local\request\userlist($this->coursecontext1, 'enrol_flatfile');
provider::get_users_in_context($userlist);
$this->assertEquals(
$this->assertEqualsCanonicalizing(
[$this->user1->id, $this->user3->id, $this->user4->id],
$userlist->get_userids(),
'', 0.0, 10, true
);
$userlist->get_userids());
$approveduserlist = new \core_privacy\local\request\approved_userlist($this->coursecontext1, 'enrol_flatfile',
[$this->user1->id, $this->user3->id]);
......
......@@ -92,7 +92,7 @@ class enrol_lti_privacy_provider_testcase extends \core_privacy\tests\provider_t
$expectedids = [$coursectx->id, $activityctx->id];
$actualids = $contextlist->get_contextids();
$this->assertEquals($expectedids, $actualids, '', 0.0, 10, true);
$this->assertEqualsCanonicalizing($expectedids, $actualids);
}
/**
......@@ -211,10 +211,9 @@ class enrol_lti_privacy_provider_testcase extends \core_privacy\tests\provider_t
$userlist = new \core_privacy\local\request\userlist($coursecontext, 'enrol_paypal');
provider::get_users_in_context($userlist);
$this->assertEquals(
$this->assertEqualsCanonicalizing(
[$this->user->id, $this->anotheruser->id],
$userlist->get_userids(),
'', 0.0, 10, true);
$userlist->get_userids());
}
/**
......
......@@ -294,9 +294,8 @@ class enrol_meta_privacy_testcase extends \core_privacy\tests\provider_testcase
$userlist = new \core_privacy\local\request\userlist($context, 'enrol_meta');
\enrol_meta\privacy\provider::get_users_in_context($userlist);
$this->assertEquals(
$this->assertEqualsCanonicalizing(
[$user1->id, $user2->id],
$userlist->get_userids(),
'', 0.0, 10, true);
$userlist->get_userids());
}
}
......@@ -302,7 +302,7 @@ class enrol_paypal_privacy_provider_testcase extends \core_privacy\tests\provide
$this->assertCount(2, $contextlist);
$contextids = $contextlist->get_contextids();
$this->assertEquals([$coursecontext1->id, $coursecontext2->id], $contextids, '', 0.0, 1, true);
$this->assertEqualsCanonicalizing([$coursecontext1->id, $coursecontext2->id], $contextids);
// Business User 3 is the Receiver of course 3 only.
$contextlist = provider::get_contexts_for_userid($this->businessuser3->id);
......@@ -368,11 +368,9 @@ class enrol_paypal_privacy_provider_testcase extends \core_privacy\tests\provide
$data = $writer->get_data([get_string('transactions', 'enrol_paypal')]);
$this->assertCount(2, $data->transactions);
$this->assertEquals(
$this->assertEqualsCanonicalizing(
['STUDENT2-IN-COURSE2-00', 'STUDENT2-IN-COURSE2-01'],
array_column($data->transactions, 'txn_id'),
'', 0.0, 10, true
);
array_column($data->transactions, 'txn_id'));
}
/**
......@@ -674,7 +672,7 @@ class enrol_paypal_privacy_provider_testcase extends \core_privacy\tests\provide
$userlist1 = new \core_privacy\local\request\userlist($coursecontext1, 'enrol_paypal');
provider::get_users_in_context($userlist1);
$this->assertEquals(
$this->assertEqualsCanonicalizing(
[
$this->businessuser1->id,
$this->businessuser2->id,
......@@ -682,13 +680,12 @@ class enrol_paypal_privacy_provider_testcase extends \core_privacy\tests\provide
$this->student1->id,
$this->student12->id
],
$userlist1->get_userids(),
'', 0.0, 10, true
$userlist1->get_userids()
);
$userlist2 = new \core_privacy\local\request\userlist($coursecontext2, 'enrol_paypal');
provider::get_users_in_context($userlist2);
$this->assertEquals(
$this->assertEqualsCanonicalizing(
[
$this->businessuser1->id,
$this->businessuser2->id,
......@@ -696,20 +693,18 @@ class enrol_paypal_privacy_provider_testcase extends \core_privacy\tests\provide
$this->student2->id,
$this->student12->id
],
$userlist2->get_userids(),
'', 0.0, 10, true
$userlist2->get_userids()
);
$userlist3 = new \core_privacy\local\request\userlist($coursecontext3, 'enrol_paypal');
provider::get_users_in_context($userlist3);
$this->assertEquals(
$this->assertEqualsCanonicalizing(
[
$this->businessuser3->id,
$this->receiveruser3->id,
$this->student3->id
],
$userlist3->get_userids(),
'', 0.0, 10, true
$userlist3->get_userids()
);
}
......@@ -729,16 +724,14 @@ class enrol_paypal_privacy_provider_testcase extends \core_privacy\tests\provide
2,
$DB->count_records('enrol_paypal', ['courseid' => $this->course1->id])
);
$this->assertEquals(
$this->assertEqualsCanonicalizing(
[$this->course1->id, $this->course2->id],
$DB->get_fieldset_select('enrol_paypal', 'courseid', 'userid = ?', [$this->student12->id]),
'', 0.0, 10, true
$DB->get_fieldset_select('enrol_paypal', 'courseid', 'userid = ?', [$this->student12->id])
);
$this->assertEquals(
$this->assertEqualsCanonicalizing(
[$this->course1->id, $this->course2->id, $this->course2->id],
$DB->get_fieldset_select('enrol_paypal', 'courseid', 'business = ?',
[\core_text::strtolower($this->businessuser1->email)]),
'', 0.0, 10, true
[\core_text::strtolower($this->businessuser1->email)])
);
$this->assertEquals(
3,
......@@ -760,16 +753,14 @@ class enrol_paypal_privacy_provider_testcase extends \core_privacy\tests\provide
1,
$DB->count_records('enrol_paypal', ['courseid' => $this->course1->id])
);
$this->assertEquals(
$this->assertEqualsCanonicalizing(
[$this->course2->id],
$DB->get_fieldset_select('enrol_paypal', 'courseid', 'userid = ?', [$this->student12->id]),
'', 0.0, 10, true
$DB->get_fieldset_select('enrol_paypal', 'courseid', 'userid = ?', [$this->student12->id])
);
$this->assertEquals(
$this->assertEqualsCanonicalizing(
[$this->course2->id, $this->course2->id],
$DB->get_fieldset_select('enrol_paypal', 'courseid', 'business = ?',
[\core_text::strtolower($this->businessuser1->email)]),
'', 0.0, 10, true
[\core_text::strtolower($this->businessuser1->email)])
);
$this->assertEquals(
3,
......
......@@ -159,7 +159,7 @@ class core_enrollib_testcase extends advanced_testcase {
$course = reset($courses);
context_helper::preload_from_record($course);
$course = (array)$course;
$this->assertEquals($basefields, array_keys($course), '', 0, 10, true);
$this->assertEqualsCanonicalizing($basefields, array_keys($course));
$courses = enrol_get_all_users_courses($user2->id, false, 'timecreated');
$course = reset($courses);
......
......@@ -351,7 +351,7 @@ class core_enrol_externallib_testcase extends externallib_advanced_testcase {
$viewed[] = $createdusers[$enrolleduser['id']];
}
// Verify viewed matches canview expectation (using canonicalize to ignore ordering).
$this->assertEquals($canview, $viewed, "Problem checking visible users for '{$createdusers[$USER->id]}'", 0, 1, true);
$this->assertEqualsCanonicalizing($canview, $viewed, "Problem checking visible users for '{$createdusers[$USER->id]}'");
}
}
......@@ -1150,10 +1150,9 @@ class core_enrol_externallib_testcase extends externallib_advanced_testcase {
core_enrol_external::submit_user_enrolment_form($querystring)
);
$this->assertEquals(
$this->assertEqualsCanonicalizing(
['result' => $expectedresult, 'validationerror' => $validationerror],
$result,
'', 0.0, 10, true);
$result);
if ($result['result']) {
$ue = $DB->get_record('user_enrolments', ['id' => $ueid], '*', MUST_EXIST);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment