Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
/**
18
 * coursecompleted enrolment plugin bulk tests.
19
 *
20
 * @package   enrol_coursecompleted
21
 * @copyright 2017 eWallah (www.eWallah.net)
22
 * @author    Renaat Debleu <info@eWallah.net>
23
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
 
26
namespace enrol_coursecompleted;
27
 
28
use stdClass;
29
 
30
/**
31
 * coursecompleted enrolment plugin bulk tests.
32
 *
33
 * @package   enrol_coursecompleted
34
 * @copyright 2017 eWallah (www.eWallah.net)
35
 * @author    Renaat Debleu <info@eWallah.net>
36
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37
 * @coversDefaultClass \enrol_coursecompleted
38
 */
39
final class bulk_test extends \advanced_testcase {
40
    /**
41
     * Setup to ensure that forms and locallib are loaded.
42
     */
43
    public static function setUpBeforeClass(): void {
44
        global $CFG;
45
        require_once($CFG->libdir . '/formslib.php');
46
        require_once($CFG->dirroot . '/enrol/locallib.php');
47
    }
48
 
49
    /**
50
     * Tests initial setup.
51
     */
52
    protected function setUp(): void {
53
        global $CFG;
54
        $CFG->enablecompletion = true;
55
        $this->resetAfterTest(true);
56
        $enabled = enrol_get_plugins(true);
57
        $enabled['coursecompleted'] = true;
58
        set_config('enrol_plugins_enabled', implode(',', array_keys($enabled)));
59
    }
60
 
61
    /**
62
     * Test bulk delete.
63
     * @covers \enrol_coursecompleted\bulkdelete
64
     * @covers \enrol_coursecompleted\form\bulkdelete
65
     */
66
    public function test_bulk_delete(): void {
67
        global $DB;
68
        $generator = $this->getDataGenerator();
69
        $plugin = enrol_get_plugin('coursecompleted');
70
        $course1 = $generator->create_course(['shortname' => 'A1', 'enablecompletion' => 1]);
71
        $course2 = $generator->create_course(['shortname' => 'B1', 'enablecompletion' => 1]);
72
        $student = $generator->create_and_enrol($course2, 'student');
73
        $id = $plugin->add_instance($course1, ['customint1' => $course2->id, 'roleid' => 5, 'customint2' => 0]);
74
        $instance = $DB->get_record('enrol', ['id' => $id]);
75
        $plugin->enrol_user($instance, $student->id);
76
        $page = new \moodle_page();
77
        $manager = new \course_enrolment_manager($page, $course1);
78
        $operation = new bulkdelete($manager, $plugin);
79
        $this->assertEquals('deleteselectedusers', $operation->get_identifier());
80
        $this->assertEquals('Delete selected enrolments on course completion', $operation->get_title());
81
        $enr = new stdClass();
82
        $enr->status = true;
83
        $enr->enrolmentplugin = $plugin;
84
        $enr->enrolmentinstance = $instance;
85
        $user = new stdClass();
86
        $user->id = $student->id;
87
        $user->enrolments = [$enr];
88
        $properties = new stdClass();
89
        $properties->status = ENROL_USER_ACTIVE;
90
        $properties->timestart = 100;
91
        $properties->timeend = 1000;
92
        $this->assertfalse($operation->process($manager, [$user], new stdClass()));
93
        $this->setAdminUser();
94
        $this->assertTrue($operation->process($manager, [$user], $properties));
95
        $this->assertNotEmpty($operation->get_form(null, ['users' => [$user]]));
96
    }
97
 
98
    /**
99
     * Test bulk edit.
100
     * @covers \enrol_coursecompleted\bulkedit
101
     * @covers \enrol_coursecompleted\form\bulkedit
102
     */
103
    public function test_bulk_edit(): void {
104
        global $DB;
105
        $generator = $this->getDataGenerator();
106
        $plugin = enrol_get_plugin('coursecompleted');
107
        $course1 = $generator->create_course(['shortname' => 'c1', 'enablecompletion' => 1]);
108
        $course2 = $generator->create_course(['shortname' => 'd1', 'enablecompletion' => 1]);
109
        $studentid = $generator->create_and_enrol($course2, 'student')->id;
110
        $id = $plugin->add_instance($course1, ['customint1' => $course2->id, 'roleid' => 5]);
111
        $instance = $DB->get_record('enrol', ['id' => $id]);
112
        $plugin->enrol_user($instance, $studentid);
113
        $page = new \moodle_page();
114
        $manager = new \course_enrolment_manager($page, $course1);
115
        $operation = new bulkedit($manager, $plugin);
116
        $this->assertEquals('editselectedusers', $operation->get_identifier());
117
        $this->assertEquals('Edit selected enrolments on course completion', $operation->get_title());
118
        $enr = new stdClass();
119
        $enr->status = true;
120
        $enr->enrolmentinstance = $instance;
121
        $enr->instance = $instance;
122
        $enr->id = $id;
123
        $user = new stdClass();
124
        $user->id = $studentid;
125
        $user->enrolments = [$enr];
126
        $properties = new stdClass();
127
        $properties->status = 1;
128
        $properties->timestart = time() - 100;
129
        $properties->timeend = time() + 1000;
130
        $this->assertfalse($operation->process($manager, [$user], $properties));
131
        $this->setAdminUser();
132
        $this->assertTrue($operation->process($manager, [$user], $properties));
133
        $properties->status = 99;
134
        $properties->timestart = null;
135
        $properties->timeend = null;
136
        $this->assertTrue($operation->process($manager, [$user], $properties));
137
        $this->assertNotEmpty($operation->get_form(null, ['users' => [$user]]));
138
    }
139
}