Differences Between: [Versions 310 and 400] [Versions 39 and 400]
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 test for the filter_tex 19 * 20 * @package filter_tex 21 * @copyright 2014 Damyon Wiese 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 namespace filter_tex; 26 27 use filter_tex; 28 29 defined('MOODLE_INTERNAL') || die(); 30 31 global $CFG; 32 require_once($CFG->dirroot . '/filter/tex/filter.php'); 33 34 35 /** 36 * Unit tests for filter_tex. 37 * 38 * Test the delimiter parsing used by the tex filter. 39 * 40 * @copyright 2014 Damyon Wiese 41 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 42 */ 43 class filter_test extends \advanced_testcase { 44 45 protected $filter; 46 47 protected function setUp(): void { 48 parent::setUp(); 49 $this->resetAfterTest(true); 50 $this->filter = new filter_tex(\context_system::instance(), array()); 51 } 52 53 function run_with_delimiters($start, $end, $filtershouldrun) { 54 $pre = 'Some pre text'; 55 $post = 'Some post text'; 56 $equation = ' \sum{a^b} '; 57 58 $before = $pre . $start . $equation . $end . $post; 59 60 $after = trim($this->filter->filter($before)); 61 62 if ($filtershouldrun) { 63 $this->assertNotEquals($after, $before); 64 } else { 65 $this->assertEquals($after, $before); 66 } 67 } 68 69 function test_delimiters() { 70 // First test the list of supported delimiters. 71 $this->run_with_delimiters('$$', '$$', true); 72 $this->run_with_delimiters('\\(', '\\)', true); 73 $this->run_with_delimiters('\\[', '\\]', true); 74 $this->run_with_delimiters('[tex]', '[/tex]', true); 75 $this->run_with_delimiters('<tex>', '</tex>', true); 76 $this->run_with_delimiters('<tex alt="nonsense">', '</tex>', true); 77 // Now test some cases that shouldn't be executed. 78 $this->run_with_delimiters('<textarea>', '</textarea>', false); 79 $this->run_with_delimiters('$', '$', false); 80 $this->run_with_delimiters('(', ')', false); 81 $this->run_with_delimiters('[', ']', false); 82 $this->run_with_delimiters('$$', '\\]', false); 83 } 84 85 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body