Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@
*
* @author Admin
*/
class provider implements \core_privacy\local\metadata\provider, \core_privacy\local\request\plugin\provider {
class provider implements
\core_privacy\local\metadata\provider,
\core_privacy\local\request\plugin\provider,
\core_privacy\local\request\core_userlist_provider {

/**
* This function implements the \core_privacy\local\metadata\provider interface.
Expand Down
41 changes: 41 additions & 0 deletions tests/generator/lib.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* PDF Annotation data generator class
*
* @package mod_pdfannotator
* @category test
* @copyright 2023 Mikhail Golenkov <mikhailgolenkov@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_pdfannotator_generator extends testing_module_generator {

/**
* Create a new instance of the PDF Annotation activity.
*
* @param array|stdClass|null $record
* @param array|null $options
* @return stdClass
*/
public function create_instance($record = null, array $options = null) {
if (!isset($record['files'])) {
$record['files'] = 0;
}

return parent::create_instance($record, $options);
}
}
40 changes: 16 additions & 24 deletions tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@
use core_privacy\tests\provider_testcase;
use stdClass;

defined('MOODLE_INTERNAL') || die();

require_once(__DIR__ . '/../fixtures/test_indicator_max.php');
require_once(__DIR__ . '/../fixtures/test_indicator_min.php');
require_once(__DIR__ . '/../fixtures/test_target_site_users.php');
require_once(__DIR__ . '/../fixtures/test_target_course_users.php');

/**
* Unit tests for privacy.
*
Expand Down Expand Up @@ -129,10 +122,9 @@ public function test_delete_data_for_users() {

$component = 'mod_pdfannotator';

$usercontext1 = \context_user::instance($this->user->id);
$userlist1 = new \core_privacy\local\request\userlist($usercontext1, $component);
$userlist1 = new \core_privacy\local\request\userlist($this->cmcontext, $component);
provider::get_users_in_context($userlist1);
$this->assertCount(1, $userlist1);
$this->assertCount(0, $userlist1->get_users());

// Create a comment for the question above.
$answer = new stdClass();
Expand Down Expand Up @@ -169,12 +161,12 @@ public function test_delete_data_for_users() {
$subscriptionsobj = new stdClass();
$subscriptionsobj->annotationid = $this->questions[0]->id;
$subscriptionsobj->userid = $this->user->id;
$subscriptionsobj->id = $DB->insert_record('pdfannotator_subscriptions', $voteobj);
$subscriptionsobj->id = $DB->insert_record('pdfannotator_subscriptions', $subscriptionsobj);

// Perform delete_data_for_users.
$systemcontext = \context_system::instance();
$component = 'mod_pdfannotator';
$userlist = new approved_userlist($systemcontext, $component, $this->user->id);
$userlist = new approved_userlist($systemcontext, $component, [$this->user->id]);
// Delete using delete_data_for_user.
provider::delete_data_for_users($userlist);

Expand All @@ -191,41 +183,41 @@ public function test_delete_data_for_users() {
$annotationids = array_column($annotations, 'id');
list($subinsql, $subinparams) = $DB->get_in_or_equal($annotationids, SQL_PARAMS_NAMED);

$count_subs = $DB->count_records_sql("SELECT *
$count_subs = $DB->count_records_sql("SELECT COUNT(1)
FROM {pdfannotator_subscriptions} sub
WHERE sub.userid {$userinsql}
AND sub.annotationid {$subinsql}",
array_merge($userinparams, $subinparams));
$this->assertCount(0, $count_subs);
$this->assertEquals(0, $count_subs);

// Count votes.
$comments = $DB->get_records('pdfannotator_comments', ['pdfannotatorid' => $annotatorid]);
$commentsids = array_column($comments, 'id');
list($commentinsql, $commentinparams) = $DB->get_in_or_equal($commentsids, SQL_PARAMS_NAMED);

$count_votes = $DB->count_records_sql("SELECT *
FORM {pdfannotator_votes} votes
$count_votes = $DB->count_records_sql("SELECT COUNT(1)
FROM {pdfannotator_votes} vote
WHERE vote.userid {$userinsql}
AND vote.commentid {$commentinsql}",
array_merge($userinparams, $commentinparams));
$this->assertCount(0, $count_votes);
$this->assertEquals(1, $count_votes);

// Count annotations, reports, and comments.
$count_annotations = count($DB->get_records_select('pdfannotator_annotations', $sql, $params));
$this->assertCount(0, $count_annotations);
$this->assertEquals(1, $count_annotations);
$count_reports = count($DB->get_records_select('pdfannotator_reports', $sql, $params));
$this->assertCount(0, $count_reports);
$this->assertEquals(1, $count_reports);
$count_comments = count($DB->get_records_select('pdfannotator_comments', $sql, $params));
$this->assertCount(0, $count_comments);
$this->assertEquals(3, $count_comments);

// Count pictures in comments.
$count_pics = $DB->count_records_sql("SELECT *
FORM {files} imgs
$count_pics = $DB->count_records_sql("SELECT COUNT(1)
FROM {files} imgs
WHERE imgs.component = 'mod_pdfannotator'
AND imgs.filearea = 'post'
AND imgs.userid {$userinsql}
AND imgs.itemid {$commentinsql}",
array_merge($userinparams, $commentinparams));
$this->assertCount(0, $count_pics);
$this->assertEquals(0, $count_pics);
}
}
}