Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 25... Línea 25...
25
 * @copyright  2013 Frédéric Massart
25
 * @copyright  2013 Frédéric Massart
26
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27
 */
27
 */
28
class helper_test extends \advanced_testcase {
28
class helper_test extends \advanced_testcase {
Línea 29... Línea 29...
29
 
29
 
30
    public function test_generate_shortname() {
30
    public function test_generate_shortname(): void {
Línea 31... Línea 31...
31
        $data = (object) array('fullname' => 'Ah bh Ch 01 02 03', 'idnumber' => 'ID123');
31
        $data = (object) array('fullname' => 'Ah bh Ch 01 02 03', 'idnumber' => 'ID123');
32
 
32
 
33
        $this->assertSame($data->fullname, tool_uploadcourse_helper::generate_shortname($data, '%f'));
33
        $this->assertSame($data->fullname, tool_uploadcourse_helper::generate_shortname($data, '%f'));
Línea 41... Línea 41...
41
 
41
 
42
        $this->assertNull(tool_uploadcourse_helper::generate_shortname($data, ''));
42
        $this->assertNull(tool_uploadcourse_helper::generate_shortname($data, ''));
43
        $this->assertNull(tool_uploadcourse_helper::generate_shortname(array(), '%f'));
43
        $this->assertNull(tool_uploadcourse_helper::generate_shortname(array(), '%f'));
Línea 44... Línea 44...
44
    }
44
    }
45
 
45
 
46
    public function test_get_course_formats() {
46
    public function test_get_course_formats(): void {
47
        $result = tool_uploadcourse_helper::get_course_formats();
47
        $result = tool_uploadcourse_helper::get_course_formats();
48
        $this->assertSame(array_keys(\core_component::get_plugin_list('format')), $result);
48
        $this->assertSame(array_keys(\core_component::get_plugin_list('format')), $result);
49
        // Should be similar as first result, as cached.
49
        // Should be similar as first result, as cached.
Línea 50... Línea 50...
50
        $this->assertSame($result, tool_uploadcourse_helper::get_course_formats());
50
        $this->assertSame($result, tool_uploadcourse_helper::get_course_formats());
51
    }
51
    }
52
 
52
 
53
    public function test_get_enrolment_data() {
53
    public function test_get_enrolment_data(): void {
54
        $this->resetAfterTest(true);
54
        $this->resetAfterTest(true);
55
        $data = array(
55
        $data = array(
Línea 94... Línea 94...
94
            )
94
            )
95
        );
95
        );
96
        $this->assertSame(tool_uploadcourse_helper::get_enrolment_data($data), $expected);
96
        $this->assertSame(tool_uploadcourse_helper::get_enrolment_data($data), $expected);
97
    }
97
    }
Línea 98... Línea 98...
98
 
98
 
99
    public function test_get_enrolment_plugins() {
99
    public function test_get_enrolment_plugins(): void {
100
        $this->resetAfterTest(true);
100
        $this->resetAfterTest(true);
101
        $actual = tool_uploadcourse_helper::get_enrolment_plugins();
101
        $actual = tool_uploadcourse_helper::get_enrolment_plugins();
102
        $this->assertSame(array_keys(enrol_get_plugins(false)), array_keys($actual));
102
        $this->assertSame(array_keys(enrol_get_plugins(false)), array_keys($actual));
103
        // This should be identical as cached.
103
        // This should be identical as cached.
104
        $secondactual = tool_uploadcourse_helper::get_enrolment_plugins();
104
        $secondactual = tool_uploadcourse_helper::get_enrolment_plugins();
105
        $this->assertEquals($actual, $secondactual);
105
        $this->assertEquals($actual, $secondactual);
Línea 106... Línea 106...
106
    }
106
    }
107
 
107
 
108
    public function test_get_restore_content_dir() {
108
    public function test_get_restore_content_dir(): void {
109
        global $CFG;
109
        global $CFG;
110
        require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
110
        require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
Línea 195... Línea 195...
195
        $this->assertEquals($dir, $dir2);
195
        $this->assertEquals($dir, $dir2);
Línea 196... Línea 196...
196
 
196
 
197
        $CFG->keeptempdirectoriesonbackup = $oldcfg;
197
        $CFG->keeptempdirectoriesonbackup = $oldcfg;
Línea 198... Línea 198...
198
    }
198
    }
199
 
199
 
200
    public function test_get_role_ids() {
200
    public function test_get_role_ids(): void {
201
        $this->getDataGenerator();
201
        $this->getDataGenerator();
202
        // Mimic function result.
202
        // Mimic function result.
203
        $expected = array();
203
        $expected = array();
Línea 211... Línea 211...
211
 
211
 
212
        // Check cache.
212
        // Check cache.
213
        $this->assertSame($actual, tool_uploadcourse_helper::get_role_ids());
213
        $this->assertSame($actual, tool_uploadcourse_helper::get_role_ids());
Línea 214... Línea 214...
214
    }
214
    }
215
 
215
 
Línea 216... Línea 216...
216
    public function test_get_role_names() {
216
    public function test_get_role_names(): void {
217
        $this->resetAfterTest(true);
217
        $this->resetAfterTest(true);
218
 
218
 
Línea 244... Línea 244...
244
    }
244
    }
Línea 245... Línea 245...
245
 
245
 
246
    /**
246
    /**
247
     * Test custom field data processing
247
     * Test custom field data processing
248
     */
248
     */
249
    public function test_get_custom_course_field_data() {
249
    public function test_get_custom_course_field_data(): void {
Línea 250... Línea 250...
250
        global $DB;
250
        global $DB;
Línea 251... Línea 251...
251
 
251
 
Línea 316... Línea 316...
316
        $fields = tool_uploadcourse_helper::get_custom_course_field_data($data, [], $context);
316
        $fields = tool_uploadcourse_helper::get_custom_course_field_data($data, [], $context);
317
        $this->assertCount(4, $fields);
317
        $this->assertCount(4, $fields);
318
        $this->assertArrayNotHasKey('customfield_mytext', $fields);
318
        $this->assertArrayNotHasKey('customfield_mytext', $fields);
319
    }
319
    }
Línea 320... Línea 320...
320
 
320
 
321
    public function test_increment_idnumber() {
321
    public function test_increment_idnumber(): void {
Línea 322... Línea 322...
322
        $this->resetAfterTest(true);
322
        $this->resetAfterTest(true);
323
 
323
 
324
        $c1 = $this->getDataGenerator()->create_course(array('idnumber' => 'C1'));
324
        $c1 = $this->getDataGenerator()->create_course(array('idnumber' => 'C1'));
Línea 328... Línea 328...
328
        $this->assertEquals('C3', tool_uploadcourse_helper::increment_idnumber('C1'));
328
        $this->assertEquals('C3', tool_uploadcourse_helper::increment_idnumber('C1'));
329
        $this->assertEquals('Yo_2', tool_uploadcourse_helper::increment_idnumber('Yo'));
329
        $this->assertEquals('Yo_2', tool_uploadcourse_helper::increment_idnumber('Yo'));
330
        $this->assertEquals('DoesNotExist', tool_uploadcourse_helper::increment_idnumber('DoesNotExist'));
330
        $this->assertEquals('DoesNotExist', tool_uploadcourse_helper::increment_idnumber('DoesNotExist'));
331
    }
331
    }
Línea 332... Línea 332...
332
 
332
 
333
    public function test_increment_shortname() {
333
    public function test_increment_shortname(): void {
Línea 334... Línea 334...
334
        $this->resetAfterTest(true);
334
        $this->resetAfterTest(true);
335
 
335
 
336
        $c1 = $this->getDataGenerator()->create_course(array('shortname' => 'C1'));
336
        $c1 = $this->getDataGenerator()->create_course(array('shortname' => 'C1'));
Línea 341... Línea 341...
341
        $this->assertEquals('C3', tool_uploadcourse_helper::increment_shortname('C1'));
341
        $this->assertEquals('C3', tool_uploadcourse_helper::increment_shortname('C1'));
342
        $this->assertEquals('Yo_2', tool_uploadcourse_helper::increment_shortname('Yo'));
342
        $this->assertEquals('Yo_2', tool_uploadcourse_helper::increment_shortname('Yo'));
343
        $this->assertEquals('DoesNotExist_2', tool_uploadcourse_helper::increment_shortname('DoesNotExist'));
343
        $this->assertEquals('DoesNotExist_2', tool_uploadcourse_helper::increment_shortname('DoesNotExist'));
344
    }
344
    }
Línea 345... Línea 345...
345
 
345
 
346
    public function test_resolve_category() {
346
    public function test_resolve_category(): void {
Línea 347... Línea 347...
347
        $this->resetAfterTest(true);
347
        $this->resetAfterTest(true);
348
 
348
 
349
        $c1 = $this->getDataGenerator()->create_category(array('name' => 'First level'));
349
        $c1 = $this->getDataGenerator()->create_category(array('name' => 'First level'));
Línea 375... Línea 375...
375
        $data['category_path'] = 'Not exist';
375
        $data['category_path'] = 'Not exist';
376
        $this->assertEmpty(tool_uploadcourse_helper::resolve_category($data, $errors));
376
        $this->assertEmpty(tool_uploadcourse_helper::resolve_category($data, $errors));
377
        $this->assertArrayHasKey('couldnotresolvecatgorybypath', $errors);
377
        $this->assertArrayHasKey('couldnotresolvecatgorybypath', $errors);
378
    }
378
    }
Línea 379... Línea 379...
379
 
379
 
380
    public function test_resolve_category_by_idnumber() {
380
    public function test_resolve_category_by_idnumber(): void {
Línea 381... Línea 381...
381
        $this->resetAfterTest(true);
381
        $this->resetAfterTest(true);
382
 
382
 
383
        $c1 = $this->getDataGenerator()->create_category(array('idnumber' => 'C1'));
383
        $c1 = $this->getDataGenerator()->create_category(array('idnumber' => 'C1'));
Línea 393... Línea 393...
393
        $this->assertEmpty(tool_uploadcourse_helper::resolve_category_by_idnumber('C3'));
393
        $this->assertEmpty(tool_uploadcourse_helper::resolve_category_by_idnumber('C3'));
394
        $this->assertEmpty(tool_uploadcourse_helper::resolve_category_by_idnumber('DoesNotExist'));
394
        $this->assertEmpty(tool_uploadcourse_helper::resolve_category_by_idnumber('DoesNotExist'));
395
        $this->assertEmpty(tool_uploadcourse_helper::resolve_category_by_idnumber('DoesNotExist'));
395
        $this->assertEmpty(tool_uploadcourse_helper::resolve_category_by_idnumber('DoesNotExist'));
396
    }
396
    }
Línea 397... Línea 397...
397
 
397
 
398
    public function test_resolve_category_by_path() {
398
    public function test_resolve_category_by_path(): void {
Línea 399... Línea 399...
399
        $this->resetAfterTest(true);
399
        $this->resetAfterTest(true);
400
 
400
 
401
        $cat1 = $this->getDataGenerator()->create_category(array('name' => 'Cat 1'));
401
        $cat1 = $this->getDataGenerator()->create_category(array('name' => 'Cat 1'));