Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 53... Línea 53...
53
            'type' => 'text',
53
            'type' => 'text',
54
            'categoryid' => $fieldcategory->get('id'),
54
            'categoryid' => $fieldcategory->get('id'),
55
        ]);
55
        ]);
56
    }
56
    }
Línea 57... Línea 57...
57
 
57
 
58
    public function test_cohort_add_cohort() {
58
    public function test_cohort_add_cohort(): void {
Línea 59... Línea 59...
59
        global $DB;
59
        global $DB;
60
 
60
 
Línea 87... Línea 87...
87
        $handler = cohort_handler::create();
87
        $handler = cohort_handler::create();
88
        $customfieldsdata = $handler->export_instance_data_object($id);
88
        $customfieldsdata = $handler->export_instance_data_object($id);
89
        $this->assertEquals('Test value 1', $customfieldsdata->testfield1);
89
        $this->assertEquals('Test value 1', $customfieldsdata->testfield1);
90
    }
90
    }
Línea 91... Línea 91...
91
 
91
 
92
    public function test_cohort_add_cohort_missing_name() {
92
    public function test_cohort_add_cohort_missing_name(): void {
93
        $cohort = new \stdClass();
93
        $cohort = new \stdClass();
94
        $cohort->contextid = \context_system::instance()->id;
94
        $cohort->contextid = \context_system::instance()->id;
95
        $cohort->name = null;
95
        $cohort->name = null;
96
        $cohort->idnumber = 'testid';
96
        $cohort->idnumber = 'testid';
Línea 100... Línea 100...
100
        $this->expectException(\coding_exception::class);
100
        $this->expectException(\coding_exception::class);
101
        $this->expectExceptionMessage('Missing cohort name in cohort_add_cohort()');
101
        $this->expectExceptionMessage('Missing cohort name in cohort_add_cohort()');
102
        cohort_add_cohort($cohort);
102
        cohort_add_cohort($cohort);
103
    }
103
    }
Línea 104... Línea 104...
104
 
104
 
105
    public function test_cohort_add_cohort_event() {
105
    public function test_cohort_add_cohort_event(): void {
Línea 106... Línea 106...
106
        $this->resetAfterTest();
106
        $this->resetAfterTest();
107
 
107
 
108
        // Setup cohort data structure.
108
        // Setup cohort data structure.
Línea 134... Línea 134...
134
        $this->assertEquals($url, $event->get_url());
134
        $this->assertEquals($url, $event->get_url());
135
        $this->assertEquals($cohort, $event->get_record_snapshot('cohort', $id));
135
        $this->assertEquals($cohort, $event->get_record_snapshot('cohort', $id));
136
        $this->assertEventContextNotUsed($event);
136
        $this->assertEventContextNotUsed($event);
137
    }
137
    }
Línea 138... Línea 138...
138
 
138
 
139
    public function test_cohort_update_cohort() {
139
    public function test_cohort_update_cohort(): void {
Línea 140... Línea 140...
140
        global $DB;
140
        global $DB;
141
 
141
 
Línea 178... Línea 178...
178
        $handler = cohort_handler::create();
178
        $handler = cohort_handler::create();
179
        $customfieldsdata = $handler->export_instance_data_object($id);
179
        $customfieldsdata = $handler->export_instance_data_object($id);
180
        $this->assertEquals('Test value updated', $customfieldsdata->testfield1);
180
        $this->assertEquals('Test value updated', $customfieldsdata->testfield1);
181
    }
181
    }
Línea 182... Línea 182...
182
 
182
 
183
    public function test_cohort_update_cohort_event() {
183
    public function test_cohort_update_cohort_event(): void {
Línea 184... Línea 184...
184
        global $DB;
184
        global $DB;
Línea 185... Línea 185...
185
 
185
 
Línea 221... Línea 221...
221
        $this->assertEquals($url, $event->get_url());
221
        $this->assertEquals($url, $event->get_url());
222
        $this->assertEquals($cohort, $event->get_record_snapshot('cohort', $id));
222
        $this->assertEquals($cohort, $event->get_record_snapshot('cohort', $id));
223
        $this->assertEventContextNotUsed($event);
223
        $this->assertEventContextNotUsed($event);
224
    }
224
    }
Línea 225... Línea 225...
225
 
225
 
226
    public function test_cohort_delete_cohort() {
226
    public function test_cohort_delete_cohort(): void {
Línea 227... Línea 227...
227
        global $DB;
227
        global $DB;
228
 
228
 
Línea 238... Línea 238...
238
 
238
 
239
        $this->assertFalse($DB->record_exists('cohort', array('id'=>$cohort->id)));
239
        $this->assertFalse($DB->record_exists('cohort', array('id'=>$cohort->id)));
240
        $this->assertFalse($DB->record_exists('customfield_data', ['instanceid' => $cohort->id, 'fieldid' => $field->get('id')]));
240
        $this->assertFalse($DB->record_exists('customfield_data', ['instanceid' => $cohort->id, 'fieldid' => $field->get('id')]));
Línea 241... Línea 241...
241
    }
241
    }
Línea 242... Línea 242...
242
 
242
 
Línea 243... Línea 243...
243
    public function test_cohort_delete_cohort_event() {
243
    public function test_cohort_delete_cohort_event(): void {
Línea 265... Línea 265...
265
        $this->assertEquals($url, $event->get_url());
265
        $this->assertEquals($url, $event->get_url());
266
        $this->assertEquals($cohort, $event->get_record_snapshot('cohort', $cohort->id));
266
        $this->assertEquals($cohort, $event->get_record_snapshot('cohort', $cohort->id));
267
        $this->assertEventContextNotUsed($event);
267
        $this->assertEventContextNotUsed($event);
268
    }
268
    }
Línea 269... Línea 269...
269
 
269
 
270
    public function test_cohort_delete_category() {
270
    public function test_cohort_delete_category(): void {
Línea 271... Línea 271...
271
        global $DB;
271
        global $DB;
Línea 272... Línea 272...
272
 
272
 
Línea 281... Línea 281...
281
        $this->assertTrue($DB->record_exists('cohort', array('id'=>$cohort->id)));
281
        $this->assertTrue($DB->record_exists('cohort', array('id'=>$cohort->id)));
282
        $newcohort = $DB->get_record('cohort', array('id'=>$cohort->id));
282
        $newcohort = $DB->get_record('cohort', array('id'=>$cohort->id));
283
        $this->assertEquals(\context_system::instance()->id, $newcohort->contextid);
283
        $this->assertEquals(\context_system::instance()->id, $newcohort->contextid);
284
    }
284
    }
Línea 285... Línea 285...
285
 
285
 
286
    public function test_cohort_add_member() {
286
    public function test_cohort_add_member(): void {
Línea 287... Línea 287...
287
        global $DB;
287
        global $DB;
Línea 288... Línea 288...
288
 
288
 
Línea 294... Línea 294...
294
        $this->assertFalse($DB->record_exists('cohort_members', array('cohortid'=>$cohort->id, 'userid'=>$user->id)));
294
        $this->assertFalse($DB->record_exists('cohort_members', array('cohortid'=>$cohort->id, 'userid'=>$user->id)));
295
        cohort_add_member($cohort->id, $user->id);
295
        cohort_add_member($cohort->id, $user->id);
296
        $this->assertTrue($DB->record_exists('cohort_members', array('cohortid'=>$cohort->id, 'userid'=>$user->id)));
296
        $this->assertTrue($DB->record_exists('cohort_members', array('cohortid'=>$cohort->id, 'userid'=>$user->id)));
297
    }
297
    }
Línea 298... Línea 298...
298
 
298
 
299
    public function test_cohort_add_member_event() {
299
    public function test_cohort_add_member_event(): void {
300
        global $USER;
300
        global $USER;
Línea 301... Línea 301...
301
        $this->resetAfterTest();
301
        $this->resetAfterTest();
302
 
302
 
Línea 324... Línea 324...
324
        $url = new \moodle_url('/cohort/assign.php', array('id' => $event->objectid));
324
        $url = new \moodle_url('/cohort/assign.php', array('id' => $event->objectid));
325
        $this->assertEquals($url, $event->get_url());
325
        $this->assertEquals($url, $event->get_url());
326
        $this->assertEventContextNotUsed($event);
326
        $this->assertEventContextNotUsed($event);
327
    }
327
    }
Línea 328... Línea 328...
328
 
328
 
329
    public function test_cohort_remove_member() {
329
    public function test_cohort_remove_member(): void {
Línea 330... Línea 330...
330
        global $DB;
330
        global $DB;
Línea 331... Línea 331...
331
 
331
 
Línea 339... Línea 339...
339
 
339
 
340
        cohort_remove_member($cohort->id, $user->id);
340
        cohort_remove_member($cohort->id, $user->id);
341
        $this->assertFalse($DB->record_exists('cohort_members', array('cohortid'=>$cohort->id, 'userid'=>$user->id)));
341
        $this->assertFalse($DB->record_exists('cohort_members', array('cohortid'=>$cohort->id, 'userid'=>$user->id)));
Línea 342... Línea 342...
342
    }
342
    }
343
 
343
 
344
    public function test_cohort_remove_member_event() {
344
    public function test_cohort_remove_member_event(): void {
Línea 345... Línea 345...
345
        global $USER;
345
        global $USER;
346
        $this->resetAfterTest();
346
        $this->resetAfterTest();
Línea 369... Línea 369...
369
        $url = new \moodle_url('/cohort/assign.php', array('id' => $event->objectid));
369
        $url = new \moodle_url('/cohort/assign.php', array('id' => $event->objectid));
370
        $this->assertEquals($url, $event->get_url());
370
        $this->assertEquals($url, $event->get_url());
371
        $this->assertEventContextNotUsed($event);
371
        $this->assertEventContextNotUsed($event);
372
    }
372
    }
Línea 373... Línea 373...
373
 
373
 
374
    public function test_cohort_is_member() {
374
    public function test_cohort_is_member(): void {
Línea 375... Línea 375...
375
        global $DB;
375
        global $DB;
Línea 376... Línea 376...
376
 
376
 
Línea 382... Línea 382...
382
        $this->assertFalse(cohort_is_member($cohort->id, $user->id));
382
        $this->assertFalse(cohort_is_member($cohort->id, $user->id));
383
        cohort_add_member($cohort->id, $user->id);
383
        cohort_add_member($cohort->id, $user->id);
384
        $this->assertTrue(cohort_is_member($cohort->id, $user->id));
384
        $this->assertTrue(cohort_is_member($cohort->id, $user->id));
385
    }
385
    }
Línea 386... Línea 386...
386
 
386
 
387
    public function test_cohort_get_cohorts() {
387
    public function test_cohort_get_cohorts(): void {
Línea 388... Línea 388...
388
        global $DB;
388
        global $DB;
Línea 389... Línea 389...
389
 
389
 
Línea 441... Línea 441...
441
        $this->assertEquals(1, $result['totalcohorts']);
441
        $this->assertEquals(1, $result['totalcohorts']);
442
        $this->assertEquals(array($cohort4->id=>$cohort4), $result['cohorts']);
442
        $this->assertEquals(array($cohort4->id=>$cohort4), $result['cohorts']);
443
        $this->assertEquals(1, $result['allcohorts']);
443
        $this->assertEquals(1, $result['allcohorts']);
444
    }
444
    }
Línea 445... Línea 445...
445
 
445
 
446
    public function test_cohort_get_all_cohorts() {
446
    public function test_cohort_get_all_cohorts(): void {
Línea 447... Línea 447...
447
        global $DB;
447
        global $DB;
Línea 448... Línea 448...
448
 
448
 
Línea 505... Línea 505...
505
        $this->assertEquals(2, $result['totalcohorts']);
505
        $this->assertEquals(2, $result['totalcohorts']);
506
        $this->assertEquals(array($cohort2->id=>$cohort2), $result['cohorts']);
506
        $this->assertEquals(array($cohort2->id=>$cohort2), $result['cohorts']);
507
        $this->assertEquals(2, $result['allcohorts']);
507
        $this->assertEquals(2, $result['allcohorts']);
508
    }
508
    }
Línea 509... Línea 509...
509
 
509
 
510
    public function test_cohort_get_available_cohorts() {
510
    public function test_cohort_get_available_cohorts(): void {
Línea 511... Línea 511...
511
        global $DB;
511
        global $DB;
Línea 512... Línea 512...
512
 
512
 
Línea 694... Línea 694...
694
     * Test that all get functions return custom fields data.
694
     * Test that all get functions return custom fields data.
695
     *
695
     *
696
     * @covers \cohort_get_cohort, \cohort_get_cohorts, \cohort_get_all_cohorts
696
     * @covers \cohort_get_cohort, \cohort_get_cohorts, \cohort_get_all_cohorts
697
     * @covers \cohort_get_available_cohorts, \cohort_get_user_cohorts
697
     * @covers \cohort_get_available_cohorts, \cohort_get_user_cohorts
698
     */
698
     */
699
    public function test_get_functions_return_custom_fields() {
699
    public function test_get_functions_return_custom_fields(): void {
700
        $this->resetAfterTest();
700
        $this->resetAfterTest();
701
        $this->setAdminUser();
701
        $this->setAdminUser();
Línea 702... Línea 702...
702
 
702
 
703
        $user = self::getDataGenerator()->create_user();
703
        $user = self::getDataGenerator()->create_user();
Línea 827... Línea 827...
827
    }
827
    }
Línea 828... Línea 828...
828
 
828
 
829
    /**
829
    /**
830
     * Create a cohort with allowcohortthemes enabled/disabled.
830
     * Create a cohort with allowcohortthemes enabled/disabled.
831
     */
831
     */
832
    public function test_cohort_add_theme_cohort() {
832
    public function test_cohort_add_theme_cohort(): void {
Línea 833... Línea 833...
833
        global $DB;
833
        global $DB;
Línea 834... Línea 834...
834
 
834
 
Línea 869... Línea 869...
869
    }
869
    }
Línea 870... Línea 870...
870
 
870
 
871
    /**
871
    /**
872
     * Update a cohort with allowcohortthemes enabled/disabled.
872
     * Update a cohort with allowcohortthemes enabled/disabled.
873
     */
873
     */
874
    public function test_cohort_update_theme_cohort() {
874
    public function test_cohort_update_theme_cohort(): void {
Línea 875... Línea 875...
875
        global $DB;
875
        global $DB;
Línea 876... Línea 876...
876
 
876
 
Línea 912... Línea 912...
912
    /**
912
    /**
913
     * Test that lib function returns custom field data for a cohorts.
913
     * Test that lib function returns custom field data for a cohorts.
914
     *
914
     *
915
     * @covers \cohort_get_custom_fields_data
915
     * @covers \cohort_get_custom_fields_data
916
     */
916
     */
917
    public function test_cohort_get_custom_fields_data() {
917
    public function test_cohort_get_custom_fields_data(): void {
918
        $this->resetAfterTest();
918
        $this->resetAfterTest();
919
        $this->setAdminUser();
919
        $this->setAdminUser();
Línea 920... Línea 920...
920
 
920
 
Línea 943... Línea 943...
943
    /**
943
    /**
944
     * Test the behaviour of cohort_get_cohort().
944
     * Test the behaviour of cohort_get_cohort().
945
     *
945
     *
946
     * @covers ::cohort_get_cohort
946
     * @covers ::cohort_get_cohort
947
     */
947
     */
948
    public function test_cohort_get_cohort() {
948
    public function test_cohort_get_cohort(): void {
949
        $this->resetAfterTest();
949
        $this->resetAfterTest();
Línea 950... Línea 950...
950
 
950
 
951
        $cat = $this->getDataGenerator()->create_category();
951
        $cat = $this->getDataGenerator()->create_category();
952
        $cat1 = $this->getDataGenerator()->create_category(['parent' => $cat->id]);
952
        $cat1 = $this->getDataGenerator()->create_category(['parent' => $cat->id]);