Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/course/simpletest/testcourselib.php
Go to the documentation of this file.
00001 <?php
00002 
00004 //                                                                       //
00005 // NOTICE OF COPYRIGHT                                                   //
00006 //                                                                       //
00007 // Moodle - Modular Object-Oriented Dynamic Learning Environment         //
00008 //          http://moodle.org                                            //
00009 //                                                                       //
00010 // Copyright (C) 1999 onwards Martin Dougiamas  http://dougiamas.com     //
00011 //                                                                       //
00012 // This program is free software; you can redistribute it and/or modify  //
00013 // it under the terms of the GNU General Public License as published by  //
00014 // the Free Software Foundation; either version 2 of the License, or     //
00015 // (at your option) any later version.                                   //
00016 //                                                                       //
00017 // This program is distributed in the hope that it will be useful,       //
00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of        //
00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
00020 // GNU General Public License for more details:                          //
00021 //                                                                       //
00022 //          http://www.gnu.org/copyleft/gpl.html                         //
00023 //                                                                       //
00025 
00034 if (!defined('MOODLE_INTERNAL')) {
00035     die('Direct access to this script is forbidden.');    
00036 }
00037 
00038 require_once($CFG->dirroot . '/course/lib.php');
00039 
00040 class courselib_test extends UnitTestCase {
00041     var $realDB;
00042     public  static $includecoverage = array('course/lib.php');
00043 
00044     function setUp() {
00045         global $DB;
00046         Mock::generate(get_class($DB), 'mockDB');
00047         $this->realDB = $DB;
00048         $DB = new mockDB();
00049     }
00050 
00051     function tearDown() {
00052         global $DB;
00053         $DB = $this->realDB;
00054     }
00055 
00056     function testMoveSection() {
00057         global $DB;
00058         $course = new stdClass();
00059         $course->numsections = 10;
00060         $course->id = 1;
00061         $sections = array(20 => 0, 21 => 1, 22 => 2, 23 => 3, 24 => 4, 25 => 5);
00062 
00063         $DB->setReturnValueAt(0, 'get_records_menu', $sections);
00064         $DB->expectAt(0, 'set_field', array('course_sections', 'section', 0, array('id' => 20)));
00065         $DB->expectAt(1, 'set_field', array('course_sections', 'section', 1, array('id' => 21)));
00066         $DB->expectAt(2, 'set_field', array('course_sections', 'section', 2, array('id' => 23)));
00067         $DB->expectAt(3, 'set_field', array('course_sections', 'section', 3, array('id' => 24)));
00068         $DB->expectAt(4, 'set_field', array('course_sections', 'section', 4, array('id' => 22)));
00069         $DB->expectAt(5, 'set_field', array('course_sections', 'section', 5, array('id' => 25)));
00070         move_section_to($course, 2, 4);
00071 
00072         $DB->setReturnValueAt(1, 'get_records_menu', $sections);
00073         $DB->expectAt(6, 'set_field', array('course_sections', 'section', 0, array('id' => 20)));
00074         $DB->expectAt(7, 'set_field', array('course_sections', 'section', 1, array('id' => 24)));
00075         $DB->expectAt(8, 'set_field', array('course_sections', 'section', 2, array('id' => 21)));
00076         $DB->expectAt(9, 'set_field', array('course_sections', 'section', 3, array('id' => 22)));
00077         $DB->expectAt(10, 'set_field', array('course_sections', 'section', 4, array('id' => 23)));
00078         $DB->expectAt(11, 'set_field', array('course_sections', 'section', 5, array('id' => 25)));
00079         move_section_to($course, 4, 0);
00080     }
00081 
00082     function testReorderSections() {
00083         $sections = array(20 => 0, 21 => 1, 22 => 2, 23 => 3, 24 => 4, 25 => 5);
00084         $this->assertFalse(reorder_sections(1,3,4));
00085 
00086         $newsections = reorder_sections($sections, 2, 4);
00087         $newsections_flipped = array_flip($newsections);
00088 
00089         $this->assertEqual(20, reset($newsections_flipped));
00090         $this->assertEqual(21, next($newsections_flipped));
00091         $this->assertEqual(23, next($newsections_flipped));
00092         $this->assertEqual(24, next($newsections_flipped));
00093         $this->assertEqual(22, next($newsections_flipped));
00094         $this->assertEqual(25, next($newsections_flipped));
00095 
00096         $newsections = reorder_sections($sections, 4, 0);
00097         $newsections_flipped = array_flip($newsections);
00098 
00099         $this->assertEqual(20, reset($newsections_flipped));
00100         $this->assertEqual(24, next($newsections_flipped));
00101         $this->assertEqual(21, next($newsections_flipped));
00102         $this->assertEqual(22, next($newsections_flipped));
00103         $this->assertEqual(23, next($newsections_flipped));
00104         $this->assertEqual(25, next($newsections_flipped));
00105 
00106         $newsections = reorder_sections($sections, 1, 5);
00107         $newsections_flipped = array_flip($newsections);
00108 
00109         $this->assertEqual(20, reset($newsections_flipped));
00110         $this->assertEqual(22, next($newsections_flipped));
00111         $this->assertEqual(23, next($newsections_flipped));
00112         $this->assertEqual(24, next($newsections_flipped));
00113         $this->assertEqual(25, next($newsections_flipped));
00114         $this->assertEqual(21, next($newsections_flipped));
00115     }
00116 
00117     function test_get_course_display_name_for_list() {
00118         global $CFG;
00119 
00120         $course = (object)array('shortname' => 'FROG101',
00121                 'fullname' => 'Introduction to pond life');
00122 
00123         // Store config value in case other tests rely on it
00124         $oldcfg = $CFG->courselistshortnames;
00125 
00126         $CFG->courselistshortnames = 0;
00127         $this->assertEqual('Introduction to pond life',
00128                 get_course_display_name_for_list($course));
00129 
00130         $CFG->courselistshortnames = 1;
00131         $this->assertEqual('FROG101 Introduction to pond life',
00132                 get_course_display_name_for_list($course));
00133 
00134         $CFG->courselistshortnames = $oldcfg;
00135     }
00136 }
 All Data Structures Namespaces Files Functions Variables Enumerations