Skip to content

Commit

Permalink
Merge branch 'MDL-73423-master' of https://github.com/marinaglancy/mo…
Browse files Browse the repository at this point in the history
  • Loading branch information
junpataleta committed May 25, 2022
2 parents 0839152 + a0398fd commit e60e8bc
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 31 deletions.
26 changes: 13 additions & 13 deletions admin/roles/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,48 +190,48 @@ public function test_export_user_data() {
if ($data = $writer->get_data($subcontextstudent)) {
$this->assertEquals($user->id, reset($data)->userid);
}
if ($data = $writer->get_data($subcontextrc)) {
if ($data = (array)$writer->get_data($subcontextrc)) {
$this->assertEquals('moodle/backup:backupactivity', reset($data)->capability);
$this->assertEquals($strpermissions[CAP_ALLOW], reset($data)->permission);
}
}
if ($context->contextlevel == CONTEXT_COURSE) {
if ($data = $writer->get_data($subcontextstudent)) {
if ($data = (array)$writer->get_data($subcontextstudent)) {
$this->assertEquals($user->id, reset($data)->userid);
}
if ($data = $writer->get_data($subcontextrc)) {
if ($data = (array)$writer->get_data($subcontextrc)) {
$this->assertEquals('moodle/backup:backupcourse', reset($data)->capability);
}
}
if ($context->contextlevel == CONTEXT_COURSECAT) {
if ($data = $writer->get_data($subcontextmanager)) {
if ($data = (array)$writer->get_data($subcontextmanager)) {
$this->assertEquals($user->id, reset($data)->modifierid);
}
if ($data = $writer->get_data($subcontextrc)) {
if ($data = (array)$writer->get_data($subcontextrc)) {
$this->assertEquals('moodle/category:manage', reset($data)->capability);
}
}
if ($context->contextlevel == CONTEXT_SYSTEM) {
if ($data = $writer->get_data($subcontextmanager)) {
if ($data = (array)$writer->get_data($subcontextmanager)) {
$this->assertEquals($user->id, reset($data)->modifierid);
}
if ($data = $writer->get_data($subcontextrc)) {
if ($data = (array)$writer->get_data($subcontextrc)) {
$this->assertEquals('moodle/backup:backupcourse', reset($data)->capability);
}
}
if ($context->contextlevel == CONTEXT_BLOCK) {
if ($data = $writer->get_data($subcontextstudent)) {
if ($data = (array)$writer->get_data($subcontextstudent)) {
$this->assertEquals($user->id, reset($data)->userid);
}
if ($data = $writer->get_data($subcontextrc)) {
if ($data = (array)$writer->get_data($subcontextrc)) {
$this->assertEquals('moodle/block:edit', reset($data)->capability);
}
}
if ($context->contextlevel == CONTEXT_USER) {
if ($data = $writer->get_data($subcontextmanager)) {
if ($data = (array)$writer->get_data($subcontextmanager)) {
$this->assertEquals($user->id, reset($data)->userid);
}
if ($data = $writer->get_data($subcontextrc)) {
if ($data = (array)$writer->get_data($subcontextrc)) {
$this->assertEquals('moodle/competency:evidencedelete', reset($data)->capability);
}
}
Expand Down Expand Up @@ -415,7 +415,7 @@ public function test_export_user_role_to_cohort() {
provider::export_user_role_to_cohort($user->id);
$writer = writer::with_context($contextuserassignover);
$this->assertTrue($writer->has_any_data());
$exported = $writer->get_related_data($subcontextteacher, 'cohortroles');
$exported = (array)$writer->get_related_data($subcontextteacher, 'cohortroles');
$this->assertEquals($user->id, reset($exported)->userid);

// Test User is member of a cohort which User2 is assigned to role to this cohort.
Expand All @@ -432,7 +432,7 @@ public function test_export_user_role_to_cohort() {
provider::export_user_role_to_cohort($user->id);
$writer = writer::with_context($contextuser);
$this->assertTrue($writer->has_any_data());
$exported = $writer->get_related_data($subcontextteacher, 'cohortroles');
$exported = (array)$writer->get_related_data($subcontextteacher, 'cohortroles');
$this->assertEquals($user2->id, reset($exported)->userid);
}

Expand Down
8 changes: 4 additions & 4 deletions admin/tool/usertours/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ public function test_export_user_preferences_correct_user(): void {
$writer = writer::with_context(\context_system::instance());
$this->assertTrue($writer->has_any_data());

$prefs = $writer->get_user_preferences('tool_usertours');
$this->assertCount(1, (array) $prefs);
$prefs = (array)$writer->get_user_preferences('tool_usertours');
$this->assertCount(1, $prefs);

// We should have received back the "completed tour" preference of the test user.
$this->assertStringStartsWith('You last marked the "' . $tour->get_name() . '" user tour as completed on',
Expand Down Expand Up @@ -180,8 +180,8 @@ public function test_export_user_preferences_deleted_tour() {
$this->assertTrue($writer->has_any_data());

// We should have one preference.
$prefs = $writer->get_user_preferences('tool_usertours');
$this->assertCount(1, (array) $prefs);
$prefs = (array)$writer->get_user_preferences('tool_usertours');
$this->assertCount(1, $prefs);

// The preference should be related to the first tour.
$this->assertStringContainsString($tour1->get_name(), reset($prefs)->description);
Expand Down
2 changes: 1 addition & 1 deletion auth/mnet/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function test_export_user_data() {
$approvedlist = new approved_contextlist($user, 'auth_mnet', [$usercontext->id]);
provider::export_user_data($approvedlist);

$data = $writer->get_data([get_string('pluginname', 'auth_mnet'), $hostrecord->name, $logrecord->coursename]);
$data = (array)$writer->get_data([get_string('pluginname', 'auth_mnet'), $hostrecord->name, $logrecord->coursename]);

$this->assertEquals($logrecord->remoteid, reset($data)->remoteid);
$this->assertEquals(transform::datetime($logrecord->time), reset($data)->time);
Expand Down
2 changes: 1 addition & 1 deletion enrol/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function test_export_user_data() {
writer::reset();
$writer = writer::with_context($coursecontext2);
$this->export_context_data_for_user($user1->id, $coursecontext2, 'core_enrol');
$data = $writer->get_related_data($subcontexts, 'manual');
$data = (array)$writer->get_related_data($subcontexts, 'manual');
$this->assertEquals($enrolmentcouse2->status, reset($data)->status);
$this->assertEquals(transform::datetime($enrolmentcouse2->timestart), reset($data)->timestart);
$this->assertEquals(transform::datetime($enrolmentcouse2->timeend), reset($data)->timeend);
Expand Down
8 changes: 5 additions & 3 deletions lib/dml/sqlsrv_native_moodle_database.php
Original file line number Diff line number Diff line change
Expand Up @@ -978,10 +978,11 @@ public function get_records_sql($sql, array $params = null, $limitfrom = 0, $lim
$results = array();

foreach ($rs as $row) {
$id = reset($row);
$rowarray = (array)$row;
$id = reset($rowarray);

if (isset($results[$id])) {
$colname = key($row);
$colname = key($rowarray);
debugging("Did you remember to make the first column something unique in your call to get_records? Duplicate value '$id' found in column '$colname'.", DEBUG_DEVELOPER);
}
$results[$id] = (object)$row;
Expand All @@ -1006,7 +1007,8 @@ public function get_fieldset_sql($sql, array $params = null) {
$results = array ();

foreach ($rs as $row) {
$results[] = reset($row);
$rowarray = (array)$row;
$results[] = reset($rowarray);
}
$rs->close();

Expand Down
4 changes: 2 additions & 2 deletions mnet/service/enrol/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ public function test_export_user_data() {
$this->assertFalse($writer->has_any_data());
$approvedlist = new approved_contextlist($user, 'mnetservice_enrol', [$usercontext->id]);
provider::export_user_data($approvedlist);
$data = $writer->get_data($subcontexts);
$this->assertCount(1, (array)$data);
$data = (array)$writer->get_data($subcontexts);
$this->assertCount(1, $data);
$this->assertEquals($this->mnethost->name, reset($data)->host);
$remotecoursename = $DB->get_field('mnetservice_enrol_courses', 'fullname',
array('remoteid' => $this->enrolment->remotecourseid));
Expand Down
8 changes: 4 additions & 4 deletions mod/h5pactivity/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,21 +123,21 @@ public function test_export_user_data() {
$data = $writer->get_data([]);
$this->assertEquals('H5P 1', $data->name);

$data = $writer->get_data($subcontextattempt1);
$this->assertCount(1, (array) $data);
$data = (array)$writer->get_data($subcontextattempt1);
$this->assertCount(1, $data);
$this->assertCount(3, (array) reset($data));
$subcontextattempt2 = [
get_string('myattempts', 'mod_h5pactivity'),
get_string('attempt', 'mod_h5pactivity'). " 2"
];
$data = $writer->get_data($subcontextattempt2);
$data = (array)$writer->get_data($subcontextattempt2);
$this->assertCount(3, (array) reset($data));
// The student1 has only 1 tracked attempts.
$subcontextattempt3 = [
get_string('myattempts', 'mod_h5pactivity'),
get_string('attempt', 'mod_h5pactivity'). " 3"
];
$data = $writer->get_data($subcontextattempt3);
$data = (array)$writer->get_data($subcontextattempt3);
$this->assertEmpty($data);
}

Expand Down
6 changes: 3 additions & 3 deletions mod/scorm/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@ public function test_export_user_data() {
$data = $writer->get_data([]);
$this->assertEquals('SCORM1', $data->name);

$data = $writer->get_data($subcontextattempt1);
$this->assertCount(1, (array) $data);
$data = (array)$writer->get_data($subcontextattempt1);
$this->assertCount(1, $data);
$this->assertCount(2, (array) reset($data));
$subcontextattempt2 = [
get_string('myattempts', 'scorm'),
get_string('attempt', 'scorm'). " 2"
];
$data = $writer->get_data($subcontextattempt2);
$data = (array)$writer->get_data($subcontextattempt2);
$this->assertCount(2, (array) reset($data));
// The student1 has only 2 scoes_track attempts.
$subcontextattempt3 = [
Expand Down

0 comments on commit e60e8bc

Please sign in to comment.