weekly release 2.9dev
[moodle.git] / mod / wiki / tests / wikiparser_test.php
CommitLineData
ba0c4843
PS
1<?php
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17/**
18 * Unit tests for the wiki parser
19 *
20 * @package mod_wiki
21 * @category phpunit
7db38cd5
SH
22 * @copyright 2009 Marc Alier, Jordi Piguillem marc.alier@upc.edu
23 * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu
ba0c4843
PS
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
34defined('MOODLE_INTERNAL') || die;
35
36global $CFG;
37require_once($CFG->dirroot . '/mod/wiki/parser/parser.php');
38
39
40class mod_wiki_wikiparser_test extends basic_testcase {
41
42 function testCreoleMarkup() {
43 $this->assertTestFiles('creole');
44 }
45
46 function testNwikiMarkup() {
47 $this->assertTestFiles('nwiki');
48 }
49
50 function testHtmlMarkup() {
51 $this->assertTestFiles('html');
52 }
53
54 private function assertTestFile($num, $markup) {
55 if(!file_exists(__DIR__."/fixtures/input/$markup/$num") || !file_exists(__DIR__."/fixtures/output/$markup/$num")) {
56 return false;
57 }
58 $input = file_get_contents(__DIR__."/fixtures/input/$markup/$num");
59 $output = file_get_contents(__DIR__."/fixtures/output/$markup/$num");
60
61 $result = wiki_parser_proxy::parse($input, $markup, array('pretty_print' => true));
62
63 //removes line breaks to avoid line break encoding causing tests to fail.
64 $result['parsed_text'] = preg_replace('~[\r\n]~', '', $result['parsed_text']);
65 $output = preg_replace('~[\r\n]~', '', $output);
66
67 $this->assertEquals($result['parsed_text'], $output);
68 return true;
69 }
70
71 private function assertTestFiles($markup) {
72 $i = 1;
73 while($this->assertTestFile($i, $markup)) {
74 $i++;
75 }
76 }
77}