3 ///////////////////////////////////////////////////////////////////////////
5 // NOTICE OF COPYRIGHT //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.org //
10 // Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
12 // This program is free software; you can redistribute it and/or modify //
13 // it under the terms of the GNU General Public License as published by //
14 // the Free Software Foundation; either version 2 of the License, or //
15 // (at your option) any later version. //
17 // This program is distributed in the hope that it will be useful, //
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
20 // GNU General Public License for more details: //
22 // http://www.gnu.org/copyleft/gpl.html //
24 ///////////////////////////////////////////////////////////////////////////
27 * Unit tests for Course lib.
29 * @author nicolasconnault@gmail.com
30 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
34 if (!defined('MOODLE_INTERNAL')) {
35 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
38 require_once($CFG->dirroot
. '/course/lib.php');
40 class courselib_test
extends UnitTestCase
{
49 function testReorderSections() {
50 $sections = array(20 => 0, 21 => 1, 22 => 2, 23 => 3, 24 => 4, 25 => 5);
51 $this->assertFalse(reorder_sections(1,3,4));
53 $newsections = reorder_sections($sections, 2, 4);
54 $newsections_flipped = array_flip($newsections);
56 $this->assertEqual(20, reset($newsections_flipped));
57 $this->assertEqual(21, next($newsections_flipped));
58 $this->assertEqual(23, next($newsections_flipped));
59 $this->assertEqual(24, next($newsections_flipped));
60 $this->assertEqual(22, next($newsections_flipped));
61 $this->assertEqual(25, next($newsections_flipped));
63 $newsections = reorder_sections($sections, 4, 0);
64 $newsections_flipped = array_flip($newsections);
66 $this->assertEqual(20, reset($newsections_flipped));
67 $this->assertEqual(24, next($newsections_flipped));
68 $this->assertEqual(21, next($newsections_flipped));
69 $this->assertEqual(22, next($newsections_flipped));
70 $this->assertEqual(23, next($newsections_flipped));
71 $this->assertEqual(25, next($newsections_flipped));
73 $newsections = reorder_sections($sections, 1, 5);
74 $newsections_flipped = array_flip($newsections);
76 $this->assertEqual(20, reset($newsections_flipped));
77 $this->assertEqual(22, next($newsections_flipped));
78 $this->assertEqual(23, next($newsections_flipped));
79 $this->assertEqual(24, next($newsections_flipped));
80 $this->assertEqual(25, next($newsections_flipped));
81 $this->assertEqual(21, next($newsections_flipped));