[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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. 19 * 20 * @package filter_glossary 21 * @category test 22 * @copyright 2013 The Open University 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 global $CFG; 29 require_once($CFG->dirroot . '/filter/glossary/filter.php'); // Include the code to test. 30 31 /** 32 * Test case for glossary. 33 */ 34 class filter_glossary_filter_testcase extends advanced_testcase { 35 36 /** 37 * Test ampersands. 38 */ 39 public function test_ampersands() { 40 global $CFG; 41 $this->resetAfterTest(true); 42 43 // Enable glossary filter at top level. 44 filter_set_global_state('glossary', TEXTFILTER_ON); 45 $CFG->glossary_linkentries = 1; 46 47 // Create a test course. 48 $course = $this->getDataGenerator()->create_course(); 49 $context = context_course::instance($course->id); 50 51 // Create a glossary. 52 $glossary = $this->getDataGenerator()->create_module('glossary', 53 array('course' => $course->id, 'mainglossary' => 1)); 54 55 // Create two entries with ampersands and one normal entry. 56 /** @var mod_glossary_generator $generator */ 57 $generator = $this->getDataGenerator()->get_plugin_generator('mod_glossary'); 58 $normal = $generator->create_content($glossary, array('concept' => 'normal')); 59 $amp1 = $generator->create_content($glossary, array('concept' => 'A&B')); 60 $amp2 = $generator->create_content($glossary, array('concept' => 'C&D')); 61 62 filter_manager::reset_caches(); 63 \mod_glossary\local\concept_cache::reset_caches(); 64 65 // Format text with all three entries in HTML. 66 $html = '<p>A&B C&D normal</p>'; 67 $filtered = format_text($html, FORMAT_HTML, array('context' => $context)); 68 69 // Find all the glossary links in the result. 70 $matches = array(); 71 preg_match_all('~eid=([0-9]+).*?title="(.*?)"~', $filtered, $matches); 72 73 // There should be 3 glossary links. 74 $this->assertEquals(3, count($matches[1])); 75 $this->assertEquals($amp1->id, $matches[1][0]); 76 $this->assertEquals($amp2->id, $matches[1][1]); 77 $this->assertEquals($normal->id, $matches[1][2]); 78 79 // Check text and escaping of title attribute. 80 $this->assertEquals($glossary->name . ': A&B', $matches[2][0]); 81 $this->assertEquals($glossary->name . ': C&D', $matches[2][1]); 82 $this->assertEquals($glossary->name . ': normal', $matches[2][2]); 83 } 84 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |