| [ Index ] |
PHP Cross Reference of DokuWiki |
[Summary view] [Print] [Text view]
1 <?php 2 if (!defined('DOKU_BASE')) define('DOKU_BASE','./'); 3 4 require_once 'parser.inc.php'; 5 require_once DOKU_INC.'inc/parser/xhtml.php'; 6 require_once DOKU_INC.'inc/geshi.php'; 7 8 if ( !extension_loaded('runkit') && 9 !@dl('runkit.dll') && 10 !@dl('runkit.so' ) ){ 11 SimpleTestOptions::ignore('xhtml_htmlphp_test'); 12 trigger_error('Skipping xhtml_htmlphp_test - http://www.php.net/runkit required'); 13 } 14 15 function xhtml_htmlphp_test_io_makefiledir() { 16 return; 17 } 18 function xhtml_htmlphp_test_io_savefile() { 19 return true; 20 } 21 22 23 class Doku_Renderer_tester extends Doku_Renderer_xhtml { 24 25 /* 26 changes to these tests remove the need to redefine any xhtml methods 27 class left for future use 28 */ 29 30 } 31 32 /* 33 * test case for parser/xhtml.php _headertolink method 34 * definition: function _headertolink($title,$create) 35 */ 36 37 class xhtml_htmlphp_test extends TestOfDoku_Parser { 38 39 var $purge; 40 var $cachedir; 41 42 function setup() { 43 global $conf; 44 45 // set purge to avoid trying to retrieve from cache 46 $this->purge = isset($_REQUEST['purge']) ? $_REQUEST['purge'] : null; 47 $_REQUEST['purge'] = 1; 48 49 if (!isset($conf['cachedir'])) { 50 $conf['cachedir'] = ''; 51 $this->cachedir = false; 52 } else { 53 $this->cachedir = true; 54 } 55 56 if (function_exists('io_makefiledir')) { 57 runkit_function_rename('io_makefiledir', 'io_makefiledir_real'); 58 } 59 runkit_function_rename('xhtml_htmlphp_test_io_makefiledir','io_makefiledir'); 60 61 if (function_exists('io_savefile')) { 62 runkit_function_rename('io_savefile', 'io_savefile_real'); 63 } 64 runkit_function_rename('xhtml_htmlphp_test_io_savefile','io_savefile'); 65 66 runkit_method_rename('GeSHi','parse_code','parse_code_real'); 67 runkit_method_add('GeSHi','parse_code','', '{ return hsc($this->source); }'); 68 69 parent::setup(); 70 } 71 72 function teardown() { 73 global $conf; 74 75 // restore purge 76 if (is_null($this->purge)) unset($_REQUEST['purge']); 77 else $_REQUEST['purge'] = $this->purge; 78 79 // restore $conf['cachedir'] if necessary 80 if (!$this->cachedir) unset($conf['cachedir']); 81 82 // restore io_functions 83 runkit_function_rename('io_makefiledir','xhtml_htmlphp_test_io_makefiledir'); 84 if (function_exists('io_makefiledir_real')) { 85 runkit_function_rename('io_makefiledir_real', 'io_makefiledir'); 86 } 87 88 runkit_function_rename('io_savefile','xhtml_htmlphp_test_io_savefile'); 89 if (function_exists('io_savefile_real')) { 90 runkit_function_rename('io_savefile_real', 'io_savefile'); 91 } 92 93 // restore GeSHi::parse_code 94 runkit_method_remove('GeSHi','parse_code'); 95 runkit_method_rename('GeSHi','parse_code_real','parse_code'); 96 97 parent::setup(); 98 } 99 100 function _run_parser($modes,$data) { 101 102 foreach ($modes as $mode => $name) { 103 $class = 'Doku_Parser_Mode_'.$name; 104 $this->P->addMode($mode,new $class()); 105 } 106 107 $R = new Doku_Renderer_tester(); 108 $this->P->parse($data); 109 foreach ( $this->H->calls as $instruction ) { 110 // Execute the callback against the Renderer 111 call_user_func_array(array(&$R, $instruction[0]),$instruction[1]); 112 } 113 114 return str_replace("\n",'',$R->doc); 115 } 116 117 function test_html_off(){ 118 $test = array('<html><b>bold</b></html>','<p><code class="code html4strict"><b>bold</b></code></p>'); 119 120 global $conf; 121 $conf['htmlok'] = 0; 122 123 $result = $this->_run_parser(array('html'=>'html'),$test[0]); 124 125 $this->assertEqual($result,$test[1]); 126 } 127 128 function test_html_on(){ 129 $test = array('<html><b>bold</b></html>','<p><b>bold</b></p>'); 130 131 global $conf; 132 $conf['htmlok'] = 1; 133 134 $result = $this->_run_parser(array('html'=>'html'),$test[0]); 135 136 $this->assertEqual($result,$test[1]); 137 } 138 139 function test_htmlblock_off(){ 140 $test = array('<HTML><b>bold</b></HTML>','<pre class="code html4strict"><b>bold</b></pre>'); 141 142 global $conf; 143 $conf['htmlok'] = 0; 144 145 $result = $this->_run_parser(array('html'=>'html'),$test[0]); 146 147 $this->assertEqual($result,$test[1]); 148 } 149 150 function test_htmlblock_on(){ 151 $test = array('<HTML><b>bold</b></HTML>','<b>bold</b>'); 152 153 global $conf; 154 $conf['htmlok'] = 1; 155 156 $result = $this->_run_parser(array('html'=>'html'),$test[0]); 157 158 $this->assertEqual($result,$test[1]); 159 } 160 161 function test_php_off(){ 162 $test = array('<php>echo(1+1);</php>','<p><code class="code php">echo(1+1);</code></p>'); 163 164 global $conf; 165 $conf['phpok'] = 0; 166 167 $result = $this->_run_parser(array('php'=>'php'),$test[0]); 168 169 $this->assertEqual($result,$test[1]); 170 } 171 172 function test_php_on(){ 173 $test = array('<php>echo(1+1);</php>','<p>2</p>'); 174 175 global $conf; 176 $conf['phpok'] = 1; 177 178 $result = $this->_run_parser(array('php'=>'php'),$test[0]); 179 180 $this->assertEqual($result,$test[1]); 181 } 182 183 function test_phpblock_off(){ 184 $test = array('<PHP>echo(1+1);</PHP>','<pre class="code php">echo(1+1);</pre>'); 185 186 global $conf; 187 $conf['phpok'] = 0; 188 189 $result = $this->_run_parser(array('php'=>'php'),$test[0]); 190 191 $this->assertEqual($result,$test[1]); 192 } 193 194 function test_phpblock_on(){ 195 $test = array('<PHP>echo(1+1);</PHP>',"2"); 196 197 global $conf; 198 $conf['phpok'] = 1; 199 200 $result = $this->_run_parser(array('php'=>'php'),$test[0]); 201 202 $this->assertEqual($result,$test[1]); 203 } 204 205 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Fri Nov 21 01:30:02 2008 | Cross-referenced by PHPXref 0.7 |