See Release Notes
Long Term Support Release
Differences Between: [Versions 310 and 401] [Versions 39 and 401]
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 * Unit test for the site generator 19 * 20 * @package tool_generator 21 * @copyright 2013 David Monllaó 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 namespace tool_generator; 26 27 use tool_generator_site_backend; 28 29 defined('MOODLE_INTERNAL') || die(); 30 31 /** 32 * Unit test for the site generator 33 * 34 * @package tool_generator 35 * @copyright 2013 David Monllaó 36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 37 */ 38 class maketestsite_test extends \advanced_testcase { 39 40 /** 41 * Checks that site courses shortnames are properly generated. 42 */ 43 public function test_shortnames_generation() { 44 45 $this->resetAfterTest(); 46 $this->setAdminUser(); 47 48 $generator = $this->getDataGenerator(); 49 50 // Shortname common prefix. 51 $prefix = tool_generator_site_backend::SHORTNAMEPREFIX; 52 53 $record = array(); 54 55 // Without courses will be 0. 56 $lastshortname = testable_tool_generator_site_backend::get_last_testcourse_id(); 57 $this->assertEquals(0, $lastshortname); 58 59 // Without {$prefix} + {no integer} courses will be 0. 60 $record['shortname'] = $prefix . 'AA'; 61 $generator->create_course($record); 62 $record['shortname'] = $prefix . '__'; 63 $generator->create_course($record); 64 $record['shortname'] = $prefix . '12.2'; 65 $generator->create_course($record); 66 67 $lastshortname = testable_tool_generator_site_backend::get_last_testcourse_id(); 68 $this->assertEquals(0, $lastshortname); 69 70 // With {$prefix} + {integer} courses will be the higher one. 71 $record['shortname'] = $prefix . '2'; 72 $generator->create_course($record); 73 $record['shortname'] = $prefix . '20'; 74 $generator->create_course($record); 75 $record['shortname'] = $prefix . '8'; 76 $generator->create_course($record); 77 78 $lastshortname = testable_tool_generator_site_backend::get_last_testcourse_id(); 79 $this->assertEquals(20, $lastshortname); 80 81 // Numeric order. 82 for ($i = 9; $i < 14; $i++) { 83 $record['shortname'] = $prefix . $i; 84 $generator->create_course($record); 85 } 86 87 $lastshortname = testable_tool_generator_site_backend::get_last_testcourse_id(); 88 $this->assertEquals(20, $lastshortname); 89 } 90 } 91 92 /** 93 * Silly class to access site_backend internal methods. 94 * 95 * @copyright 2013 David Monllaó 96 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 97 */ 98 class testable_tool_generator_site_backend extends tool_generator_site_backend { 99 100 /** 101 * Public accessor. 102 * 103 * @return int 104 */ 105 public static function get_last_testcourse_id() { 106 return parent::get_last_testcourse_id(); 107 } 108 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body