forked from lsuits/lsu-block_quickmail
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds test coverage for privacy provider.
- Loading branch information
1 parent
c696dbc
commit 6235a00
Showing
3 changed files
with
304 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?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/>. | ||
|
||
/** | ||
* Data generator for block_quickmail. | ||
* | ||
* @package block_quickmail | ||
* @copyright The Regents of the University of California | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
/** | ||
* Quickmail block data generator class. | ||
* | ||
* @package block_quickmail | ||
* @copyright The Regents of the University of California | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class block_quickmail_generator extends testing_block_generator { | ||
|
||
/** | ||
* Creates and returns a quickmail log (aka "sent message") record with the given data points. | ||
* | ||
* @param stdClass $user The message sender. | ||
* @param stdClass $course The course that this message was sent in. | ||
* @param array $recipients A list of user records that are recipients of this message. | ||
* @param stdClass|null $alternateemail An alternate email to be used as sender. | ||
* @param string|null $subject The message subject. | ||
* @param string|null $message The message contents. | ||
* @param string|null $attachment A comma-separated list of attachment names. | ||
* @param int|null $format The message format. | ||
* @param int|null $timesent The timestamp of when the message was sent. | ||
* @param string|null $faileduserids A comma-separated list of user IDs where message delivery failed. | ||
* @param string|null $additionalemails A comma-separated list of emails that this message was sent to. | ||
* @return stdClass The log record. | ||
* @throws dml_exception | ||
*/ | ||
public function create_quickmail_log( | ||
stdClass $user, | ||
stdClass $course, | ||
array $recipients, | ||
?stdClass $alternateemail = null, | ||
?string $subject = null, | ||
?string $message = null, | ||
?string $attachment = null, | ||
?int $format = null, | ||
?int $timesent = null, | ||
?string $faileduserids = null, | ||
?string $additionalemails = null, | ||
): stdClass { | ||
global $DB; | ||
|
||
$record = []; | ||
$record['courseid'] = $course->id; | ||
$record['userid'] = $user->id; | ||
$record['alternateemail'] = $alternateemail ?? null; | ||
$recipientids = []; | ||
foreach ($recipients as $recipient) { | ||
$recipientids[] = $recipient->id; | ||
} | ||
$record['mailto'] = implode(',', $recipientids); | ||
$record['subject'] = $subject ?? 'test subject'; | ||
$record['message'] = $message ?? 'test message'; | ||
$record['attachment'] = $attachment ?? ''; | ||
$record['format'] = $format ?? 0; | ||
$record['time'] = $timesent ?? time(); | ||
$record['faileduserids'] = $faileduserids ?? ''; | ||
$record['additional_emails'] = $additionalemails ?? ''; | ||
|
||
$id = $DB->insert_record('block_quickmail_log', $record); | ||
return $DB->get_record('block_quickmail_log', ['id' => $id]); | ||
} | ||
|
||
/** | ||
* Creates a quickmail draft (aka "message draft") record with the given data points. | ||
* @param stdClass $user The message sender. | ||
* @param stdClass $course The course that this message will be sent in. | ||
* @return stdClass The draft record. | ||
*/ | ||
public function create_quickmail_draft(stdClass $user, stdClass $course): stdClass { | ||
// Todo: Implement. [ST 2024/06/07]. | ||
return new stdClass(); | ||
} | ||
|
||
/** | ||
* Creates a quickmail alternate email record for the given user. | ||
* @param stdClass $user The alternate email owner. | ||
* @return stdClass The alternate email record. | ||
*/ | ||
public function create_quickmail_alternate_email(stdClass $user): stdClass { | ||
// Todo: Implement. [ST 2024/06/07]. | ||
return new stdClass(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?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/>. | ||
|
||
/** | ||
* Test coverage for Quickmail block data generator. | ||
* | ||
* @package block_quickmail | ||
* @copyright The Regents of the University of California | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace block_quickmail; | ||
|
||
use advanced_testcase; | ||
|
||
/** | ||
* Quickmail block data generator testcase. | ||
* | ||
* @package block_quickmail | ||
* @copyright The Regents of the University of California | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
* @covers \block_quickmail_generator | ||
*/ | ||
final class generator_test extends advanced_testcase { | ||
/** | ||
* Tests quickmail log record generator. | ||
*/ | ||
public function test_create_quickmail_log(): void { | ||
// Todo: implement. [ST 2024/06/07]. | ||
$this->markTestIncomplete('to be implemented'); | ||
} | ||
|
||
/** | ||
* Tests quickmail draft record generator. | ||
*/ | ||
public function test_create_quickmail_draft(): void { | ||
// Todo: implement. [ST 2024/06/07]. | ||
$this->markTestIncomplete('to be implemented'); | ||
} | ||
|
||
/** | ||
* Tests quickmail alternate email record record generator. | ||
*/ | ||
public function test_create_quickmail_alternate_email(): void { | ||
// Todo: implement. [ST 2024/06/07]. | ||
$this->markTestIncomplete('to be implemented'); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
<?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/>. | ||
|
||
/** | ||
* Privacy provider tests for block_quickmail. | ||
* | ||
* @package block_quickmail | ||
* @copyright The Regents of the University of California | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
namespace block_quickmail\privacy; | ||
|
||
use coding_exception; | ||
use context_system; | ||
use context_user; | ||
use core_privacy\local\metadata\collection; | ||
use core_privacy\local\request\approved_contextlist; | ||
use core_privacy\local\request\approved_userlist; | ||
use core_privacy\local\request\userlist; | ||
use core_privacy\local\request\writer; | ||
use core_privacy\tests\provider_testcase; | ||
use dml_exception; | ||
|
||
/** | ||
* Privacy provider test case. | ||
* | ||
* @package block_quickmail | ||
* @copyright The Regents of the University of California | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
* @covers \block_quickmail\privacy\provider | ||
*/ | ||
final class provider_test extends provider_testcase { | ||
|
||
|
||
/** | ||
* Test getting the context for the user ID related to this plugin. | ||
* @throws dml_exception | ||
*/ | ||
public function test_get_contexts_for_userid(): void { | ||
global $DB; | ||
$this->resetAfterTest(); | ||
$generator = $this->getDataGenerator(); | ||
$quickmailgenerator = $this->getDataGenerator()->get_plugin_generator('block_quickmail'); | ||
|
||
// Create four users and a course. | ||
$user1 = $generator->create_user(); | ||
$usercontext1 = context_user::instance($user1->id); | ||
$user2 = $generator->create_user(); | ||
$usercontext2 = context_user::instance($user2->id); | ||
$user3 = $generator->create_user(); | ||
$usercontext3 = context_user::instance($user3->id); | ||
$user4 = $generator->create_user(); | ||
$usercontext4 = context_user::instance($user4->id); | ||
|
||
$course = $generator->create_course(); | ||
|
||
// No contexts returned before user-specific block configurations are applied. | ||
$contextlist1 = provider::get_contexts_for_userid($user1->id); | ||
$this->assertCount(0, $contextlist1); | ||
$contextlist2 = provider::get_contexts_for_userid($user2->id); | ||
$this->assertCount(0, $contextlist2); | ||
|
||
// Create some quickmail data points for all users. | ||
$log1 = $quickmailgenerator->create_quickmail_log($user1, $course, [$user2]); | ||
// Todo: add more test vectors here for the other users [ST 2024/06/07]. | ||
|
||
// Ensure provider only fetches the user's own context. | ||
$contextlist1 = provider::get_contexts_for_userid($user1->id); | ||
$this->assertCount(1, $contextlist1); | ||
$this->assertEquals($usercontext1, $contextlist1->current()); | ||
// Todo: check the other user contexts [ST 2024/06/07]. | ||
} | ||
|
||
/** | ||
* Test getting users in the context ID related to this plugin. | ||
*/ | ||
public function test_get_users_in_context(): void { | ||
// Todo: implement. [ST 2024/06/07]. | ||
$this->markTestIncomplete('to be implemented'); | ||
} | ||
|
||
/** | ||
* Test fetching information about user data stored. | ||
*/ | ||
public function test_get_metadata(): void { | ||
// Todo: implement. [ST 2024/06/07]. | ||
$this->markTestIncomplete('to be implemented'); | ||
} | ||
|
||
/** | ||
* Test exporting data for an approved contextlist. | ||
*/ | ||
public function test_export_user_data(): void { | ||
// Todo: implement. [ST 2024/06/07]. | ||
$this->markTestIncomplete('to be implemented'); | ||
} | ||
|
||
/** | ||
* Test deleting data for all users within an approved contextlist. | ||
*/ | ||
public function test_delete_data_for_all_users_in_context(): void { | ||
// Todo: implement. [ST 2024/06/07]. | ||
$this->markTestIncomplete('to be implemented'); | ||
} | ||
|
||
/** | ||
* Test deleting data within an approved contextlist for a user. | ||
*/ | ||
public function test_delete_data_for_user(): void { | ||
// Todo: implement. [ST 2024/06/07]. | ||
$this->markTestIncomplete('to be implemented'); | ||
} | ||
|
||
/** | ||
* Test deleting data within a context for an approved userlist. | ||
*/ | ||
public function test_delete_data_for_users(): void { | ||
// Todo: implement. [ST 2024/06/07]. | ||
$this->markTestIncomplete('to be implemented'); | ||
} | ||
} |