Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
moodle-tool_lifecycle
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elc
moodle-tool_lifecycle
Commits
1c46c0b1
You need to sign in or sign up before continuing.
Commit
1c46c0b1
authored
5 years ago
by
Justus Dieckmann
Committed by
Tobias Reischmann
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
classes/privacy/provider.php
+1
-1
1 addition, 1 deletion
classes/privacy/provider.php
tests/privacy_test.php
+77
-0
77 additions, 0 deletions
tests/privacy_test.php
with
78 additions
and
1 deletion
classes/privacy/provider.php
+
1
−
1
View file @
1c46c0b1
...
@@ -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
);
}
}
...
...
This diff is collapsed.
Click to expand it.
tests/privacy_test.php
+
77
−
0
View file @
1c46c0b1
...
@@ -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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment