|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00026 defined('MOODLE_INTERNAL') || die(); 00027 00028 00029 class purifier_test extends UnitTestCase { 00030 00031 public static $includecoverage = array('lib/htmlpurifier/HTMLPurifier.php'); 00032 00033 private $cachetext = null; 00034 00035 function setUp() { 00036 global $CFG; 00037 $this->cachetext = $CFG->cachetext; 00038 $CFG->cachetext = 0; 00039 } 00040 00041 function tearDown() { 00042 global $CFG; 00043 $CFG->cachetext = $this->cachetext; 00044 } 00045 00050 public function test_allow_blank_target() { 00051 $text = '<a href="http://moodle.org" target="_blank">Some link</a>'; 00052 $result = format_text($text, FORMAT_HTML); 00053 $this->assertIdentical($text, $result); 00054 00055 $result = format_text('<a href="http://moodle.org" target="some">Some link</a>', FORMAT_HTML); 00056 $this->assertIdentical('<a href="http://moodle.org">Some link</a>', $result); 00057 } 00058 00063 public function test_nolink() { 00064 // we can not use format text because nolink changes result 00065 $text = '<nolink><div>no filters</div></nolink>'; 00066 $result = purify_html($text, array()); 00067 $this->assertIdentical($text, $result); 00068 } 00069 00074 public function test_tex() { 00075 $text = '<tex>a+b=c</tex>'; 00076 $result = purify_html($text, array()); 00077 $this->assertIdentical($text, $result); 00078 } 00079 00084 public function test_algebra() { 00085 $text = '<algebra>a+b=c</algebra>'; 00086 $result = purify_html($text, array()); 00087 $this->assertIdentical($text, $result); 00088 } 00089 00094 public function test_multilang() { 00095 $text = '<lang lang="en">hmmm</lang><lang lang="anything">hm</lang>'; 00096 $result = purify_html($text, array()); 00097 $this->assertIdentical($text, $result); 00098 00099 $text = '<span lang="en" class="multilang">hmmm</span><span lang="anything" class="multilang">hm</span>'; 00100 $result = purify_html($text, array()); 00101 $this->assertIdentical($text, $result); 00102 00103 $text = '<span lang="en">hmmm</span>'; 00104 $result = purify_html($text, array()); 00105 $this->assertNotIdentical($text, $result); 00106 } 00107 00111 public function test_format_text_allowid() { 00112 // Start off by not allowing ids (default) 00113 $options = array( 00114 'nocache' => true 00115 ); 00116 $result = format_text('<div id="example">Frog</div>', FORMAT_HTML, $options); 00117 $this->assertIdentical('<div>Frog</div>', $result); 00118 00119 // Now allow ids 00120 $options['allowid'] = true; 00121 $result = format_text('<div id="example">Frog</div>', FORMAT_HTML, $options); 00122 $this->assertIdentical('<div id="example">Frog</div>', $result); 00123 } 00124 00125 00126 //TODO: add XSS smoke tests here 00127 } 00128