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