2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * format_weeks related unit tests
20 * @package format_weeks
21 * @copyright 2015 Marina Glancy
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') || die();
28 require_once($CFG->dirroot . '/course/lib.php');
31 * format_weeks related unit tests
33 * @package format_weeks
34 * @copyright 2015 Marina Glancy
35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37 class format_weeks_testcase extends advanced_testcase {
39 public function test_update_course_numsections() {
41 $this->resetAfterTest(true);
43 $generator = $this->getDataGenerator();
45 $course = $generator->create_course(array('numsections' => 10, 'format' => 'weeks'),
46 array('createsections' => true));
47 $generator->create_module('assign', array('course' => $course, 'section' => 7));
49 $this->setAdminUser();
51 $this->assertEquals(11, $DB->count_records('course_sections', array('course' => $course->id)));
53 // Change the numsections to 8, last two sections did not have any activities, they should be deleted.
54 update_course((object)array('id' => $course->id, 'numsections' => 8));
55 $this->assertEquals(9, $DB->count_records('course_sections', array('course' => $course->id)));
56 $this->assertEquals(9, count(get_fast_modinfo($course)->get_section_info_all()));
58 // Change the numsections to 5, section 8 should be deleted but section 7 should remain as it has activities.
59 update_course((object)array('id' => $course->id, 'numsections' => 6));
60 $this->assertEquals(8, $DB->count_records('course_sections', array('course' => $course->id)));
61 $this->assertEquals(8, count(get_fast_modinfo($course)->get_section_info_all()));
62 $this->assertEquals(6, course_get_format($course)->get_course()->numsections);