@@ -127,6 +127,13 @@ public function test_delete_data_for_users() {
127127
128128 $ this ->resetAfterTest ();
129129
130+ $ component = 'mod_pdfannotator ' ;
131+
132+ $ usercontext1 = \context_user::instance ($ this ->user ->id );
133+ $ userlist1 = new \core_privacy \local \request \userlist ($ usercontext1 , $ component );
134+ provider::get_users_in_context ($ userlist1 );
135+ $ this ->assertCount (1 , $ userlist1 );
136+
130137 // Create a comment for the question above.
131138 $ answer = new stdClass ();
132139 $ answer ->pdfannotatorid = $ this ->pdffile ->id ;
@@ -171,6 +178,54 @@ public function test_delete_data_for_users() {
171178 // Delete using delete_data_for_user.
172179 provider::delete_data_for_users ($ userlist );
173180
174-
181+ list ($ userinsql , $ userinparams ) = $ DB ->get_in_or_equal ($ userlist ->get_userids (), SQL_PARAMS_NAMED );
182+
183+ $ annotatorid = $ this ->pdffile ->id ;
184+
185+ // Combine instance + user sql.
186+ $ params = array_merge (['pdfannotatorid ' => $ annotatorid ], $ userinparams );
187+ $ sql = "pdfannotatorid = :pdfannotatorid AND userid {$ userinsql }" ;
188+
189+ // Count subscriptions.
190+ $ annotations = $ DB ->get_records ('pdfannotator_annotations ' , ['pdfannotatorid ' => $ annotatorid ]);
191+ $ annotationids = array_column ($ annotations , 'id ' );
192+ list ($ subinsql , $ subinparams ) = $ DB ->get_in_or_equal ($ annotationids , SQL_PARAMS_NAMED );
193+
194+ $ count_subs = $ DB ->count_records_sql ("SELECT *
195+ FROM {pdfannotator_subscriptions} sub
196+ WHERE sub.userid {$ userinsql }
197+ AND sub.annotationid {$ subinsql }" ,
198+ array_merge ($ userinparams , $ subinparams ));
199+ $ this ->assertCount (0 , $ count_subs );
200+
201+ // Count votes.
202+ $ comments = $ DB ->get_records ('pdfannotator_comments ' , ['pdfannotatorid ' => $ annotatorid ]);
203+ $ commentsids = array_column ($ comments , 'id ' );
204+ list ($ commentinsql , $ commentinparams ) = $ DB ->get_in_or_equal ($ commentsids , SQL_PARAMS_NAMED );
205+
206+ $ count_votes = $ DB ->count_records_sql ("SELECT *
207+ FORM {pdfannotator_votes} votes
208+ WHERE vote.userid {$ userinsql }
209+ AND vote.commentid {$ commentinsql }" ,
210+ array_merge ($ userinparams , $ commentinparams ));
211+ $ this ->assertCount (0 , $ count_votes );
212+
213+ // Count annotations, reports, and comments.
214+ $ count_annotations = count ($ DB ->get_records_select ('pdfannotator_annotations ' , $ sql , $ params ));
215+ $ this ->assertCount (0 , $ count_annotations );
216+ $ count_reports = count ($ DB ->get_records_select ('pdfannotator_reports ' , $ sql , $ params ));
217+ $ this ->assertCount (0 , $ count_reports );
218+ $ count_comments = count ($ DB ->get_records_select ('pdfannotator_comments ' , $ sql , $ params ));
219+ $ this ->assertCount (0 , $ count_comments );
220+
221+ // Count pictures in comments.
222+ $ count_pics = $ DB ->count_records_sql ("SELECT *
223+ FORM {files} imgs
224+ WHERE imgs.component = 'mod_pdfannotator'
225+ AND imgs.filearea = 'post'
226+ AND imgs.userid {$ userinsql }
227+ AND imgs.itemid {$ commentinsql }" ,
228+ array_merge ($ userinparams , $ commentinparams ));
229+ $ this ->assertCount (0 , $ count_pics );
175230 }
176231}
0 commit comments