-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from waleedhassan5/aws_suppression_list
Task tool_emailutils\task\update_suppression_list should gracefully fail #53
- Loading branch information
Showing
4 changed files
with
153 additions
and
69 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
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
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
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 |
---|---|---|
|
@@ -35,24 +35,17 @@ | |
final class suppressionlist_test extends \advanced_testcase { | ||
|
||
/** | ||
* Test the update of the suppression list and the generation of the CSV file. | ||
* | ||
* This test checks the following: | ||
* 1. The suppression list is properly updated in the database from the mock AWS SES response. | ||
* 2. The correct number of records (2 in this case) is added to the suppression table. | ||
* 3. Each record has the correct email and reason as per the mock data. | ||
* 4. A CSV file is generated with the correct headers and content matching the database. | ||
* Set up the test environment and return a configured task. | ||
* | ||
* @covers \tool_emailutils\task\update_suppression_list::execute | ||
* @covers \tool_emailutils\suppression_list::generate_csv | ||
* | ||
* @return void | ||
* @param bool $enablefeature Whether to enable the suppression list feature. | ||
* @return \tool_emailutils\task\update_suppression_list | ||
*/ | ||
public function test_suppression_list_update_and_export(): void { | ||
global $DB; | ||
|
||
protected function setup_test_environment(bool $enablefeature): \tool_emailutils\task\update_suppression_list { | ||
$this->resetAfterTest(true); | ||
|
||
// Set the suppression list feature configuration. | ||
set_config('enable_suppression_list', $enablefeature ? 1 : 0, 'tool_emailutils'); | ||
|
||
// Set up a user with necessary permissions. | ||
$this->setAdminUser(); | ||
|
||
|
@@ -83,8 +76,36 @@ public function test_suppression_list_update_and_export(): void { | |
$task = new \tool_emailutils\task\update_suppression_list(); | ||
$task->set_ses_client($mockclient); | ||
|
||
// Execute the task. | ||
return $task; | ||
} | ||
|
||
/** | ||
* Test the update of the suppression list and the generation of the CSV file. | ||
* | ||
* This test checks the following: | ||
* 1. The suppression list is properly updated in the database from the mock AWS SES response. | ||
* 2. The correct number of records (2 in this case) is added to the suppression table. | ||
* 3. Each record has the correct email and reason as per the mock data. | ||
* 4. A CSV file is generated with the correct headers and content matching the database. | ||
* | ||
* @covers \tool_emailutils\task\update_suppression_list::execute | ||
* @covers \tool_emailutils\suppression_list::generate_csv | ||
* | ||
* @return void | ||
* @throws \dml_exception | ||
*/ | ||
public function test_suppression_list_update_and_export(): void { | ||
global $DB; | ||
|
||
$task = $this->setup_test_environment(true); | ||
|
||
// Capture the output. | ||
ob_start(); | ||
$task->execute(); | ||
$output = ob_get_clean(); | ||
|
||
// Assert that the expected string is in the output. | ||
$this->assertStringContainsString('Suppression list updated successfully.', $output); | ||
|
||
// Verify that the suppression list was updated in the database. | ||
$records = $DB->get_records('tool_emailutils_suppression'); | ||
|
@@ -116,4 +137,32 @@ public function test_suppression_list_update_and_export(): void { | |
$this->assertStringContainsString('[email protected]', $lines[2]); | ||
$this->assertStringContainsString('COMPLAINT', $lines[2]); | ||
} | ||
|
||
/** | ||
* Test the update of the suppression list when the feature is disabled. | ||
* | ||
* This test checks the following: | ||
* 1. The suppression list is not updated in the database. | ||
* 2. The suppression list table is empty. | ||
* | ||
* @return void | ||
* @throws \dml_exception | ||
*/ | ||
public function test_suppression_list_update_when_disabled(): void { | ||
global $DB; | ||
|
||
$task = $this->setup_test_environment(false); | ||
|
||
// Capture the output. | ||
ob_start(); | ||
$task->execute(); | ||
$output = ob_get_clean(); | ||
|
||
// Assert that there is no output. | ||
$this->assertEmpty($output); | ||
|
||
// Verify that the suppression list table is empty. | ||
$records = $DB->get_records('tool_emailutils_suppression'); | ||
$this->assertEmpty($records); | ||
} | ||
} |