Skip to content

Commit

Permalink
MDL-71036 phpunit: Renamed various regexp-related assertions
Browse files Browse the repository at this point in the history
In PHPUnit 9.1, the following regexp-related assertions
have been deprecated and there are new alternatives for
all them:
    - assertRegExp()     -> assertMatchesRegularExpression()
    - assertNotRegExp()  -> assertDoesNotMatchRegularExpression()

This is about to, simply, move all cases to the new alternatives.

Source: https://github.com/sebastianbergmann/phpunit/blob/9.1.0/ChangeLog-9.1.md

Regexp to find all them:

    ag 'assertRegExp|assertNotRegExp' -li
  • Loading branch information
stronk7 committed Mar 11, 2021
1 parent 309a65a commit ba5b608
Show file tree
Hide file tree
Showing 81 changed files with 620 additions and 620 deletions.
2 changes: 1 addition & 1 deletion admin/tool/dataprivacy/tests/api_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function test_update_request_status() {
$result = api::update_request_status($requestid, api::DATAREQUEST_STATUS_AWAITING_APPROVAL, 0, $secondcomment);
$this->assertTrue($result);
$datarequest = new data_request($requestid);
$this->assertRegExp("/.*{$comment}.*{$secondcomment}/s", $datarequest->get('dpocomment'));
$this->assertMatchesRegularExpression("/.*{$comment}.*{$secondcomment}/s", $datarequest->get('dpocomment'));

// Update with a valid status.
$result = api::update_request_status($requestid, api::DATAREQUEST_STATUS_DOWNLOAD_READY);
Expand Down
6 changes: 3 additions & 3 deletions admin/tool/health/tests/healthlib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ public function test_tool_health_category_list_missing_parents() {
$missingparent = array((object) array('id' => 2, 'parent' => 3, 'name' => 'test'),
(object) array('id' => 4, 'parent' => 5, 'name' => 'test2'));
$result = tool_health_category_list_missing_parents($missingparent);
$this->assertRegExp('/Category 2: test/', $result);
$this->assertRegExp('/Category 4: test2/', $result);
$this->assertMatchesRegularExpression('/Category 2: test/', $result);
$this->assertMatchesRegularExpression('/Category 4: test2/', $result);
}

/**
Expand All @@ -213,6 +213,6 @@ public function test_tool_health_category_list_missing_parents() {
public function test_tool_health_category_list_loops() {
$loops = array((object) array('id' => 2, 'parent' => 3, 'name' => 'test'));
$result = tool_health_category_list_loops($loops);
$this->assertRegExp('/Category 2: test/', $result);
$this->assertMatchesRegularExpression('/Category 2: test/', $result);
}
}
8 changes: 4 additions & 4 deletions admin/tool/lpmigrate/tests/processor_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,13 @@ public function test_destination_competency_exists() {
$this->assertEquals($this->c1->id, $warning['courseid']);
$this->assertEquals($this->f1comps['A1']->get('id'), $warning['competencyid']);
$this->assertEquals(null, $warning['cmid']);
$this->assertRegexp('/competency already exists/', $warning['message']);
$this->assertMatchesRegularExpression('/competency already exists/', $warning['message']);

$warning = array_shift($warnings);
$this->assertEquals($this->c2->id, $warning['courseid']);
$this->assertEquals($this->f1comps['A2']->get('id'), $warning['competencyid']);
$this->assertEquals($this->cms[$this->c2->id]['F1']->cmid, $warning['cmid']);
$this->assertRegexp('/competency already exists/', $warning['message']);
$this->assertMatchesRegularExpression('/competency already exists/', $warning['message']);

$this->assertCourseCompetencyExists($this->c1, $this->f1comps['A1']);
$this->assertModuleCompetencyExists($this->cms[$this->c2->id]['F1'], $this->f1comps['A2']);
Expand Down Expand Up @@ -436,7 +436,7 @@ public function test_permission_exception() {
$this->assertEquals($this->c1->id, $errors[0]['courseid']);
$this->assertEquals($this->f1comps['A1']->get('id'), $errors[0]['competencyid']);
$this->assertEquals(null, $errors[0]['cmid']);
$this->assertRegexp('/Sorry, but you do not currently have permissions to do that/', $errors[0]['message']);
$this->assertMatchesRegularExpression('/Sorry, but you do not currently have permissions to do that/', $errors[0]['message']);
$this->assertEquals($this->f1comps['A3']->get('id'), $errors[1]['competencyid']);

$this->assertCourseCompetencyNotMigrated($this->c1, $this->f1comps['A1'], $this->f2comps['A1']);
Expand Down Expand Up @@ -465,7 +465,7 @@ public function test_permission_exception() {
$this->assertEquals($this->c2->id, $errors[0]['courseid']);
$this->assertEquals($this->f1comps['A2']->get('id'), $errors[0]['competencyid']);
$this->assertEquals($this->cms[$this->c2->id]['F1']->cmid, $errors[0]['cmid']);
$this->assertRegexp('/Sorry, but you do not currently have permissions to do that/', $errors[0]['message']);
$this->assertMatchesRegularExpression('/Sorry, but you do not currently have permissions to do that/', $errors[0]['message']);
$this->assertEquals($this->f1comps['A3']->get('id'), $errors[1]['competencyid']);

// The new competencies were added to the course, but the old ones were not removed because they are still in modules.
Expand Down
4 changes: 2 additions & 2 deletions admin/tool/monitor/tests/eventobservers_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,8 @@ public function test_replace_placeholders() {

$modurl = new moodle_url('/mod/book/view.php', array('id' => $book->cmid));

$this->assertRegExp('~<h2>.*' . preg_quote($event->get_url()->out(), '~') . '.*</h2>~', $msg->fullmessagehtml);
$this->assertRegExp('~<li>.*' . preg_quote($modurl->out(), '~') . '.*</li>~', $msg->fullmessagehtml);
$this->assertMatchesRegularExpression('~<h2>.*' . preg_quote($event->get_url()->out(), '~') . '.*</h2>~', $msg->fullmessagehtml);
$this->assertMatchesRegularExpression('~<li>.*' . preg_quote($modurl->out(), '~') . '.*</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);
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/usertours/tests/tour_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ public function test_get_tour_key($id, $getconfig, $setconfig, $willpersist, $us
set_user_preference(\tool_usertours\tour::TOUR_REQUESTED_BY_USER . $id, $userpref);
}

$this->assertRegExp(
$this->assertMatchesRegularExpression(
'/' . $expectation . '/',
$tour->get_tour_key()
);
Expand Down
26 changes: 13 additions & 13 deletions availability/condition/completion/tests/condition_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public function test_usage() {
$this->assertFalse($cond->is_available(false, $info, true, $user->id));
$information = $cond->get_description(false, false, $info);
$information = \core_availability\info::format_info($information, $course);
$this->assertRegExp('~Page!.*is marked complete~', $information);
$this->assertMatchesRegularExpression('~Page!.*is marked complete~', $information);
$this->assertTrue($cond->is_available(true, $info, true, $user->id));

// INCOMPLETE state (true).
Expand All @@ -236,7 +236,7 @@ public function test_usage() {
$this->assertFalse($cond->is_available(true, $info, true, $user->id));
$information = $cond->get_description(false, true, $info);
$information = \core_availability\info::format_info($information, $course);
$this->assertRegExp('~Page!.*is marked complete~', $information);
$this->assertMatchesRegularExpression('~Page!.*is marked complete~', $information);

// Mark page complete.
$completion = new completion_info($course);
Expand All @@ -250,7 +250,7 @@ public function test_usage() {
$this->assertFalse($cond->is_available(true, $info, true, $user->id));
$information = $cond->get_description(false, true, $info);
$information = \core_availability\info::format_info($information, $course);
$this->assertRegExp('~Page!.*is incomplete~', $information);
$this->assertMatchesRegularExpression('~Page!.*is incomplete~', $information);

// INCOMPLETE state (false).
$cond = new condition((object)[
Expand All @@ -259,7 +259,7 @@ public function test_usage() {
$this->assertFalse($cond->is_available(false, $info, true, $user->id));
$information = $cond->get_description(false, false, $info);
$information = \core_availability\info::format_info($information, $course);
$this->assertRegExp('~Page!.*is incomplete~', $information);
$this->assertMatchesRegularExpression('~Page!.*is incomplete~', $information);
$this->assertTrue($cond->is_available(true, $info,
true, $user->id));

Expand Down Expand Up @@ -289,7 +289,7 @@ public function test_usage() {
$this->assertFalse($cond->is_available(false, $info, true, $user->id));
$information = $cond->get_description(false, false, $info);
$information = \core_availability\info::format_info($information, $course);
$this->assertRegExp('~Assign!.*is complete and passed~', $information);
$this->assertMatchesRegularExpression('~Assign!.*is complete and passed~', $information);
$this->assertTrue($cond->is_available(true, $info, true, $user->id));

$cond = new condition((object)[
Expand All @@ -298,7 +298,7 @@ public function test_usage() {
$this->assertFalse($cond->is_available(false, $info, true, $user->id));
$information = $cond->get_description(false, false, $info);
$information = \core_availability\info::format_info($information, $course);
$this->assertRegExp('~Assign!.*is complete and failed~', $information);
$this->assertMatchesRegularExpression('~Assign!.*is complete and failed~', $information);
$this->assertTrue($cond->is_available(true, $info, true, $user->id));

// Change the grade to be complete and failed.
Expand All @@ -322,7 +322,7 @@ public function test_usage() {
$this->assertFalse($cond->is_available(false, $info, true, $user->id));
$information = $cond->get_description(false, false, $info);
$information = \core_availability\info::format_info($information, $course);
$this->assertRegExp('~Assign!.*is complete and passed~', $information);
$this->assertMatchesRegularExpression('~Assign!.*is complete and passed~', $information);
$this->assertTrue($cond->is_available(true, $info, true, $user->id));

$cond = new condition((object)[
Expand All @@ -332,7 +332,7 @@ public function test_usage() {
$this->assertFalse($cond->is_available(true, $info, true, $user->id));
$information = $cond->get_description(false, true, $info);
$information = \core_availability\info::format_info($information, $course);
$this->assertRegExp('~Assign!.*is not complete and failed~', $information);
$this->assertMatchesRegularExpression('~Assign!.*is not complete and failed~', $information);

// Now change it to pass.
self::set_grade($assignrow, $user->id, 60);
Expand All @@ -356,15 +356,15 @@ public function test_usage() {
$this->assertFalse($cond->is_available(true, $info, true, $user->id));
$information = $cond->get_description(false, true, $info);
$information = \core_availability\info::format_info($information, $course);
$this->assertRegExp('~Assign!.*is not complete and passed~', $information);
$this->assertMatchesRegularExpression('~Assign!.*is not complete and passed~', $information);

$cond = new condition((object)[
'cm' => (int)$assigncm->id, 'e' => COMPLETION_COMPLETE_FAIL
]);
$this->assertFalse($cond->is_available(false, $info, true, $user->id));
$information = $cond->get_description(false, false, $info);
$information = \core_availability\info::format_info($information, $course);
$this->assertRegExp('~Assign!.*is complete and failed~', $information);
$this->assertMatchesRegularExpression('~Assign!.*is complete and failed~', $information);
$this->assertTrue($cond->is_available(true, $info, true, $user->id));

// Simulate deletion of an activity by using an invalid cmid. These
Expand All @@ -375,7 +375,7 @@ public function test_usage() {
$this->assertFalse($cond->is_available(false, $info, true, $user->id));
$information = $cond->get_description(false, false, $info);
$information = \core_availability\info::format_info($information, $course);
$this->assertRegExp('~(Missing activity).*is marked complete~', $information);
$this->assertMatchesRegularExpression('~(Missing activity).*is marked complete~', $information);
$this->assertFalse($cond->is_available(true, $info, true, $user->id));
$cond = new condition((object)[
'cm' => ($assigncm->id + 100), 'e' => COMPLETION_INCOMPLETE
Expand Down Expand Up @@ -472,7 +472,7 @@ public function test_previous_activity(int $grade, int $condition, string $mark,
$this->assertEquals($resultnot, $cond->is_available(true, $info, true, $user->id));
$information = $cond->get_description(false, false, $info);
$information = \core_availability\info::format_info($information, $course);
$this->assertRegExp($description, $information);
$this->assertMatchesRegularExpression($description, $information);
}

public function test_previous_activity_data(): array {
Expand Down Expand Up @@ -636,7 +636,7 @@ public function test_section_previous_activity(int $condition, bool $mark, strin
$this->assertEquals($resultnot, $cond->is_available(true, $info, true, $user->id));
$information = $cond->get_description(false, false, $info);
$information = \core_availability\info::format_info($information, $course);
$this->assertRegExp($description, $information);
$this->assertMatchesRegularExpression($description, $information);

}

Expand Down
34 changes: 17 additions & 17 deletions availability/condition/date/tests/condition_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function test_in_tree() {

// Note: PM is normally upper-case, but an issue with PHP on Mac means
// that on that platform, it is reported lower-case.
$this->assertRegExp('~from.*18 February 2014, 7:20 (PM|pm)~', $information);
$this->assertMatchesRegularExpression('~from.*18 February 2014, 7:20 (PM|pm)~', $information);

// Check if available (when available).
condition::set_current_time_for_test($time);
Expand Down Expand Up @@ -192,50 +192,50 @@ public function test_get_description() {
// Test with >=.
$date = new condition((object)array('d' => '>=', 't' => $time));
$information = $date->get_description(true, false, $info);
$this->assertRegExp('~after.*18 February 2014, 2:55 (PM|pm)~', $information);
$this->assertMatchesRegularExpression('~after.*18 February 2014, 2:55 (PM|pm)~', $information);
$information = $date->get_description(true, true, $info);
$this->assertRegExp('~before.*18 February 2014, 2:55 (PM|pm)~', $information);
$this->assertMatchesRegularExpression('~before.*18 February 2014, 2:55 (PM|pm)~', $information);
$information = $date->get_standalone_description(true, false, $info);
$this->assertRegExp('~from.*18 February 2014, 2:55 (PM|pm)~', $information);
$this->assertMatchesRegularExpression('~from.*18 February 2014, 2:55 (PM|pm)~', $information);
$information = $date->get_standalone_description(true, true, $info);
$this->assertRegExp('~until.*18 February 2014, 2:55 (PM|pm)~', $information);
$this->assertMatchesRegularExpression('~until.*18 February 2014, 2:55 (PM|pm)~', $information);

// Test with <.
$date = new condition((object)array('d' => '<', 't' => $time));
$information = $date->get_description(true, false, $info);
$this->assertRegExp('~before.*18 February 2014, 2:55 (PM|pm)~', $information);
$this->assertMatchesRegularExpression('~before.*18 February 2014, 2:55 (PM|pm)~', $information);
$information = $date->get_description(true, true, $info);
$this->assertRegExp('~after.*18 February 2014, 2:55 (PM|pm)~', $information);
$this->assertMatchesRegularExpression('~after.*18 February 2014, 2:55 (PM|pm)~', $information);
$information = $date->get_standalone_description(true, false, $info);
$this->assertRegExp('~until.*18 February 2014, 2:55 (PM|pm)~', $information);
$this->assertMatchesRegularExpression('~until.*18 February 2014, 2:55 (PM|pm)~', $information);
$information = $date->get_standalone_description(true, true, $info);
$this->assertRegExp('~from.*18 February 2014, 2:55 (PM|pm)~', $information);
$this->assertMatchesRegularExpression('~from.*18 February 2014, 2:55 (PM|pm)~', $information);

// Test special case for dates that are midnight.
$date = new condition((object)array('d' => '>=',
't' => strtotime('2014-03-05 00:00 GMT')));
$information = $date->get_description(true, false, $info);
$this->assertRegExp('~on or after.*5 March 2014([^0-9]*)$~', $information);
$this->assertMatchesRegularExpression('~on or after.*5 March 2014([^0-9]*)$~', $information);
$information = $date->get_description(true, true, $info);
$this->assertRegExp('~before.*end of.*4 March 2014([^0-9]*)$~', $information);
$this->assertMatchesRegularExpression('~before.*end of.*4 March 2014([^0-9]*)$~', $information);
$information = $date->get_standalone_description(true, false, $info);
$this->assertRegExp('~from.*5 March 2014([^0-9]*)$~', $information);
$this->assertMatchesRegularExpression('~from.*5 March 2014([^0-9]*)$~', $information);
$information = $date->get_standalone_description(true, true, $info);
$this->assertRegExp('~until end of.*4 March 2014([^0-9]*)$~', $information);
$this->assertMatchesRegularExpression('~until end of.*4 March 2014([^0-9]*)$~', $information);

// In the 'until' case for midnight, it shows the previous day. (I.e.
// if the date is 5 March 00:00, then we show it as available until 4
// March, implying 'the end of'.)
$date = new condition((object)array('d' => '<',
't' => strtotime('2014-03-05 00:00 GMT')));
$information = $date->get_description(true, false, $info);
$this->assertRegExp('~before end of.*4 March 2014([^0-9]*)$~', $information);
$this->assertMatchesRegularExpression('~before end of.*4 March 2014([^0-9]*)$~', $information);
$information = $date->get_description(true, true, $info);
$this->assertRegExp('~on or after.*5 March 2014([^0-9]*)$~', $information);
$this->assertMatchesRegularExpression('~on or after.*5 March 2014([^0-9]*)$~', $information);
$information = $date->get_standalone_description(true, false, $info);
$this->assertRegExp('~until end of.*4 March 2014([^0-9]*)$~', $information);
$this->assertMatchesRegularExpression('~until end of.*4 March 2014([^0-9]*)$~', $information);
$information = $date->get_standalone_description(true, true, $info);
$this->assertRegExp('~from.*5 March 2014([^0-9]*)$~', $information);
$this->assertMatchesRegularExpression('~from.*5 March 2014([^0-9]*)$~', $information);
}

/**
Expand Down
Loading

0 comments on commit ba5b608

Please sign in to comment.