|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00027 defined('MOODLE_INTERNAL') || die(); 00028 00029 require_once($CFG->libdir . '/questionlib.php'); 00030 require_once($CFG->dirroot . '/question/format.php'); 00031 00032 00039 class testable_qformat extends qformat_default { 00040 public function assemble_category_path($names) { 00041 return parent::assemble_category_path($names); 00042 } 00043 00044 public function split_category_path($names) { 00045 return parent::split_category_path($names); 00046 } 00047 } 00048 00049 00056 class qformat_default_test extends UnitTestCase { 00057 public function test_assemble_category_path() { 00058 $format = new testable_qformat(); 00059 $pathsections = array( 00060 '$course$', 00061 "Tim's questions", 00062 "Tricky things like / // and so on", 00063 'Category name ending in /', 00064 '/ and one that starts with one', 00065 '<span lang="en" class="multilang">Matematically</span> <span lang="sv" class="multilang">Matematiskt (svenska)</span>' 00066 ); 00067 $this->assertEqual('$course$/Tim\'s questions/Tricky things like // //// and so on/Category name ending in // / // and one that starts with one/<span lang="en" class="multilang">Matematically<//span> <span lang="sv" class="multilang">Matematiskt (svenska)<//span>', 00068 $format->assemble_category_path($pathsections)); 00069 } 00070 00071 public function test_split_category_path() { 00072 $format = new testable_qformat(); 00073 $path = '$course$/Tim\'s questions/Tricky things like // //// and so on/Category name ending in // / // and one that starts with one/<span lang="en" class="multilang">Matematically<//span> <span lang="sv" class="multilang">Matematiskt (svenska)<//span>'; 00074 $this->assertEqual(array( 00075 '$course$', 00076 "Tim's questions", 00077 "Tricky things like / // and so on", 00078 'Category name ending in /', 00079 '/ and one that starts with one', 00080 '<span lang="en" class="multilang">Matematically</span> <span lang="sv" class="multilang">Matematiskt (svenska)</span>' 00081 ), $format->split_category_path($path)); 00082 } 00083 00084 public function test_split_category_path_cleans() { 00085 $format = new testable_qformat(); 00086 $path = '<evil>Nasty <virus //> thing<//evil>'; 00087 $this->assertEqual(array('Nasty thing'), $format->split_category_path($path)); 00088 } 00089 }