|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00034 if (!defined('MOODLE_INTERNAL')) { 00035 die('Direct access to this script is forbidden.'); 00036 } 00037 00038 require_once($CFG->dirroot . '/mod/wiki/parser/parser.php'); 00039 00040 class wikiparser_test extends UnitTestCase { 00041 00042 private $test_directory; 00043 00044 function setUp() { 00045 global $CFG; 00046 $this->test_directory = $CFG->dirroot . '/mod/wiki/simpletest/'; 00047 } 00048 00049 function testCreoleMarkup() { 00050 $this->assertTestFiles('creole'); 00051 } 00052 00053 function testNwikiMarkup() { 00054 $this->assertTestFiles('nwiki'); 00055 } 00056 00057 function testHtmlMarkup() { 00058 $this->assertTestFiles('html'); 00059 } 00060 00061 private function assertTestFile($num, $markup) { 00062 if(!file_exists($this->test_directory."input/$markup/$num") || !file_exists($this->test_directory."output/$markup/$num")) { 00063 return false; 00064 } 00065 $input = file_get_contents($this->test_directory."input/$markup/$num"); 00066 $output = file_get_contents($this->test_directory."output/$markup/$num"); 00067 00068 $result = wiki_parser_proxy::parse($input, $markup, array('pretty_print' => true)); 00069 00070 //removes line breaks to avoid line break encoding causing tests to fail. 00071 $result['parsed_text'] = preg_replace('~[\r\n]~', '', $result['parsed_text']); 00072 $output = preg_replace('~[\r\n]~', '', $output); 00073 00074 $this->assertEqual($result['parsed_text'], $output); 00075 return true; 00076 } 00077 00078 private function assertTestFiles($markup) { 00079 $i = 1; 00080 while($this->assertTestFile($i, $markup)) { 00081 $i++; 00082 } 00083 } 00084 }