1+ <?php
2+ // This file is part of Moodle - http://moodle.org/
3+ //
4+ // Moodle is free software: you can redistribute it and/or modify
5+ // it under the terms of the GNU General Public License as published by
6+ // the Free Software Foundation, either version 3 of the License, or
7+ // (at your option) any later version.
8+ //
9+ // Moodle is distributed in the hope that it will be useful,
10+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+ // GNU General Public License for more details.
13+ //
14+ // You should have received a copy of the GNU General Public License
15+ // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+ namespace mod_pdfannotator \privacy ;
18+
19+ use mod_pdfannotator \privacy \provider ;
20+ use core_privacy \local \request \transform ;
21+ use core_privacy \local \request \writer ;
22+ use core_privacy \local \request \approved_contextlist ;
23+ use core_privacy \local \request \approved_userlist ;
24+ use stdClass ;
25+
26+ defined ('MOODLE_INTERNAL ' ) || die ();
27+
28+ require_once (__DIR__ . '/../fixtures/test_indicator_max.php ' );
29+ require_once (__DIR__ . '/../fixtures/test_indicator_min.php ' );
30+ require_once (__DIR__ . '/../fixtures/test_target_site_users.php ' );
31+ require_once (__DIR__ . '/../fixtures/test_target_course_users.php ' );
32+
33+ /**
34+ * Unit tests for privacy.
35+ *
36+ * @package mod_pdfannotator
37+ * @copyright IT Center RWTH Aachen University
38+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39+ */
40+ class provider_test extends \core_privacy \tests \provider_testcase {
41+
42+ protected $ course ;
43+ protected $ cmcontext ;
44+ protected $ user ;
45+ protected $ pdffile ;
46+ protected $ annotations ;
47+ protected $ questions ;
48+ protected $ answers ;
49+
50+ public function setUp (): void {
51+ global $ DB ;
52+
53+ $ this ->resetAfterTest ();
54+
55+ // Create a course.
56+ $ generator = $ this ->getDataGenerator ();
57+ $ this ->course = $ generator ->create_course ();
58+
59+ // Create a pdfannotator module.
60+ $ cm = $ generator ->create_module ('pdfannotator ' , ['course ' => $ this ->course ->id ]);
61+ $ this ->cmcontext = \context_module::instance ($ cm ->cmid );
62+
63+ // Create a user.
64+ $ this ->user = $ generator ->create_user ();
65+
66+ // Create a pdf object.
67+ $ pdfobject = new stdClass ();
68+ $ pdfobject ->course = $ this ->course ->id ;
69+ $ pdfobject ->name = "PDF_Provider_Test " ;
70+ $ pdfobject ->intro = "" ;
71+ $ pdfobject ->introformat = 1 ;
72+ $ pdfobject ->usevotes = 1 ;
73+ $ pdfobject ->useprint = 1 ;
74+ $ pdfobject ->useprintcomments = 1 ;
75+ $ pdfobject ->use_studenttextbox = 0 ;
76+ $ pdfobject ->use_studentdrawing = 0 ;
77+ $ pdfobject ->useprivatecomments = 0 ;
78+ $ pdfobject ->useprotectedcomments = 0 ;
79+ $ pdfobject ->timecreated = time ();
80+ $ pdfobject ->timemodified = time ();
81+ $ pdfobject ->id = $ DB ->insert_record ('pdfannotator ' , $ pdfobject );
82+ $ this ->pdffile = $ pdfobject ;
83+
84+ // Create an (pin as a test) annotation to the test pdf.
85+ $ annotationobj = new stdClass ();
86+ $ annotationobj ->pdfannotatorid = $ this ->pdffile ->id ;
87+ $ annotationobj ->page = 1 ;
88+ $ annotationobj ->userid = $ this ->user ->id ;
89+ $ pinannotation = $ DB ->get_record ('pdfannotator_annotationtypes ' , ['name ' => 'pin ' ]);
90+ $ annotationobj ->annotationtypeid = $ pinannotation ->id ;
91+ $ annotationobj ->data = json_encode (['x ' => 365 , 'y ' => 166 ]);
92+ $ annotationobj ->timecreated = time ();
93+ $ annotationobj ->timemodified = time ();
94+ $ annotationobj ->id = $ DB ->insert_record ('pdfannotator_annotations ' , $ annotationobj );
95+ $ this ->annotations [] = $ annotationobj ;
96+
97+ // Create a question for the pin annotation.
98+ $ question = new stdClass ();
99+ $ question ->pdfannotatorid = $ this ->pdffile ->id ;
100+ $ question ->annotationid = $ this ->annotations [0 ]->id ;
101+ $ question ->userid = $ this ->user ->id ;
102+ $ question ->timecreated = time ();
103+ $ question ->timemodified = time ();
104+ $ question ->isquestion = 1 ;
105+ $ question ->isdeleted = 0 ;
106+ $ question ->ishidden = 0 ;
107+ $ question ->solved = 0 ;
108+ $ question ->id = $ DB ->insert_record ('pdfannotator_comments ' , $ question );
109+ $ this ->questions [] = $ question ;
110+
111+ // Create a comment for the question above.
112+ $ answer = new stdClass ();
113+ $ answer ->pdfannotatorid = $ this ->pdffile ->id ;
114+ $ answer ->annotationid = $ this ->annotations [0 ]->id ;
115+ $ answer ->userid = $ this ->user ->id ;
116+ $ answer ->timecreated = time ();
117+ $ answer ->timemodified = time ();
118+ $ answer ->isquestion = 0 ;
119+ $ answer ->isdeleted = 0 ;
120+ $ answer ->ishidden = 0 ;
121+ $ answer ->solved = 0 ;
122+ $ answer ->id = $ DB ->insert_record ('pdfannotator_comments ' , $ answer );
123+ $ this ->answers [] = $ answer ;
124+ }
125+
126+ public function test_delete_data_for_users () {
127+ global $ DB ;
128+
129+ $ this ->resetAfterTest ();
130+
131+ // Create a comment for the question above.
132+ $ answer = new stdClass ();
133+ $ answer ->pdfannotatorid = $ this ->pdffile ->id ;
134+ $ answer ->annotationid = $ this ->annotations [0 ]->id ;
135+ $ answer ->userid = $ this ->user ->id ;
136+ $ answer ->timecreated = time ();
137+ $ answer ->timemodified = time ();
138+ $ answer ->isquestion = 0 ;
139+ $ answer ->isdeleted = 0 ;
140+ $ answer ->ishidden = 0 ;
141+ $ answer ->solved = 0 ;
142+ $ answer ->id = $ DB ->insert_record ('pdfannotator_comments ' , $ answer );
143+ $ this ->answers [] = $ answer ;
144+
145+ // Report the first comment from the setUp().
146+ $ reportobj = new stdClass ();
147+ $ reportobj ->commentid = $ this ->answers [0 ]->id ;
148+ $ reportobj ->courseid = $ this ->course ->id ;
149+ $ reportobj ->pdfannotatorid = $ this ->pdffile ->id ;
150+ $ reportobj ->userid = $ this ->user ->id ;
151+ $ reportobj ->timecreated = time ();
152+ $ reportobj ->seen = 0 ;
153+ $ reportobj ->id = $ DB ->insert_record ('pdfannotator_reports ' , $ reportobj );
154+
155+ // Vote the second comment in the quetions[0].
156+ $ voteobj = new stdClass ();
157+ $ voteobj ->commentid = $ this ->answers [1 ]->id ;
158+ $ voteobj ->userid = $ this ->user ->id ;
159+ $ voteobj ->vote = 1 ;
160+ $ voteobj ->id = $ DB ->insert_record ('pdfannotator_votes ' , $ voteobj );
161+
162+ // Subscribe the questions[0].
163+ $ subscriptionsobj = new stdClass ();
164+ $ subscriptionsobj ->annotationid = $ this ->questions [0 ]->id ;
165+ $ subscriptionsobj ->userid = $ this ->user ->id ;
166+ $ subscriptionsobj ->id = $ DB ->insert_record ('pdfannotator_subscriptions ' , $ voteobj );
167+
168+ // Perform delete_data_for_users.
169+ $ systemcontext = \context_system::instance ();
170+ $ component = 'mod_pdfannotator ' ;
171+ $ userlist = new approved_userlist ($ systemcontext , $ component , $ this ->user ->id );
172+ // Delete using delete_data_for_user.
173+ provider::delete_data_for_users ($ userlist );
174+ }
175+ }
0 commit comments