Merge branch 'MDL-62370-master' of git://github.com/andrewnicols/moodle
[moodle.git] / filter / algebra / tests / filter_test.php
blob6c7db8fbdad0dd30556fdd038e3288ee75ba61ab
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.
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/>.
17 /**
18 * Unit test for the filter_algebra
20 * @package filter_algebra
21 * @category phpunit
22 * @copyright 2012 Tim Hunt
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 defined('MOODLE_INTERNAL') || die();
28 global $CFG;
29 require_once($CFG->dirroot . '/filter/algebra/filter.php');
32 /**
33 * Unit tests for filter_algebra.
35 * Note that this only tests some of the filter logic. It does not acutally test
36 * the normal case of the filter working, because I cannot make it work on my
37 * test server, and if it does not work here, it probably does not also work
38 * for other people. A failing test will be irritating noise.
40 * @copyright 2012 Tim Hunt
41 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
43 class filter_algebra_testcase extends basic_testcase {
45 protected $filter;
47 protected function setUp() {
48 parent::setUp();
49 $this->filter = new filter_algebra(context_system::instance(), array());
52 function test_algebra_filter_no_algebra() {
53 $this->assertEquals('<p>Look no algebra!</p>',
54 $this->filter->filter('<p>Look no algebra!</p>'));
58 function test_algebra_filter_pluginfile() {
59 $this->assertEquals('<img src="@@PLUGINFILE@@/photo.jpg">',
60 $this->filter->filter('<img src="@@PLUGINFILE@@/photo.jpg">'));
63 function test_algebra_filter_draftfile() {
64 $this->assertEquals('<img src="@@DRAFTFILE@@/photo.jpg">',
65 $this->filter->filter('<img src="@@DRAFTFILE@@/photo.jpg">'));
68 function test_algebra_filter_unified_diff() {
69 $diff = '
70 diff -u -r1.1 Worksheet.php
71 --- Worksheet.php 26 Sep 2003 04:18:02 -0000 1.1
72 +++ Worksheet.php 18 Nov 2009 03:58:50 -0000
73 @@ -1264,10 +1264,10 @@
76 // Strip the = or @ sign at the beginning of the formula string
77 - if (ereg("^=",$formula)) {
78 + if (preg_match("/^=/",$formula)) {
79 $formula = preg_replace("/(^=)/","",$formula);
81 - elseif(ereg("^@",$formula)) {
82 + elseif(preg_match("/^@/",$formula)) {
83 $formula = preg_replace("/(^@)/","",$formula);
85 else {
87 $this->assertEquals('<pre>' . $diff . '</pre>',
88 $this->filter->filter('<pre>' . $diff . '</pre>'));