Unit tests MDL-24992 Fixed mod/wiki unit test CRLF issue (ahem, not using ereg)
[moodle.git] / mod / wiki / simpletest / testwikiparser.php
CommitLineData
00710f4c
DC
1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18/**
19 * Unit tests for the wiki parser
20 *
21 * @package mod-wiki-2.0
22 * @copyrigth 2009 Marc Alier, Jordi Piguillem marc.alier@upc.edu
23 * @copyrigth 2009 Universitat Politecnica de Catalunya http://www.upc.edu
24 *
25 * @author Jordi Piguillem
26 * @author Marc Alier
27 * @author David Jimenez
28 * @author Josep Arus
29 * @author Kenneth Riba
30 *
31 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32 */
33
34if (!defined('MOODLE_INTERNAL')) {
35 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
36}
37
38require_once($CFG->dirroot . '/mod/wiki/parser/parser.php');
39
40class wikiparser_test extends UnitTestCase {
41
42 private $test_directory;
43
44 function setUp() {
45 global $CFG;
46 $this->test_directory = $CFG->dirroot . '/mod/wiki/simpletest/';
47 }
48
49 function testCreoleMarkup() {
50 $this->assertTestFiles('creole');
51 }
52
53 function testNwikiMarkup() {
54 $this->assertTestFiles('nwiki');
55 }
56
57 function testHtmlMarkup() {
58 $this->assertTestFiles('html');
59 }
60
61 private function assertTestFile($num, $markup) {
62 if(!file_exists($this->test_directory."input/$markup/$num") || !file_exists($this->test_directory."output/$markup/$num")) {
63 return false;
64 }
00710f4c
DC
65 $input = file_get_contents($this->test_directory."input/$markup/$num");
66 $output = file_get_contents($this->test_directory."output/$markup/$num");
67
68 $result = wiki_parser_proxy::parse($input, $markup, array('pretty_print' => true));
69
cf72c969 70 //removes line breaks to avoid line break encoding causing tests to fail.
49a874ce
SM
71 $result['parsed_text'] = preg_replace('~[\r\n]~', '', $result['parsed_text']);
72 $output = preg_replace('~[\r\n]~', '', $output);
cf72c969 73
00710f4c
DC
74 $this->assertEqual($result['parsed_text'], $output);
75 return true;
76 }
77
78 private function assertTestFiles($markup) {
79 $i = 1;
80 while($this->assertTestFile($i, $markup)) {
81 $i++;
82 }
83 }
84}