Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/settingsreset
Browse files Browse the repository at this point in the history
  • Loading branch information
TamaroWalter authored May 23, 2024
2 parents e2f8e2c + 0bc711c commit f7cdb4a
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 33 deletions.
32 changes: 13 additions & 19 deletions .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ jobs:

strategy:
matrix:
php: ['8.1']
moodle-branch: ['MOODLE_402_STABLE']
php: ['8.2']
moodle-branch: ['MOODLE_403_STABLE']
database: ['pgsql']

steps:
Expand Down Expand Up @@ -110,27 +110,21 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['8.0', '8.1']
moodle-branch: ['MOODLE_401_STABLE', 'MOODLE_402_STABLE']
php: [8.1']
moodle-branch: ['MOODLE_401_STABLE', 'MOODLE_402_STABLE', 'MOODLE_403_STABLE']
database: ['mariadb', 'pgsql']
include:
- php: '7.4'
moodle-branch: 'MOODLE_39_STABLE'
- php: '8.2'
moodle-branch: 'MOODLE_402_STABLE'
database: 'mariadb'
- php: '7.4'
moodle-branch: 'MOODLE_39_STABLE'
- php: '8.2'
moodle-branch: 'MOODLE_402_STABLE'
database: 'pgsql'
- php: '8.0'
moodle-branch: 'MOODLE_311_STABLE'
- php: '8.2'
moodle-branch: 'MOODLE_403_STABLE'
database: 'mariadb'
- php: '8.0'
moodle-branch: 'MOODLE_311_STABLE'
database: 'pgsql'
- php: '8.0'
moodle-branch: 'MOODLE_400_STABLE'
database: 'mariadb'
- php: '8.0'
moodle-branch: 'MOODLE_400_STABLE'
- php: '8.2'
moodle-branch: 'MOODLE_403_STABLE'
database: 'pgsql'

steps:
Expand Down Expand Up @@ -193,4 +187,4 @@ jobs:

- name: Behat features
if: ${{ always() }}
run: moodle-plugin-ci behat --auto-rerun 0
run: moodle-plugin-ci behat --auto-rerun 0
11 changes: 8 additions & 3 deletions classes/task/send_daily_mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,13 @@ public function execute() {
$mail = [];
// Fill the $mail array.
foreach ($userdata as $row) {
$currentcourse = $DB->get_record('course', ['id' => $row->courseid], 'fullname, id');
$currentforum = $DB->get_record('moodleoverflow', ['id' => $row->forumid], 'name, id');
$currentcourse = $DB->get_record('course', array('id' => $row->courseid), 'fullname, id');
// Check if the user is enrolled in the course, if not, go to the next row.
if (!is_enrolled(\context_course::instance($row->courseid), $user->userid, '', true)) {
continue;
}

$currentforum = $DB->get_record('moodleoverflow', array('id' => $row->forumid), 'name, id');
$coursemoduleid = get_coursemodule_from_instance('moodleoverflow', $row->forumid);
$discussion = $DB->get_record('moodleoverflow_discussions', ['id' => $row->forumdiscussionid], 'name, id');
$unreadposts = $row->numberofposts;
Expand All @@ -77,7 +82,7 @@ public function execute() {
'linktoforum' => $linktoforum,
'linktodiscussion' => $linktodiscussion,
'unreadposts' => $unreadposts, ]);
array_push($mail, $string);
$mail[] = $string;
}
// Build the final message and send it to user. Then remove the sent records.
$message = implode('<br>', $mail);
Expand Down
10 changes: 5 additions & 5 deletions db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@
<TABLE NAME="moodleoverflow_mail_info" COMMENT="represent the content of the digest mail">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true"/>
<FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="true"/>
<FIELD NAME="forumid" TYPE="int" LENGTH="10" NOTNULL="true"/>
<FIELD NAME="forumdiscussionid" TYPE="int" LENGTH="10" NOTNULL="true"/>
<FIELD NAME="numberofposts" TYPE="int" LENGTH="10" NOTNULL="true"/>
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="forumid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="forumdiscussionid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="numberofposts" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
Expand Down
2 changes: 1 addition & 1 deletion tests/behat/add_moodleoverflow.feature
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Feature: Add moodleoverflow activities and discussions
And I log in as "teacher1"
And I am on "Course 1" course homepage
And I turn editing mode on
And I add a "Moodleoverflow" to section "1" and I fill the form with:
And I add a "moodleoverflow" activity to course "C1" section "1" and I fill the form with:
| Moodleoverflow name | Test moodleoverflow name |
| Description | Test forum description |
And I add a new discussion to "Test moodleoverflow name" moodleoverflow with:
Expand Down
2 changes: 1 addition & 1 deletion tests/behat/delete_file.feature
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Feature: Delete attachments
And I log in as "teacher1"
And I am on "Course 1" course homepage
And I turn editing mode on
And I add a "Moodleoverflow" to section "1" and I fill the form with:
And I add a "moodleoverflow" activity to course "C1" section "1" and I fill the form with:
| Moodleoverflow name | Test moodleoverflow name |
| Description | Test forum description |
And I add a new discussion to "Test moodleoverflow name" moodleoverflow with:
Expand Down
57 changes: 53 additions & 4 deletions tests/dailymail_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ class dailymail_test extends \advanced_testcase {
/** @var \stdClass discussion instance */
private $discussion;

/** @var moodleoverflow generator */
private $generator;

/**
* Test setUp.
*/
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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');

Expand All @@ -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.
Expand Down

0 comments on commit f7cdb4a

Please sign in to comment.