-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into bugfix/settingsreset
- Loading branch information
Showing
6 changed files
with
81 additions
and
33 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
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 |
---|---|---|
|
@@ -59,6 +59,9 @@ class dailymail_test extends \advanced_testcase { | |
/** @var \stdClass discussion instance */ | ||
private $discussion; | ||
|
||
/** @var moodleoverflow generator */ | ||
private $generator; | ||
|
||
/** | ||
* Test setUp. | ||
*/ | ||
|
@@ -94,12 +97,13 @@ public function tearDown(): void { | |
*/ | ||
public function helper_create_user_and_discussion($maildigest) { | ||
// Create a user enrolled in the course as student. | ||
$this->user = $this->getDataGenerator()->create_user(['firstname' => 'Tamaro', 'maildigest' => $maildigest]); | ||
$this->user = $this->getDataGenerator()->create_user(['firstname' => 'Tamaro', 'email' => '[email protected]', | ||
'maildigest' => $maildigest]); | ||
$this->getDataGenerator()->enrol_user($this->user->id, $this->course->id, 'student'); | ||
|
||
// Create a new discussion and post within the moodleoverflow. | ||
$generator = $this->getDataGenerator()->get_plugin_generator('mod_moodleoverflow'); | ||
$this->discussion = $generator->post_to_forum($this->moodleoverflow, $this->user); | ||
$this->generator = $this->getDataGenerator()->get_plugin_generator('mod_moodleoverflow'); | ||
$this->discussion = $this->generator->post_to_forum($this->moodleoverflow, $this->user); | ||
} | ||
|
||
/** | ||
|
@@ -137,7 +141,6 @@ private function helper_run_send_mails() { | |
* @covers \send_daily_mail::execute | ||
*/ | ||
public function test_mail_delivery(): void { | ||
|
||
// Create user with maildigest = on. | ||
$this->helper_create_user_and_discussion('1'); | ||
|
||
|
@@ -149,6 +152,52 @@ public function test_mail_delivery(): void { | |
$this->assertEquals(1, $messages); | ||
} | ||
|
||
/** | ||
* Test if the task send_daily_mail does not sends email from posts that are not in the course of the user. | ||
* @return void | ||
*/ | ||
public function test_delivery_not_enrolled(): void { | ||
// Create user with maildigest = on. | ||
$this->helper_create_user_and_discussion('1'); | ||
|
||
// Create another user, course and a moodleoverflow post. | ||
$course = $this->getDataGenerator()->create_course(); | ||
$location = ['course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_FORCESUBSCRIBE]; | ||
$moodleoverflow = $this->getDataGenerator()->create_module('moodleoverflow', $location); | ||
$student = $this->getDataGenerator()->create_user(['firstname' => 'Ethan', 'email' => '[email protected]', | ||
'maildigest' => '1']); | ||
$this->getDataGenerator()->enrol_user($student->id, $course->id, 'teacher'); | ||
$discussion = $this->generator->post_to_forum($moodleoverflow, $student); | ||
|
||
// Send the mails. | ||
$this->helper_run_send_mails(); | ||
$this->helper_run_send_daily_mail(); | ||
$messages = $this->sink->count(); | ||
$content = $this->sink->get_messages(); | ||
|
||
// There should be 2 mails. | ||
$this->assertEquals(2, $messages); | ||
|
||
// Check the recipient of the mails and the discussion that is addressed. There should be no false addressed discussions. | ||
$firstmail = $content[0]; | ||
$secondmail = $content[1]; | ||
// Depending on the order of the mails, check the recipient and the discussion that is addressed. | ||
if ($firstmail->to == "[email protected]") { | ||
$this->assertStringContainsString($this->discussion[0]->name, $firstmail->body); | ||
$this->assertStringNotContainsString($discussion[0]->name, $firstmail->body); | ||
$this->assertEquals('[email protected]', $secondmail->to); | ||
$this->assertStringContainsString($discussion[0]->name, $secondmail->body); | ||
$this->assertStringNotContainsString($this->discussion[0]->name, $secondmail->body); | ||
} else { | ||
$this->assertEquals('[email protected]', $firstmail->to); | ||
$this->assertStringContainsString($discussion[0]->name, $firstmail->body); | ||
$this->assertStringNotContainsString($this->discussion[0]->name, $firstmail->body); | ||
$this->assertEquals('[email protected]', $secondmail->to); | ||
$this->assertStringContainsString($this->discussion[0]->name, $secondmail->body); | ||
$this->assertStringNotContainsString($discussion[0]->name, $secondmail->body); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Test if the content of the mail matches the supposed content. | ||
|