Commit 713722c3 authored by Eloy Lafuente's avatar Eloy Lafuente
Browse files

MDL-71036 phpunit: Coding style changes, 99% whitespace only

I've gone over a few of the mofified files (those
which were showing warnings and errors to CiBoT. Some of them
have been fixed completely, while others only have fixed
for the lines belonging to this issue (lib/tests/moodlelib_test.php)
for example.
parent 49975d58
......@@ -436,7 +436,8 @@ class tool_lpmigrate_framework_processor_testcase extends advanced_testcase {
$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->assertMatchesRegularExpression('/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']);
......@@ -465,7 +466,8 @@ class tool_lpmigrate_framework_processor_testcase extends advanced_testcase {
$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->assertMatchesRegularExpression('/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.
......@@ -616,5 +618,4 @@ class tool_lpmigrate_framework_processor_testcase extends advanced_testcase {
$this->assertEquals($before->get('sortorder'), $after->get('sortorder'));
$this->assertEquals($before->get('ruleoutcome'), $after->get('ruleoutcome'));
}
}
......@@ -498,7 +498,8 @@ class tool_monitor_eventobservers_testcase extends advanced_testcase {
$modurl = new moodle_url('/mod/book/view.php', array('id' => $book->cmid));
$this->assertMatchesRegularExpression('~<h2>.*' . preg_quote($event->get_url()->out(), '~') . '.*</h2>~', $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);
......
......@@ -2525,7 +2525,8 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
(new DateTime('1997-11-06 09:00:00 EST'))->getTimestamp()
];
foreach ($records as $record) {
$this->assertContainsEquals($record->timestart, $expecteddates, date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
$this->assertContainsEquals($record->timestart, $expecteddates,
date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
}
}
......@@ -2603,7 +2604,8 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
(new DateTime('1997-09-02 15:00:00 EDT'))->getTimestamp(),
];
foreach ($records as $record) {
$this->assertContainsEquals($record->timestart, $expecteddates, date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
$this->assertContainsEquals($record->timestart, $expecteddates,
date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
}
}
......@@ -2634,7 +2636,8 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
(new DateTime('1997-09-02 10:15:00 EDT'))->getTimestamp(),
];
foreach ($records as $record) {
$this->assertContainsEquals($record->timestart, $expecteddates, date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
$this->assertContainsEquals($record->timestart, $expecteddates,
date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
}
}
......@@ -2663,7 +2666,8 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
(new DateTime('1997-09-02 13:30:00 EDT'))->getTimestamp(),
];
foreach ($records as $record) {
$this->assertContainsEquals($record->timestart, $expecteddates, date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
$this->assertContainsEquals($record->timestart, $expecteddates,
date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
}
}
......@@ -2707,7 +2711,8 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
$this->assertCount($count, $records);
foreach ($records as $record) {
$this->assertContainsEquals($record->timestart, $expecteddates, date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
$this->assertContainsEquals($record->timestart, $expecteddates,
date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
}
}
......@@ -2751,7 +2756,8 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
$this->assertCount($count, $records);
foreach ($records as $record) {
$this->assertContainsEquals($record->timestart, $expecteddates, date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
$this->assertContainsEquals($record->timestart, $expecteddates,
date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
}
}
......@@ -2782,7 +2788,8 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
(new DateTime('1997-08-24 09:00:00 EDT'))->getTimestamp(),
];
foreach ($records as $record) {
$this->assertContainsEquals($record->timestart, $expecteddates, date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
$this->assertContainsEquals($record->timestart, $expecteddates,
date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
}
}
......@@ -2815,7 +2822,8 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
];
foreach ($records as $record) {
$this->assertContainsEquals($record->timestart, $expecteddates, date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
$this->assertContainsEquals($record->timestart, $expecteddates,
date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
}
}
......
......@@ -455,7 +455,8 @@ class core_competency_api_testcase extends advanced_testcase {
$plan = api::update_plan($record);
$this->fail('Updating the status is not allowed.');
} catch (coding_exception $e) {
$this->assertMatchesRegularExpression('/To change the status of a plan use the appropriate methods./', $e->getMessage());
$this->assertMatchesRegularExpression('/To change the status of a plan use the appropriate methods./',
$e->getMessage());
}
// Test when user with manage own plan capability try to edit other user plan.
......@@ -2101,8 +2102,8 @@ class core_competency_api_testcase extends advanced_testcase {
$c3 = $lpg->create_competency(array('competencyframeworkid' => $f1->get('id')));
// Creating an evidence with minimal information.
$evidence = api::add_evidence($u1->id, $c1->get('id'), $u1ctx->id, \core_competency\evidence::ACTION_COMPLETE, 'invaliddata',
'error');
$evidence = api::add_evidence($u1->id, $c1->get('id'), $u1ctx->id, \core_competency\evidence::ACTION_COMPLETE,
'invaliddata', 'error');
$evidence->read();
$uc = \core_competency\user_competency::get_record(array('userid' => $u1->id, 'competencyid' => $c1->get('id')));
$this->assertEquals(\core_competency\user_competency::STATUS_IDLE, $uc->get('status'));
......@@ -2119,8 +2120,8 @@ class core_competency_api_testcase extends advanced_testcase {
$this->assertSame(null, $evidence->get('actionuserid'));
// Creating an evidence complete on competency with custom scale.
$evidence = api::add_evidence($u1->id, $c2->get('id'), $u1ctx->id, \core_competency\evidence::ACTION_COMPLETE, 'invaliddata',
'error');
$evidence = api::add_evidence($u1->id, $c2->get('id'), $u1ctx->id, \core_competency\evidence::ACTION_COMPLETE,
'invaliddata', 'error');
$evidence->read();
$uc = \core_competency\user_competency::get_record(array('userid' => $u1->id, 'competencyid' => $c2->get('id')));
$this->assertEquals(\core_competency\user_competency::STATUS_IDLE, $uc->get('status'));
......@@ -2141,8 +2142,8 @@ class core_competency_api_testcase extends advanced_testcase {
'proficiency' => 0));
$this->assertEquals(1, $uc->get('grade'));
$this->assertEquals(0, $uc->get('proficiency'));
$evidence = api::add_evidence($u1->id, $c3->get('id'), $u1ctx->id, \core_competency\evidence::ACTION_COMPLETE, 'invaliddata',
'error');
$evidence = api::add_evidence($u1->id, $c3->get('id'), $u1ctx->id, \core_competency\evidence::ACTION_COMPLETE,
'invaliddata', 'error');
$evidence->read();
$uc->read();
$this->assertEquals(\core_competency\user_competency::STATUS_IDLE, $uc->get('status'));
......@@ -2159,8 +2160,8 @@ class core_competency_api_testcase extends advanced_testcase {
$this->assertSame(null, $evidence->get('actionuserid'));
// Creating a standard evidence and send for review.
$evidence = api::add_evidence($u1->id, $c2->get('id'), $u1ctx->id, \core_competency\evidence::ACTION_COMPLETE, 'invaliddata',
'error', null, true);
$evidence = api::add_evidence($u1->id, $c2->get('id'), $u1ctx->id, \core_competency\evidence::ACTION_COMPLETE,
'invaliddata', 'error', null, true);
$evidence->read();
$uc = \core_competency\user_competency::get_record(array('userid' => $u1->id, 'competencyid' => $c2->get('id')));
$this->assertEquals(\core_competency\user_competency::STATUS_WAITING_FOR_REVIEW, $uc->get('status'));
......@@ -2185,8 +2186,8 @@ class core_competency_api_testcase extends advanced_testcase {
$c1 = $lpg->create_competency(array('competencyframeworkid' => $f1->get('id')));
// Creating an evidence with minimal information.
$evidence = api::add_evidence($u1->id, $c1->get('id'), $u1ctx->id, \core_competency\evidence::ACTION_OVERRIDE, 'invaliddata',
'error');
$evidence = api::add_evidence($u1->id, $c1->get('id'), $u1ctx->id, \core_competency\evidence::ACTION_OVERRIDE,
'invaliddata', 'error');
$evidence->read();
$uc = \core_competency\user_competency::get_record(array('userid' => $u1->id, 'competencyid' => $c1->get('id')));
$this->assertEquals(\core_competency\user_competency::STATUS_IDLE, $uc->get('status'));
......@@ -2203,8 +2204,8 @@ class core_competency_api_testcase extends advanced_testcase {
$this->assertSame(null, $evidence->get('actionuserid'));
// Creating an evidence with a grade information.
$evidence = api::add_evidence($u1->id, $c1->get('id'), $u1ctx->id, \core_competency\evidence::ACTION_OVERRIDE, 'invaliddata',
'error', null, false, null, 3);
$evidence = api::add_evidence($u1->id, $c1->get('id'), $u1ctx->id, \core_competency\evidence::ACTION_OVERRIDE,
'invaliddata', 'error', null, false, null, 3);
$evidence->read();
$uc = \core_competency\user_competency::get_record(array('userid' => $u1->id, 'competencyid' => $c1->get('id')));
$this->assertEquals(\core_competency\user_competency::STATUS_IDLE, $uc->get('status'));
......@@ -2221,8 +2222,8 @@ class core_competency_api_testcase extends advanced_testcase {
$this->assertSame(null, $evidence->get('actionuserid'));
// Creating an evidence with another grade information.
$evidence = api::add_evidence($u1->id, $c1->get('id'), $u1ctx->id, \core_competency\evidence::ACTION_OVERRIDE, 'invaliddata',
'error', null, false, null, 1);
$evidence = api::add_evidence($u1->id, $c1->get('id'), $u1ctx->id, \core_competency\evidence::ACTION_OVERRIDE,
'invaliddata', 'error', null, false, null, 1);
$evidence->read();
$uc = \core_competency\user_competency::get_record(array('userid' => $u1->id, 'competencyid' => $c1->get('id')));
$this->assertEquals(\core_competency\user_competency::STATUS_IDLE, $uc->get('status'));
......@@ -2239,8 +2240,8 @@ class core_competency_api_testcase extends advanced_testcase {
$this->assertSame(null, $evidence->get('actionuserid'));
// Creating reverting the grade and send for review.
$evidence = api::add_evidence($u1->id, $c1->get('id'), $u1ctx->id, \core_competency\evidence::ACTION_OVERRIDE, 'invaliddata',
'error', null, true);
$evidence = api::add_evidence($u1->id, $c1->get('id'), $u1ctx->id, \core_competency\evidence::ACTION_OVERRIDE,
'invaliddata', 'error', null, true);
$evidence->read();
$uc = \core_competency\user_competency::get_record(array('userid' => $u1->id, 'competencyid' => $c1->get('id')));
$this->assertSame(null, $uc->get('grade'));
......@@ -2407,7 +2408,8 @@ class core_competency_api_testcase extends advanced_testcase {
api::add_evidence($u1->id, $c1a, $ctxid, evidence::ACTION_LOG, 'commentincontext', 'core');
$uc1a = user_competency::get_record(array('userid' => $u1->id, 'competencyid' => $c1a->get('id')));
$this->assertSame(null, $uc1a->get('proficiency'));
$this->assertFalse(user_competency::record_exists_select('userid = ? AND competencyid = ?', array($u1->id, $c1->get('id'))));
$this->assertFalse(user_competency::record_exists_select('userid = ? AND competencyid = ?',
array($u1->id, $c1->get('id'))));
// Now let's try complete a competency but the rule won't match (not all children are complete).
// The parent (the thing with the rule) will be created but won't have any evidence attached, and not
......@@ -2450,7 +2452,8 @@ class core_competency_api_testcase extends advanced_testcase {
api::add_evidence($u1->id, $c4a, $ctxid, evidence::ACTION_COMPLETE, 'commentincontext', 'core');
$uc4a = user_competency::get_record(array('userid' => $u1->id, 'competencyid' => $c4a->get('id')));
$this->assertEquals(true, $uc1a->get('proficiency'));
$this->assertFalse(user_competency::record_exists_select('userid = ? AND competencyid = ?', array($u1->id, $c4->get('id'))));
$this->assertFalse(user_competency::record_exists_select('userid = ? AND competencyid = ?',
array($u1->id, $c4->get('id'))));
// Check marking on something that has no parent. This just checks that nothing breaks.
api::add_evidence($u1->id, $c5, $ctxid, evidence::ACTION_COMPLETE, 'commentincontext', 'core');
......@@ -2791,7 +2794,8 @@ class core_competency_api_testcase extends advanced_testcase {
$this->assertTrue(api::set_course_competency_ruleoutcome($recordscc[0]['coursecompetency']->get('id'),
\core_competency\course_competency::OUTCOME_NONE));
$recordscc = api::list_course_competencies($course->id);
$this->assertEquals(\core_competency\course_competency::OUTCOME_NONE, $recordscc[0]['coursecompetency']->get('ruleoutcome'));
$this->assertEquals(\core_competency\course_competency::OUTCOME_NONE,
$recordscc[0]['coursecompetency']->get('ruleoutcome'));
}
/**
......
......@@ -42,7 +42,7 @@ class core_completionlib_testcase extends advanced_testcase {
$DB = $this->createMock(get_class($DB));
$CFG->enablecompletion = COMPLETION_ENABLED;
$USER = (object)array('id' =>314159);
$USER = (object)array('id' => 314159);
}
/**
......@@ -101,7 +101,7 @@ class core_completionlib_testcase extends advanced_testcase {
$this->assertEquals(COMPLETION_ENABLED, completion_info::is_enabled_for_site());
// Course.
$course = (object)array('id' =>13);
$course = (object)array('id' => 13);
$c = new completion_info($course);
$course->enablecompletion = COMPLETION_DISABLED;
$this->assertEquals(COMPLETION_DISABLED, $c->is_enabled());
......@@ -132,7 +132,7 @@ class core_completionlib_testcase extends advanced_testcase {
$mockbuilder->onlyMethods(array('is_enabled', 'get_data', 'internal_get_state', 'internal_set_data',
'user_can_override_completion'));
$mockbuilder->setConstructorArgs(array((object)array('id' => 42)));
$cm = (object)array('id'=>13, 'course'=>42);
$cm = (object)array('id' => 13, 'course' => 42);
// Not enabled, should do nothing.
$c = $mockbuilder->getMock();
......@@ -171,8 +171,8 @@ class core_completionlib_testcase extends advanced_testcase {
// Manual, change state (no change).
$c = $mockbuilder->getMock();
$cm = (object)array('id'=>13, 'course'=>42, 'completion'=>COMPLETION_TRACKING_MANUAL);
$current->completionstate=COMPLETION_COMPLETE;
$cm = (object)array('id' => 13, 'course' => 42, 'completion' => COMPLETION_TRACKING_MANUAL);
$current->completionstate = COMPLETION_COMPLETE;
$c->expects($this->once())
->method('is_enabled')
->with($cm)
......@@ -205,7 +205,7 @@ class core_completionlib_testcase extends advanced_testcase {
// Auto, change state.
$c = $mockbuilder->getMock();
$cm = (object)array('id'=>13, 'course'=>42, 'completion'=>COMPLETION_TRACKING_AUTOMATIC);
$cm = (object)array('id' => 13, 'course' => 42, 'completion' => COMPLETION_TRACKING_AUTOMATIC);
$current = (object)array('completionstate' => COMPLETION_COMPLETE, 'overrideby' => null);
$c->expects($this->once())
->method('is_enabled')
......@@ -301,7 +301,7 @@ class core_completionlib_testcase extends advanced_testcase {
->with($cm)
->will($this->returnValue(true));
$c->expects($this->Once()) // Pretend the user has the required capability for overriding completion statuses.
->method('user_can_override_completion')
->method('user_can_override_completion')
->will($this->returnValue(true));
$c->expects($this->once())
->method('get_data')
......@@ -455,7 +455,7 @@ class core_completionlib_testcase extends advanced_testcase {
$mockbuilder = $this->getMockBuilder('completion_info');
$mockbuilder->onlyMethods(array('is_enabled', 'get_data', 'internal_set_data', 'update_state'));
$mockbuilder->setConstructorArgs(array((object)array('id' => 42)));
$cm = (object)array('id'=>13, 'course'=>42);
$cm = (object)array('id' => 13, 'course' => 42);
// Not tracking completion, should do nothing.
$c = $mockbuilder->getMock();
......@@ -481,7 +481,7 @@ class core_completionlib_testcase extends advanced_testcase {
$c->expects($this->once())
->method('get_data')
->with($cm, 0)
->will($this->returnValue((object)array('viewed'=>COMPLETION_VIEWED)));
->will($this->returnValue((object)array('viewed' => COMPLETION_VIEWED)));
$c->set_module_viewed($cm);
// OK finally one that hasn't been viewed, now it should set it viewed
......@@ -494,10 +494,10 @@ class core_completionlib_testcase extends advanced_testcase {
$c->expects($this->once())
->method('get_data')
->with($cm, false, 1337)
->will($this->returnValue((object)array('viewed'=>COMPLETION_NOT_VIEWED)));
->will($this->returnValue((object)array('viewed' => COMPLETION_NOT_VIEWED)));
$c->expects($this->once())
->method('internal_set_data')
->with($cm, (object)array('viewed'=>COMPLETION_VIEWED));
->with($cm, (object)array('viewed' => COMPLETION_VIEWED));
$c->expects($this->once())
->method('update_state')
->with($cm, COMPLETION_COMPLETE, 1337);
......@@ -508,8 +508,8 @@ class core_completionlib_testcase extends advanced_testcase {
global $DB;
$this->mock_setup();
$course = (object)array('id'=>13);
$cm = (object)array('id'=>42);
$course = (object)array('id' => 13);
$cm = (object)array('id' => 42);
/** @var $DB PHPUnit_Framework_MockObject_MockObject */
$DB->expects($this->once())
......@@ -524,15 +524,15 @@ class core_completionlib_testcase extends advanced_testcase {
global $DB;
$this->mock_setup();
$course = (object)array('id'=>13);
$cm = (object)array('id'=>42, 'course'=>13);
$course = (object)array('id' => 13);
$cm = (object)array('id' => 42, 'course' => 13);
$c = new completion_info($course);
// Check it works ok without data in session.
/** @var $DB PHPUnit_Framework_MockObject_MockObject */
$DB->expects($this->once())
->method('delete_records')
->with('course_modules_completion', array('coursemoduleid'=>42))
->with('course_modules_completion', array('coursemoduleid' => 42))
->will($this->returnValue(true));
$c->delete_all_state($cm);
}
......@@ -546,13 +546,14 @@ class core_completionlib_testcase extends advanced_testcase {
$mockbuilder->setConstructorArgs(array((object)array('id' => 42)));
$c = $mockbuilder->getMock();
$cm = (object)array('id'=>13, 'course'=>42, 'completion'=>COMPLETION_TRACKING_AUTOMATIC);
$cm = (object)array('id' => 13, 'course' => 42, 'completion' => COMPLETION_TRACKING_AUTOMATIC);
/** @var $DB PHPUnit_Framework_MockObject_MockObject */
$DB->expects($this->once())
->method('get_recordset')
->will($this->returnValue(
new core_completionlib_fake_recordset(array((object)array('id'=>1, 'userid'=>100), (object)array('id'=>2, 'userid'=>101)))));
new core_completionlib_fake_recordset(array((object)array('id' => 1, 'userid' => 100),
(object)array('id' => 2, 'userid' => 101)))));
$c->expects($this->once())
->method('delete_all_state')
......@@ -561,8 +562,8 @@ class core_completionlib_testcase extends advanced_testcase {
$c->expects($this->once())
->method('get_tracked_users')
->will($this->returnValue(array(
(object)array('id'=>100, 'firstname'=>'Woot', 'lastname'=>'Plugh'),
(object)array('id'=>201, 'firstname'=>'Vroom', 'lastname'=>'Xyzzy'))));
(object)array('id' => 100, 'firstname' => 'Woot', 'lastname' => 'Plugh'),
(object)array('id' => 201, 'firstname' => 'Vroom', 'lastname' => 'Xyzzy'))));
$c->expects($this->exactly(3))
->method('update_state')
......@@ -733,9 +734,7 @@ class core_completionlib_testcase extends advanced_testcase {
// Cache for another user is not filled.
$this->assertEquals(false, $cache->get($d2->userid . '_' . $cm2->course));
// 3) Test where it THINKS the data is new (from cache) but actually
// in the database it has been set since.
// 1) Test with new data.
// 3) Test where it THINKS the data is new (from cache) but actually in the database it has been set since.
$forum3 = $this->getDataGenerator()->create_module('forum', array('course' => $this->course->id), $completionauto);
$cm3 = get_coursemodule_from_instance('forum', $forum3->id);
$newuser2 = $this->getDataGenerator()->create_user();
......@@ -765,23 +764,23 @@ class core_completionlib_testcase extends advanced_testcase {
->method('get_tracked_users')
->with(false, array(), 0, '', '', '', null)
->will($this->returnValue(array(
(object)array('id'=>100, 'firstname'=>'Woot', 'lastname'=>'Plugh'),
(object)array('id'=>201, 'firstname'=>'Vroom', 'lastname'=>'Xyzzy'))));
(object)array('id' => 100, 'firstname' => 'Woot', 'lastname' => 'Plugh'),
(object)array('id' => 201, 'firstname' => 'Vroom', 'lastname' => 'Xyzzy'))));
$DB->expects($this->once())
->method('get_in_or_equal')
->with(array(100, 201))
->will($this->returnValue(array(' IN (100, 201)', array())));
$progress1 = (object)array('userid'=>100, 'coursemoduleid'=>13);
$progress2 = (object)array('userid'=>201, 'coursemoduleid'=>14);
$progress1 = (object)array('userid' => 100, 'coursemoduleid' => 13);
$progress2 = (object)array('userid' => 201, 'coursemoduleid' => 14);
$DB->expects($this->once())
->method('get_recordset_sql')
->will($this->returnValue(new core_completionlib_fake_recordset(array($progress1, $progress2))));
$this->assertEquals(array(
100 => (object)array('id'=>100, 'firstname'=>'Woot', 'lastname'=>'Plugh',
'progress'=>array(13=>$progress1)),
201 => (object)array('id'=>201, 'firstname'=>'Vroom', 'lastname'=>'Xyzzy',
'progress'=>array(14=>$progress2)),
100 => (object)array('id' => 100, 'firstname' => 'Woot', 'lastname' => 'Plugh',
'progress' => array(13 => $progress1)),
201 => (object)array('id' => 201, 'firstname' => 'Vroom', 'lastname' => 'Xyzzy',
'progress' => array(14 => $progress2)),
), $c->get_progress_all(false));
}
......@@ -798,11 +797,11 @@ class core_completionlib_testcase extends advanced_testcase {
$ids = array();
$progress = array();
// With more than 1000 results.
for ($i = 100; $i<2000; $i++) {
$tracked[] = (object)array('id'=>$i, 'firstname'=>'frog', 'lastname'=>$i);
for ($i = 100; $i < 2000; $i++) {
$tracked[] = (object)array('id' => $i, 'firstname' => 'frog', 'lastname' => $i);
$ids[] = $i;
$progress[] = (object)array('userid'=>$i, 'coursemoduleid'=>13);
$progress[] = (object)array('userid'=>$i, 'coursemoduleid'=>14);
$progress[] = (object)array('userid' => $i, 'coursemoduleid' => 13);
$progress[] = (object)array('userid' => $i, 'coursemoduleid' => 14);
}
$c->expects($this->once())
->method('get_tracked_users')
......@@ -825,16 +824,16 @@ class core_completionlib_testcase extends advanced_testcase {
$result = $c->get_progress_all(true, 3);
$resultok = true;
$resultok = $resultok && ($ids == array_keys($result));
$resultok = $resultok && ($ids == array_keys($result));
foreach ($result as $userid => $data) {
$resultok = $resultok && $data->firstname == 'frog';
$resultok = $resultok && $data->lastname == $userid;
$resultok = $resultok && $data->id == $userid;
$resultok = $resultok && $data->firstname == 'frog';
$resultok = $resultok && $data->lastname == $userid;
$resultok = $resultok && $data->id == $userid;
$cms = $data->progress;
$resultok = $resultok && (array(13, 14) == array_keys($cms));
$resultok = $resultok && ((object)array('userid'=>$userid, 'coursemoduleid'=>13) == $cms[13]);
$resultok = $resultok && ((object)array('userid'=>$userid, 'coursemoduleid'=>14) == $cms[14]);
$resultok = $resultok && (array(13, 14) == array_keys($cms));
$resultok = $resultok && ((object)array('userid' => $userid, 'coursemoduleid' => 13) == $cms[13]);
$resultok = $resultok && ((object)array('userid' => $userid, 'coursemoduleid' => 14) == $cms[14]);
}
$this->assertTrue($resultok);
$this->assertCount(count($tracked), $result);
......@@ -847,9 +846,9 @@ class core_completionlib_testcase extends advanced_testcase {
$mockbuilder->onlyMethods(array('is_enabled', 'update_state'));
$mockbuilder->setConstructorArgs(array((object)array('id' => 42)));
$cm = (object)array('course'=>42, 'id'=>13, 'completion'=>0, 'completiongradeitemnumber'=>null);
$item = (object)array('itemnumber'=>3, 'gradepass'=>1, 'hidden'=>0);
$grade = (object)array('userid'=>31337, 'finalgrade'=>0, 'rawgrade'=>0);
$cm = (object)array('course' => 42, 'id' => 13, 'completion' => 0, 'completiongradeitemnumber' => null);
$item = (object)array('itemnumber' => 3, 'gradepass' => 1, 'hidden' => 0);
$grade = (object)array('userid' => 31337, 'finalgrade' => 0, 'rawgrade' => 0);
// Not enabled (should do nothing).
$c = $mockbuilder->getMock();
......@@ -869,7 +868,7 @@ class core_completionlib_testcase extends advanced_testcase {
// Enabled and completion required but item number is wrong, does nothing.
$c = $mockbuilder->getMock();
$cm = (object)array('course'=>42, 'id'=>13, 'completion'=>0, 'completiongradeitemnumber'=>7);
$cm = (object)array('course' => 42, 'id' => 13, 'completion' => 0, 'completiongradeitemnumber' => 7);
$c->expects($this->once())
->method('is_enabled')
->with($cm)
......@@ -880,8 +879,8 @@ class core_completionlib_testcase extends advanced_testcase {
// to call update_state with the new potential state being obtained from
// internal_get_grade_state.
$c = $mockbuilder->getMock();
$cm = (object)array('course'=>42, 'id'=>13, 'completion'=>0, 'completiongradeitemnumber'=>3);
$grade = (object)array('userid'=>31337, 'finalgrade'=>1, 'rawgrade'=>0);
$cm = (object)array('course' => 42, 'id' => 13, 'completion' => 0, 'completiongradeitemnumber' => 3);
$grade = (object)array('userid' => 31337, 'finalgrade' => 1, 'rawgrade' => 0);
$c->expects($this->once())
->method('is_enabled')
->with($cm)
......@@ -895,8 +894,8 @@ class core_completionlib_testcase extends advanced_testcase {
// Same as above but marked deleted. It is supposed to call update_state
// with new potential state being COMPLETION_INCOMPLETE.
$c = $mockbuilder->getMock();
$cm = (object)array('course'=>42, 'id'=>13, 'completion'=>0, 'completiongradeitemnumber'=>3);
$grade = (object)array('userid'=>31337, 'finalgrade'=>1, 'rawgrade'=>0);
$cm = (object)array('course' => 42, 'id' => 13, 'completion' => 0, 'completiongradeitemnumber' => 3);
$grade = (object)array('userid' => 31337, 'finalgrade' => 1, 'rawgrade' => 0);
$c->expects($this->once())
->method('is_enabled')
->with($cm)
......@@ -1078,7 +1077,8 @@ class core_completionlib_testcase extends advanced_testcase {
$events = $sink->get_events();
$event = reset($events);
$this->assertInstanceOf('\core\event\course_module_completion_updated', $event);
$this->assertEquals($forum->cmid, $event->get_record_snapshot('course_modules_completion', $event->objectid)->coursemoduleid);
$this->assertEquals($forum->cmid,
$event->get_record_snapshot('course_modules_completion', $event->objectid)->coursemoduleid);
$this->assertEquals($current, $event->get_record_snapshot('course_modules_completion', $event->objectid));
$this->assertEquals(context_module::instance($forum->cmid), $event->get_context());
$this->assertEquals($USER->id, $event->userid);
......@@ -1206,8 +1206,8 @@ class core_completionlib_testcase extends advanced_testcase {
* @param string|null $expectedexception Expected exception.
* @param int|null $expectedresult The expected completion status.
*/
public function test_get_grade_completion(bool $completionusegrade, bool $hasgrade, ?int $passinggrade, ?string $expectedexception,
?int $expectedresult) {
public function test_get_grade_completion(bool $completionusegrade, bool $hasgrade, ?int $passinggrade,
?string $expectedexception, ?int $expectedresult) {
$this->setup_data();
/** @var \mod_assign_generator $assigngenerator */
......
......@@ -48,18 +48,17 @@ class core_curl_security_helper_testcase extends advanced_testcase {
public function test_curl_security_helper_url_is_blocked($dns, $url, $blockedhosts, $allowedports, $expected) {
$this->resetAfterTest(true);
$helper = $this->getMockBuilder('\core\files\curl_security_helper')
->onlyMethods(['get_host_list_by_name'])
->getMock();
->onlyMethods(['get_host_list_by_name'])
->getMock();
// Override the get host list method to return hard coded values based on a mapping provided by $dns.
$helper->method('get_host_list_by_name')
->will(
$this->returnCallback(
function($host) use ($dns) {
return isset($dns[$host]) ? $dns[$host] : [];
}
)
);
$helper->method('get_host_list_by_name')->will(
$this->returnCallback(
function($host) use ($dns) {
return isset($dns[$host]) ? $dns[$host] : [];
}
)
);
set_config('curlsecurityblockedhosts', $blockedhosts);
set_config('curlsecurityallowedport', $allowedports);
......
......@@ -54,8 +54,10 @@ class core_filter_manager_testcase extends advanced_testcase {
public function test_filter_normal() {
$this->resetAfterTest();
filter_set_global_state('emoticon', TEXTFILTER_ON);
$this->assertMatchesRegularExpression('~^<p><img class="icon emoticon" alt="smile" title="smile" src="https://www.example.com/moodle/theme/image.php/_s/boost/core/1/s/smiley" /></p>$~',
$this->filter_text('<p>:-)</p>', array()));
$this->assertMatchesRegularExpression(
'~^<p><img class="icon emoticon" alt="smile" title="smile" ' .
'src="https://www.example.com/moodle/theme/image.php/_s/boost/core/1/s/smiley" /></p>$~',
$this->filter_text('<p>:-)</p>', array()));
}
public function test_one_filter_disabled() {
......@@ -68,15 +70,17 @@ class core_filter_manager_testcase extends advanced_testcase {
public function test_disabling_other_filter_does_not_break_it() {
$this->resetAfterTest();
filter_set_global_state('emoticon', TEXTFILTER_ON);
$this->assertMatchesRegularExpression('~^<p><img class="icon emoticon" alt="smile" title="smile" src="https://www.example.com/moodle/theme/image.php/_s/boost/core/1/s/smiley" /></p>$~',
$this->filter_text('<p>:-)</p>', array('urltolink')));
$this->assertMatchesRegularExpression('~^<p><img class="icon emoticon" alt="smile" ' .
'title="smile" src="https://www.example.com/moodle/theme/image.php/_s/boost/core/1/s/smiley" /></p>$~',
$this->filter_text('<p>:-)</p>', array('urltolink')));
<