Proyectos de Subversion Moodle

Rev

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

Rev 11 Rev 1441
Línea 36... Línea 36...
36
 * @package    enrol_manual
36
 * @package    enrol_manual
37
 * @category   phpunit
37
 * @category   phpunit
38
 * @copyright  2012 Petr Skoda {@link http://skodak.org}
38
 * @copyright  2012 Petr Skoda {@link http://skodak.org}
39
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40
 */
40
 */
41
class lib_test extends \advanced_testcase {
41
final class lib_test extends \advanced_testcase {
42
    /**
42
    /**
43
     * Test enrol migration function used when uninstalling enrol plugins.
43
     * Test enrol migration function used when uninstalling enrol plugins.
44
     */
44
     */
45
    public function test_migrate_plugin_enrolments(): void {
45
    public function test_migrate_plugin_enrolments(): void {
46
        global $DB, $CFG;
46
        global $DB, $CFG;
Línea 584... Línea 584...
584
    /**
584
    /**
585
     * Data provider for test_default_enrolment_instance_acquires_correct_settings().
585
     * Data provider for test_default_enrolment_instance_acquires_correct_settings().
586
     *
586
     *
587
     * @return array
587
     * @return array
588
     */
588
     */
589
    public function default_enrolment_instance_data_provider(): array {
589
    public static function default_enrolment_instance_data_provider(): array {
590
        $studentroles = get_archetype_roles('student');
590
        $studentroles = get_archetype_roles('student');
591
        $studentrole = array_shift($studentroles);
591
        $studentrole = array_shift($studentroles);
Línea 592... Línea 592...
592
 
592
 
593
        $teacherroles = get_archetype_roles('teacher');
593
        $teacherroles = get_archetype_roles('teacher');
Línea 601... Línea 601...
601
                    'enrolperiod' => 0,
601
                    'enrolperiod' => 0,
602
                    'expirynotify' => 0,
602
                    'expirynotify' => 0,
603
                    'notifyall' => 0,
603
                    'notifyall' => 0,
604
                    'expirythreshold' => 12 * HOURSECS,
604
                    'expirythreshold' => 12 * HOURSECS,
605
                ],
605
                ],
606
                'global settings' => (object) [
606
                'globalsettings' => (object) [
607
                    'status' => ENROL_INSTANCE_ENABLED,
607
                    'status' => ENROL_INSTANCE_ENABLED,
608
                    'roleid' => $studentrole->id,
608
                    'roleid' => $studentrole->id,
609
                    'enrolperiod' => 0,
609
                    'enrolperiod' => 0,
610
                    'expirynotify' => 0,
610
                    'expirynotify' => 0,
611
                    'expirythreshold' => 12 * HOURSECS,
611
                    'expirythreshold' => 12 * HOURSECS,
Línea 618... Línea 618...
618
                    'enrolperiod' => 72 * HOURSECS,
618
                    'enrolperiod' => 72 * HOURSECS,
619
                    'expirynotify' => 1,
619
                    'expirynotify' => 1,
620
                    'notifyall' => 0,
620
                    'notifyall' => 0,
621
                    'expirythreshold' => DAYSECS,
621
                    'expirythreshold' => DAYSECS,
622
                ],
622
                ],
623
                'global settings' => (object) [
623
                'globalsettings' => (object) [
624
                    'status' => ENROL_INSTANCE_ENABLED,
624
                    'status' => ENROL_INSTANCE_ENABLED,
625
                    'roleid' => $studentrole->id,
625
                    'roleid' => $studentrole->id,
626
                    'enrolperiod' => 72 * HOURSECS,
626
                    'enrolperiod' => 72 * HOURSECS,
627
                    'expirynotify' => 1,
627
                    'expirynotify' => 1,
628
                    'expirythreshold' => DAYSECS,
628
                    'expirythreshold' => DAYSECS,
Línea 635... Línea 635...
635
                    'enrolperiod' => 0,
635
                    'enrolperiod' => 0,
636
                    'expirynotify' => 2,
636
                    'expirynotify' => 2,
637
                    'notifyall' => 1,
637
                    'notifyall' => 1,
638
                    'expirythreshold' => 0
638
                    'expirythreshold' => 0
639
                ],
639
                ],
640
                'global settings' => (object) [
640
                'globalsettings' => (object) [
641
                    'status' => ENROL_INSTANCE_DISABLED,
641
                    'status' => ENROL_INSTANCE_DISABLED,
642
                    'roleid' => $teacherrole->id,
642
                    'roleid' => $teacherrole->id,
643
                    'enrolperiod' => 0,
643
                    'enrolperiod' => 0,
644
                    'expirynotify' => 2,
644
                    'expirynotify' => 2,
645
                    'expirythreshold' => 0,
645
                    'expirythreshold' => 0,
Línea 698... Línea 698...
698
    /**
698
    /**
699
     * Data provider for test_enrolment_instance_is_updated().
699
     * Data provider for test_enrolment_instance_is_updated().
700
     *
700
     *
701
     * @return array
701
     * @return array
702
     */
702
     */
703
    public function update_enrolment_instance_data_provider(): array {
703
    public static function update_enrolment_instance_data_provider(): array {
704
        $studentroles = get_archetype_roles('student');
704
        $studentroles = get_archetype_roles('student');
705
        $studentrole = array_shift($studentroles);
705
        $studentrole = array_shift($studentroles);
Línea 706... Línea 706...
706
 
706
 
707
        $teacherroles = get_archetype_roles('teacher');
707
        $teacherroles = get_archetype_roles('teacher');
Línea 715... Línea 715...
715
                    'enrolperiod' => 30 * DAYSECS,
715
                    'enrolperiod' => 30 * DAYSECS,
716
                    'expirynotify' => 1,
716
                    'expirynotify' => 1,
717
                    'notifyall' => 0,
717
                    'notifyall' => 0,
718
                    'expirythreshold' => 2 * DAYSECS,
718
                    'expirythreshold' => 2 * DAYSECS,
719
                ],
719
                ],
720
                'update data' => (object) [
720
                'updatedata' => (object) [
721
                    'status' => ENROL_INSTANCE_DISABLED,
721
                    'status' => ENROL_INSTANCE_DISABLED,
722
                    'roleid' => $studentrole->id,
722
                    'roleid' => $studentrole->id,
723
                    'enrolperiod' => 30 * DAYSECS,
723
                    'enrolperiod' => 30 * DAYSECS,
724
                    'expirynotify' => 1,
724
                    'expirynotify' => 1,
725
                    'expirythreshold' => 2 * DAYSECS,
725
                    'expirythreshold' => 2 * DAYSECS,
Línea 732... Línea 732...
732
                    'enrolperiod' => 0,
732
                    'enrolperiod' => 0,
733
                    'expirynotify' => 0,
733
                    'expirynotify' => 0,
734
                    'notifyall' => 0,
734
                    'notifyall' => 0,
735
                    'expirythreshold' => 0,
735
                    'expirythreshold' => 0,
736
                ],
736
                ],
737
                'update data' => (object) [
737
                'updatedata' => (object) [
738
                    'status' => ENROL_INSTANCE_ENABLED,
738
                    'status' => ENROL_INSTANCE_ENABLED,
739
                    'roleid' => $teacherrole->id,
739
                    'roleid' => $teacherrole->id,
740
                    'enrolperiod' => 0,
740
                    'enrolperiod' => 0,
741
                    'expirynotify' => 0,
741
                    'expirynotify' => 0,
742
                    'expirythreshold' => 0,
742
                    'expirythreshold' => 0,
Línea 749... Línea 749...
749
                    'enrolperiod' => 30 * DAYSECS,
749
                    'enrolperiod' => 30 * DAYSECS,
750
                    'expirynotify' => 2,
750
                    'expirynotify' => 2,
751
                    'notifyall' => 1,
751
                    'notifyall' => 1,
752
                    'expirythreshold' => 2 * DAYSECS,
752
                    'expirythreshold' => 2 * DAYSECS,
753
                ],
753
                ],
754
                'update data' => (object) [
754
                'updatedata' => (object) [
755
                    'status' => ENROL_INSTANCE_ENABLED,
755
                    'status' => ENROL_INSTANCE_ENABLED,
756
                    'roleid' => $studentrole->id,
756
                    'roleid' => $studentrole->id,
757
                    'enrolperiod' => 30 * DAYSECS,
757
                    'enrolperiod' => 30 * DAYSECS,
758
                    'expirynotify' => 2,
758
                    'expirynotify' => 2,
759
                    'expirythreshold' => 2 * DAYSECS,
759
                    'expirythreshold' => 2 * DAYSECS,
Línea 801... Línea 801...
801
        // Create course.
801
        // Create course.
802
        $course = $this->getDataGenerator()->create_course([
802
        $course = $this->getDataGenerator()->create_course([
803
            'fullname' => 'Course 1 & 2',
803
            'fullname' => 'Course 1 & 2',
804
            'shortname' => 'C1',
804
            'shortname' => 'C1',
805
        ]);
805
        ]);
-
 
806
        $courseurl = course_get_url($course)->out();
-
 
807
 
806
        // Create users.
808
        // Create users.
807
        $student = $this->getDataGenerator()->create_user();
809
        $student = $this->getDataGenerator()->create_user();
808
        $teacher1 = $this->getDataGenerator()->create_user();
810
        $teacher1 = $this->getDataGenerator()->create_user();
809
        $teacher2 = $this->getDataGenerator()->create_user();
811
        $teacher2 = $this->getDataGenerator()->create_user();
810
        $noreplyuser = \core_user::get_noreply_user();
812
        $noreplyuser = \core_user::get_noreply_user();
Línea 841... Línea 843...
841
        $this->assertStringContainsString($course->fullname, $message->subject);
843
        $this->assertStringContainsString($course->fullname, $message->subject);
842
        $this->assertEquals(
844
        $this->assertEquals(
843
            get_string(
845
            get_string(
844
                'customwelcomemessageplaceholder',
846
                'customwelcomemessageplaceholder',
845
                'core_enrol',
847
                'core_enrol',
846
                ['fullname' => fullname($student), 'coursename' => $course->fullname],
848
                ['firstname' => $student->firstname, 'coursename' => $course->fullname],
847
            ),
849
            ),
848
            $message->fullmessage,
850
            $message->fullmessage,
849
        );
851
        );
Línea 850... Línea 852...
850
 
852
 
Línea 886... Línea 888...
886
        $messagesink = $this->redirectMessages();
888
        $messagesink = $this->redirectMessages();
887
        $manualplugin->send_course_welcome_message_to_user(
889
        $manualplugin->send_course_welcome_message_to_user(
888
            instance: $maninstance,
890
            instance: $maninstance,
889
            userid: $student->id,
891
            userid: $student->id,
890
            sendoption: ENROL_SEND_EMAIL_FROM_NOREPLY,
892
            sendoption: ENROL_SEND_EMAIL_FROM_NOREPLY,
891
            message: 'Your email address: {$a->email}, your first name: {$a->firstname}, your last name: {$a->lastname}',
893
            message: 'Welcome to <a href="{$a->courselink}">{$a->coursename}</a>',
892
        );
894
        );
893
        $messages = $messagesink->get_messages_by_component_and_type(
895
        $messages = $messagesink->get_messages_by_component_and_type(
894
            'moodle',
896
            'moodle',
895
            'enrolcoursewelcomemessage',
897
            'enrolcoursewelcomemessage',
896
        );
898
        );
Línea 899... Línea 901...
899
 
901
 
900
        // The message should be sent from the noreply user.
902
        // The message should be sent from the noreply user.
901
        $this->assertEquals($noreplyuser->id, $message->useridfrom);
903
        $this->assertEquals($noreplyuser->id, $message->useridfrom);
902
        $this->assertStringContainsString($course->fullname, $message->subject);
904
        $this->assertStringContainsString($course->fullname, $message->subject);
903
        $this->assertEquals(
905
        $this->assertEquals(
904
            'Your email address: ' . $student->email . ', your first name: ' . $student->firstname . ', your last name: ' .
-
 
905
            $student->lastname,
906
            "Welcome to <a href=\"{$courseurl}\">" . htmlentities($course->fullname) . "</a>",
906
            $message->fullmessage,
907
            $message->fullmessagehtml,
907
        );
908
        );
908
        // Clear sink.
909
        // Clear sink.
Línea 909... Línea 910...
909
        $messagesink->clear();
910
        $messagesink->clear();