Skip to content
Snippets Groups Projects
Commit 1c46c0b1 authored by Justus Dieckmann's avatar Justus Dieckmann Committed by Tobias Reischmann
Browse files

Privacy: Implement tests for delete_data_for_user, delete_data_for_users, get_users_in_context

parent e09c2c34
No related branches found
No related tags found
No related merge requests found
...@@ -166,7 +166,7 @@ class provider implements ...@@ -166,7 +166,7 @@ class provider implements
list($insql, $params) = $DB->get_in_or_equal($userlist->get_userids()); list($insql, $params) = $DB->get_in_or_equal($userlist->get_userids());
$sql = "UPDATE {tool_lifecycle_action_log} $sql = "UPDATE {tool_lifecycle_action_log}
SET userid = -1 SET userid = -1
WHERE $insql"; WHERE userid " . $insql;
$DB->execute($sql, $params); $DB->execute($sql, $params);
} }
......
...@@ -26,7 +26,9 @@ ...@@ -26,7 +26,9 @@
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
global $CFG; global $CFG;
use core_privacy\local\request\approved_userlist;
use core_privacy\local\request\content_writer; use core_privacy\local\request\content_writer;
use core_privacy\local\request\userlist;
use core_privacy\local\request\writer; use core_privacy\local\request\writer;
use core_privacy\tests\provider_testcase; use core_privacy\tests\provider_testcase;
use core_privacy\tests\request\approved_contextlist; use core_privacy\tests\request\approved_contextlist;
...@@ -165,4 +167,79 @@ class tool_lifecycle_privacy_test extends provider_testcase { ...@@ -165,4 +167,79 @@ class tool_lifecycle_privacy_test extends provider_testcase {
$this->assertFalse($DB->record_exists_select('tool_lifecycle_action_log', 'userid != -1')); $this->assertFalse($DB->record_exists_select('tool_lifecycle_action_log', 'userid != -1'));
} }
public function test_delete_data_for_user() {
global $DB;
$c1 = $this->getDataGenerator()->create_course();
$c2 = $this->getDataGenerator()->create_course();
$u1 = $this->getDataGenerator()->create_user();
$u2 = $this->getDataGenerator()->create_user();
$p1 = $this->generator->create_process($c1->id, $this->workflow->id);
$p2 = $this->generator->create_process($c2->id, $this->workflow->id);
$processor = new processor();
$processor->process_courses();
$this->setUser($u1);
interaction_manager::handle_interaction($this->emailstep->id, $p1->id, self::ACTION_KEEP);
$this->setUser($u2);
interaction_manager::handle_interaction($this->emailstep->id, $p2->id, self::ACTION_KEEP);
$contextlist = new approved_contextlist($u1, 'tool_lifecycle', [1]);
provider::delete_data_for_user($contextlist);
$this->assertEquals(0, $DB->count_records_select('tool_lifecycle_action_log', "userid = $u1->id"));
$this->assertEquals(1, $DB->count_records_select('tool_lifecycle_action_log', "userid = $u2->id"));
$this->assertEquals(1, $DB->count_records_select('tool_lifecycle_action_log', "userid = -1"));
}
public function test_get_users_in_context() {
$c1 = $this->getDataGenerator()->create_course();
$c2 = $this->getDataGenerator()->create_course();
$u1 = $this->getDataGenerator()->create_user();
$p1 = $this->generator->create_process($c1->id, $this->workflow->id);
$p2 = $this->generator->create_process($c2->id, $this->workflow->id);
$processor = new processor();
$processor->process_courses();
$this->setUser($u1);
interaction_manager::handle_interaction($this->emailstep->id, $p1->id, self::ACTION_KEEP);
interaction_manager::handle_interaction($this->emailstep->id, $p2->id, self::ACTION_KEEP);
$userlist = new userlist(context_system::instance(), 'tool_lifecycle');
provider::get_users_in_context($userlist);
$this->assertEquals(1, $userlist->count());
$this->assertEquals($u1->id, $userlist->current()->id);
}
public function test_delete_data_for_users() {
global $DB;
$c1 = $this->getDataGenerator()->create_course();
$c2 = $this->getDataGenerator()->create_course();
$u1 = $this->getDataGenerator()->create_user();
$u2 = $this->getDataGenerator()->create_user();
$proc1 = $this->generator->create_process($c1->id, $this->workflow->id);
$proc2 = $this->generator->create_process($c2->id, $this->workflow->id);
$this->setUser($u1);
$processor = new processor();
$processor->process_courses();
interaction_manager::handle_interaction($this->emailstep->id, $proc1->id, self::ACTION_KEEP);
$this->setUser($u2);
interaction_manager::handle_interaction($this->emailstep->id, $proc2->id, self::ACTION_KEEP);
$userlist = new approved_userlist(context_system::instance(), 'tool_lifecycle', [$u1->id]);
provider::delete_data_for_users($userlist);
$this->assertEquals(0, $DB->count_records_select('tool_lifecycle_action_log', "userid = $u1->id"));
$this->assertEquals(1, $DB->count_records_select('tool_lifecycle_action_log', "userid = $u2->id"));
$this->assertEquals(1, $DB->count_records_select('tool_lifecycle_action_log', "userid = -1"));
}
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment