Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 78... Línea 78...
78
    }
78
    }
Línea 79... Línea 79...
79
 
79
 
80
    /**
80
    /**
81
     * Test to confirm the task is named correctly.
81
     * Test to confirm the task is named correctly.
82
     */
82
     */
83
    public function test_task_name() {
83
    public function test_task_name(): void {
84
        $task = new \tool_monitor\task\check_subscriptions();
84
        $task = new \tool_monitor\task\check_subscriptions();
85
        $this->assertEquals(get_string('taskchecksubscriptions', 'tool_monitor'), $task->get_name());
85
        $this->assertEquals(get_string('taskchecksubscriptions', 'tool_monitor'), $task->get_name());
Línea 86... Línea 86...
86
    }
86
    }
87
 
87
 
88
    /**
88
    /**
89
     * Test to confirm that site level subscriptions are activated and deactivated according to system capabilities.
89
     * Test to confirm that site level subscriptions are activated and deactivated according to system capabilities.
90
     */
90
     */
91
    public function test_site_level_subscription() {
91
    public function test_site_level_subscription(): void {
92
        // Create a site level subscription.
92
        // Create a site level subscription.
93
        $monitorgenerator = $this->getDataGenerator()->get_plugin_generator('tool_monitor');
93
        $monitorgenerator = $this->getDataGenerator()->get_plugin_generator('tool_monitor');
94
        $sub = new \stdClass();
94
        $sub = new \stdClass();
Línea 117... Línea 117...
117
    }
117
    }
Línea 118... Línea 118...
118
 
118
 
119
    /**
119
    /**
120
     * Test to confirm that if the module is disabled, no changes are made to active subscriptions.
120
     * Test to confirm that if the module is disabled, no changes are made to active subscriptions.
121
     */
121
     */
122
    public function test_module_disabled() {
122
    public function test_module_disabled(): void {
Línea 123... Línea 123...
123
        set_config('enablemonitor', 0, 'tool_monitor');
123
        set_config('enablemonitor', 0, 'tool_monitor');
124
 
124
 
Línea 135... Línea 135...
135
    }
135
    }
Línea 136... Línea 136...
136
 
136
 
137
    /**
137
    /**
138
     * Test to confirm an active, valid subscription stays active once the scheduled task is run.
138
     * Test to confirm an active, valid subscription stays active once the scheduled task is run.
139
     */
139
     */
140
    public function test_active_unaffected() {
140
    public function test_active_unaffected(): void {
141
        // Enrol the user as a teacher. This role should have the required capability.
141
        // Enrol the user as a teacher. This role should have the required capability.
Línea 142... Línea 142...
142
        $this->getDataGenerator()->enrol_user($this->user->id, $this->course->id, $this->teacherrole->id);
142
        $this->getDataGenerator()->enrol_user($this->user->id, $this->course->id, $this->teacherrole->id);
143
 
143
 
Línea 154... Línea 154...
154
    }
154
    }
Línea 155... Línea 155...
155
 
155
 
156
    /**
156
    /**
157
     * Test to confirm that a subscription for a user without an enrolment to the course is made inactive.
157
     * Test to confirm that a subscription for a user without an enrolment to the course is made inactive.
158
     */
158
     */
159
    public function test_course_enrolment() {
159
    public function test_course_enrolment(): void {
160
        // Subscription should be active until deactivated by the scheduled task. Remember, by default the test setup
160
        // Subscription should be active until deactivated by the scheduled task. Remember, by default the test setup
161
        // doesn't enrol the user, so the first run of the task should deactivate it.
161
        // doesn't enrol the user, so the first run of the task should deactivate it.
Línea 162... Línea 162...
162
        $this->assertEquals(true, \tool_monitor\subscription_manager::subscription_is_active($this->subscription));
162
        $this->assertEquals(true, \tool_monitor\subscription_manager::subscription_is_active($this->subscription));
Línea 182... Línea 182...
182
    }
182
    }
Línea 183... Línea 183...
183
 
183
 
184
    /**
184
    /**
185
     * Test to confirm that subscriptions for enrolled users without the required capability are made inactive.
185
     * Test to confirm that subscriptions for enrolled users without the required capability are made inactive.
186
     */
186
     */
187
    public function test_enrolled_user_with_no_capability() {
187
    public function test_enrolled_user_with_no_capability(): void {
188
        // Enrol the user. By default, students won't have the required capability.
188
        // Enrol the user. By default, students won't have the required capability.
Línea 189... Línea 189...
189
        $this->getDataGenerator()->enrol_user($this->user->id, $this->course->id, $this->studentrole->id);
189
        $this->getDataGenerator()->enrol_user($this->user->id, $this->course->id, $this->studentrole->id);
190
 
190
 
Línea 201... Línea 201...
201
    }
201
    }
Línea 202... Línea 202...
202
 
202
 
203
    /**
203
    /**
204
     * Test to confirm that subscriptions for users who fail can_access_course(), are deactivated.
204
     * Test to confirm that subscriptions for users who fail can_access_course(), are deactivated.
205
     */
205
     */
206
    public function test_can_access_course() {
206
    public function test_can_access_course(): void {
207
        // Enrol the user as a teacher. This role should have the required capability.
207
        // Enrol the user as a teacher. This role should have the required capability.
Línea 208... Línea 208...
208
        $this->getDataGenerator()->enrol_user($this->user->id, $this->course->id, $this->teacherrole->id);
208
        $this->getDataGenerator()->enrol_user($this->user->id, $this->course->id, $this->teacherrole->id);
209
 
209
 
Línea 227... Línea 227...
227
    }
227
    }
Línea 228... Línea 228...
228
 
228
 
229
    /**
229
    /**
230
     * Test to confirm that subscriptions for enrolled users who don't have CM access, are deactivated.
230
     * Test to confirm that subscriptions for enrolled users who don't have CM access, are deactivated.
231
     */
231
     */
232
    public function test_cm_access() {
232
    public function test_cm_access(): void {
233
        // Enrol the user as a student but grant to ability to subscribe. Students cannot view hidden activities.
233
        // Enrol the user as a student but grant to ability to subscribe. Students cannot view hidden activities.
234
        $context = \context_course::instance($this->course->id);
234
        $context = \context_course::instance($this->course->id);
235
        assign_capability('tool/monitor:subscribe', CAP_ALLOW, $this->studentrole->id, $context);
235
        assign_capability('tool/monitor:subscribe', CAP_ALLOW, $this->studentrole->id, $context);
Línea 282... Línea 282...
282
    }
282
    }
Línea 283... Línea 283...
283
 
283
 
284
    /**
284
    /**
285
     * Test to confirm that long term inactive subscriptions are removed entirely.
285
     * Test to confirm that long term inactive subscriptions are removed entirely.
286
     */
286
     */
287
    public function test_stale_subscription_removal() {
287
    public function test_stale_subscription_removal(): void {
288
        global $DB;
288
        global $DB;
289
        // Manually set the inactivedate to 1 day older than the limit allowed.
289
        // Manually set the inactivedate to 1 day older than the limit allowed.
Línea 290... Línea 290...
290
        $daysold = 1 + \tool_monitor\subscription_manager::INACTIVE_SUBSCRIPTION_LIFESPAN_IN_DAYS;
290
        $daysold = 1 + \tool_monitor\subscription_manager::INACTIVE_SUBSCRIPTION_LIFESPAN_IN_DAYS;
Línea 305... Línea 305...
305
    }
305
    }
Línea 306... Línea 306...
306
 
306
 
307
    /**
307
    /**
308
     * Test to confirm that subscriptions for a partially set up user are deactivated.
308
     * Test to confirm that subscriptions for a partially set up user are deactivated.
309
     */
309
     */
310
    public function test_user_not_fully_set_up() {
310
    public function test_user_not_fully_set_up(): void {
Línea 311... Línea 311...
311
        global $DB;
311
        global $DB;
312
 
312
 
Línea 329... Línea 329...
329
    }
329
    }
Línea 330... Línea 330...
330
 
330
 
331
    /**
331
    /**
332
     * Test to confirm that a suspended user's subscriptions are deactivated properly.
332
     * Test to confirm that a suspended user's subscriptions are deactivated properly.
333
     */
333
     */
334
    public function test_suspended_user() {
334
    public function test_suspended_user(): void {
Línea 335... Línea 335...
335
        global $DB;
335
        global $DB;
336
 
336