Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 33... Línea 33...
33
 * @category   test
33
 * @category   test
34
 * @copyright  2013 Andrew Nicols
34
 * @copyright  2013 Andrew Nicols
35
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36
 *
36
 *
37
 */
37
 */
38
class mail_test extends \advanced_testcase {
38
final class mail_test extends \advanced_testcase {
39
    // Make use of the cron tester trait.
39
    // Make use of the cron tester trait.
40
    use mod_forum_tests_cron_trait;
40
    use mod_forum_tests_cron_trait;
Línea 41... Línea 41...
41
 
41
 
42
    // Make use of the test generator trait.
42
    // Make use of the test generator trait.
Línea 55... Línea 55...
55
    /** @var \phpunit_event_sink */
55
    /** @var \phpunit_event_sink */
56
    protected $eventsink;
56
    protected $eventsink;
Línea 57... Línea 57...
57
 
57
 
58
    public function setUp(): void {
58
    public function setUp(): void {
-
 
59
        global $CFG;
Línea 59... Línea 60...
59
        global $CFG;
60
        parent::setUp();
60
 
61
 
61
        // We must clear the subscription caches. This has to be done both before each test, and after in case of other
62
        // We must clear the subscription caches. This has to be done both before each test, and after in case of other
62
        // tests using these functions.
63
        // tests using these functions.
Línea 85... Línea 86...
85
        unset($this->messagesink);
86
        unset($this->messagesink);
Línea 86... Línea 87...
86
 
87
 
87
        $this->mailsink->clear();
88
        $this->mailsink->clear();
88
        $this->mailsink->close();
89
        $this->mailsink->close();
-
 
90
        unset($this->mailsink);
89
        unset($this->mailsink);
91
        parent::tearDown();
Línea 90... Línea 92...
90
    }
92
    }
91
 
93
 
92
    /**
94
    /**
Línea 932... Línea 934...
932
        $this->assertEquals($author->id, $message->useridfrom);
934
        $this->assertEquals($author->id, $message->useridfrom);
933
        $this->assertEquals($expectedsubject, $message->subject);
935
        $this->assertEquals($expectedsubject, $message->subject);
934
    }
936
    }
Línea 935... Línea 937...
935
 
937
 
936
    /**
-
 
937
     * Test inital email and reply email subjects
-
 
938
     */
-
 
939
    public function test_subjects(): void {
-
 
940
        $this->resetAfterTest(true);
-
 
941
 
-
 
942
        $course = $this->getDataGenerator()->create_course();
-
 
943
 
-
 
944
        $options = array('course' => $course->id, 'forcesubscribe' => FORUM_FORCESUBSCRIBE);
-
 
945
        $forum = $this->getDataGenerator()->create_module('forum', $options);
-
 
946
 
-
 
947
        list($author) = $this->helper_create_users($course, 1);
-
 
948
        list($commenter) = $this->helper_create_users($course, 1);
-
 
949
 
-
 
950
        $strre = get_string('re', 'forum');
-
 
951
 
-
 
952
        // New posts should not have Re: in the subject.
-
 
953
        list($discussion, $post) = $this->helper_post_to_forum($forum, $author);
-
 
954
        $expect = [
-
 
955
            'author' => (object) [
-
 
956
                'userid' => $author->id,
-
 
957
                'messages' => 1,
-
 
958
            ],
-
 
959
            'commenter' => (object) [
-
 
960
                'userid' => $commenter->id,
-
 
961
                'messages' => 1,
-
 
962
            ],
-
 
963
        ];
-
 
964
        $this->queue_tasks_and_assert($expect);
-
 
965
 
-
 
966
        $this->send_notifications_and_assert($author, [$post]);
-
 
967
        $this->send_notifications_and_assert($commenter, [$post]);
-
 
968
        $messages = $this->messagesink->get_messages();
-
 
969
        $this->assertStringNotContainsString($strre, $messages[0]->subject);
-
 
970
        $this->messagesink->clear();
-
 
971
 
-
 
972
        // Replies should have Re: in the subject.
-
 
973
        $reply = $this->helper_post_to_discussion($forum, $discussion, $commenter);
-
 
974
 
-
 
975
        $expect = [
-
 
976
            'author' => (object) [
-
 
977
                'userid' => $author->id,
-
 
978
                'messages' => 1,
-
 
979
            ],
-
 
980
            'commenter' => (object) [
-
 
981
                'userid' => $commenter->id,
-
 
982
                'messages' => 1,
-
 
983
            ],
-
 
984
        ];
-
 
985
        $this->queue_tasks_and_assert($expect);
-
 
986
 
-
 
987
        $this->send_notifications_and_assert($commenter, [$reply]);
-
 
988
        $this->send_notifications_and_assert($author, [$reply]);
-
 
989
        $messages = $this->messagesink->get_messages();
-
 
990
        $this->assertStringContainsString($strre, $messages[0]->subject);
-
 
991
        $this->assertStringContainsString($strre, $messages[1]->subject);
-
 
992
    }
-
 
993
 
-
 
994
    /**
938
    /**
995
     * dataProvider for test_forum_post_email_templates().
939
     * dataProvider for test_forum_post_email_templates().
996
     */
940
     */
997
    public function forum_post_email_templates_provider() {
941
    public static function forum_post_email_templates_provider(): array {
998
        // Base information, we'll build variations based on it.
942
        // Base information, we'll build variations based on it.
999
        $base = array(
943
        $base = array(
1000
            'user' => array('firstname' => 'Love', 'lastname' => 'Moodle', 'mailformat' => 0, 'maildigest' => 0),
944
            'user' => array('firstname' => 'Love', 'lastname' => 'Moodle', 'mailformat' => 0, 'maildigest' => 0),
1001
            'course' => array('shortname' => '101', 'fullname' => 'Moodle 101'),
945
            'course' => array('shortname' => '101', 'fullname' => 'Moodle 101'),
Línea 1580... Línea 1524...
1580
        $forum = $this->getDataGenerator()->create_module('forum', $options);
1524
        $forum = $this->getDataGenerator()->create_module('forum', $options);
Línea 1581... Línea 1525...
1581
 
1525
 
1582
        list($author) = $this->helper_create_users($course, 1);
1526
        list($author) = $this->helper_create_users($course, 1);
Línea 1583... Línea -...
1583
        list($commenter) = $this->helper_create_users($course, 1);
-
 
1584
 
-
 
1585
        $strre = get_string('re', 'forum');
1527
        list($commenter) = $this->helper_create_users($course, 1);
1586
 
1528
 
1587
        // New posts should not have Re: in the subject.
1529
        // New posts should not have Re: in the subject.
1588
        list($discussion, $post) = $this->helper_post_to_forum($forum, $author);
1530
        list($discussion, $post) = $this->helper_post_to_forum($forum, $author);
1589
        $expect = [
1531
        $expect = [