[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/_test/tests/inc/parser/ -> parser_code.test.php (source)

   1  <?php
   2  
   3  use dokuwiki\Parsing\ParserMode\Code;
   4  
   5  require_once  'parser.inc.php';
   6  
   7  /**
   8   * Tests to ensure functionality of the <code> syntax tag.
   9   *
  10   * @group parser_code
  11   */
  12  class TestOfDoku_Parser_Code extends TestOfDoku_Parser {
  13  
  14      function setUp() {
  15          parent::setUp();
  16          $this->P->addMode('code',new Code());
  17      }
  18  
  19      function testCode() {
  20          $this->P->parse('Foo <code>Test</code> Bar');
  21          $calls = array (
  22              array('document_start',array()),
  23              array('p_open',array()),
  24              array('cdata',array("\n".'Foo ')),
  25              array('p_close',array()),
  26              array('code',array('Test',null,null)),
  27              array('p_open',array()),
  28              array('cdata',array(' Bar')),
  29              array('p_close',array()),
  30              array('document_end',array()),
  31          );
  32          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
  33      }
  34  
  35      function testCodeBash() {
  36          $this->P->parse('Foo <code bash>Test</code> Bar');
  37          $calls = array (
  38              array('document_start',array()),
  39              array('p_open',array()),
  40              array('cdata',array("\n".'Foo ')),
  41              array('p_close',array()),
  42              array('code',array('Test','bash',null)),
  43              array('p_open',array()),
  44              array('cdata',array(' Bar')),
  45              array('p_close',array()),
  46              array('document_end',array()),
  47          );
  48          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
  49      }
  50  
  51      function testCodeDownload() {
  52          $this->P->parse('Foo <code bash script.sh>Test</code> Bar');
  53          $calls = array (
  54              array('document_start',array()),
  55              array('p_open',array()),
  56              array('cdata',array("\n".'Foo ')),
  57              array('p_close',array()),
  58              array('code',array('Test','bash','script.sh')),
  59              array('p_open',array()),
  60              array('cdata',array(' Bar')),
  61              array('p_close',array()),
  62              array('document_end',array()),
  63          );
  64          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
  65      }
  66  
  67      function testCodeToken() {
  68          $this->P->parse('Foo <code2>Bar</code2><code>Test</code>');
  69          $calls = array (
  70              array('document_start',array()),
  71              array('p_open',array()),
  72              array('cdata',array("\n".'Foo <code2>Bar</code2>')),
  73              array('p_close',array()),
  74              array('code',array('Test',null,null)),
  75              array('document_end',array()),
  76          );
  77          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
  78      }
  79  
  80      function testCodeOptionsArray_OneOption() {
  81          $this->P->parse('Foo <code C [enable_line_numbers]>Test</code> Bar');
  82          $calls = array (
  83              array('document_start',array()),
  84              array('p_open',array()),
  85              array('cdata',array("\n".'Foo ')),
  86              array('p_close',array()),
  87              array('code',array('Test','C', null,
  88                                 array('enable_line_numbers' => 1)
  89                                 )),
  90              array('p_open',array()),
  91              array('cdata',array(' Bar')),
  92              array('p_close',array()),
  93              array('document_end',array()),
  94          );
  95          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
  96      }
  97  
  98      function testCodeOptionsArray_TwoOptions() {
  99          $this->P->parse('Foo <code C [enable_line_numbers highlight_lines_extra="3"]>Test</code> Bar');
 100          $calls = array (
 101              array('document_start',array()),
 102              array('p_open',array()),
 103              array('cdata',array("\n".'Foo ')),
 104              array('p_close',array()),
 105              array('code',array('Test','C', null,
 106                                 array('enable_line_numbers' => true,
 107                                       'highlight_lines_extra' => array(3)
 108                                 ))),
 109              array('p_open',array()),
 110              array('cdata',array(' Bar')),
 111              array('p_close',array()),
 112              array('document_end',array()),
 113          );
 114          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
 115      }
 116  
 117      function testCodeOptionsArray_UnknownOption() {
 118          $this->P->parse('Foo <code C [unknown="I will be deleted/ignored!"]>Test</code> Bar');
 119          $calls = array (
 120              array('document_start',array()),
 121              array('p_open',array()),
 122              array('cdata',array("\n".'Foo ')),
 123              array('p_close',array()),
 124              array('code',array('Test','C', null, null)),
 125              array('p_open',array()),
 126              array('cdata',array(' Bar')),
 127              array('p_close',array()),
 128              array('document_end',array()),
 129          );
 130          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
 131      }
 132  
 133      function testCodeOptionsArray_EnableLineNumbers1() {
 134          $this->P->parse('Foo <code C [enable_line_numbers]>Test</code> Bar');
 135          $calls = array (
 136              array('document_start',array()),
 137              array('p_open',array()),
 138              array('cdata',array("\n".'Foo ')),
 139              array('p_close',array()),
 140              array('code',array('Test','C', null,
 141                                 array('enable_line_numbers' => true)
 142                                 )),
 143              array('p_open',array()),
 144              array('cdata',array(' Bar')),
 145              array('p_close',array()),
 146              array('document_end',array()),
 147          );
 148          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
 149      }
 150  
 151      function testCodeOptionsArray_EnableLineNumbers2() {
 152          $this->P->parse('Foo <code C [enable_line_numbers="1"]>Test</code> Bar');
 153          $calls = array (
 154              array('document_start',array()),
 155              array('p_open',array()),
 156              array('cdata',array("\n".'Foo ')),
 157              array('p_close',array()),
 158              array('code',array('Test','C', null,
 159                                 array('enable_line_numbers' => true)
 160                                 )),
 161              array('p_open',array()),
 162              array('cdata',array(' Bar')),
 163              array('p_close',array()),
 164              array('document_end',array()),
 165          );
 166          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
 167      }
 168  
 169      function testCodeOptionsArray_EnableLineNumbers3() {
 170          $this->P->parse('Foo <code C [enable_line_numbers="0"]>Test</code> Bar');
 171          $calls = array (
 172              array('document_start',array()),
 173              array('p_open',array()),
 174              array('cdata',array("\n".'Foo ')),
 175              array('p_close',array()),
 176              array('code',array('Test','C', null,
 177                                 array('enable_line_numbers' => false)
 178                                 )),
 179              array('p_open',array()),
 180              array('cdata',array(' Bar')),
 181              array('p_close',array()),
 182              array('document_end',array()),
 183          );
 184          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
 185      }
 186  
 187      function testCodeOptionsArray_EnableLineNumbers4() {
 188          $this->P->parse('Foo <code C [enable_line_numbers=""]>Test</code> Bar');
 189          $calls = array (
 190              array('document_start',array()),
 191              array('p_open',array()),
 192              array('cdata',array("\n".'Foo ')),
 193              array('p_close',array()),
 194              array('code',array('Test','C', null,
 195                                 array('enable_line_numbers' => true)
 196                                 )),
 197              array('p_open',array()),
 198              array('cdata',array(' Bar')),
 199              array('p_close',array()),
 200              array('document_end',array()),
 201          );
 202          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
 203      }
 204  
 205      function testCodeOptionsArray_HighlightLinesExtra1() {
 206          $this->P->parse('Foo <code C [enable_line_numbers highlight_lines_extra="42, 123, 456, 789"]>Test</code> Bar');
 207          $calls = array (
 208              array('document_start',array()),
 209              array('p_open',array()),
 210              array('cdata',array("\n".'Foo ')),
 211              array('p_close',array()),
 212              array('code',array('Test','C', null,
 213                                 array('enable_line_numbers' => true,
 214                                       'highlight_lines_extra' => array(42, 123, 456, 789)
 215                                 ))),
 216              array('p_open',array()),
 217              array('cdata',array(' Bar')),
 218              array('p_close',array()),
 219              array('document_end',array()),
 220          );
 221          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
 222      }
 223  
 224      function testCodeOptionsArray_HighlightLinesExtra2() {
 225          $this->P->parse('Foo <code C [enable_line_numbers highlight_lines_extra]>Test</code> Bar');
 226          $calls = array (
 227              array('document_start',array()),
 228              array('p_open',array()),
 229              array('cdata',array("\n".'Foo ')),
 230              array('p_close',array()),
 231              array('code',array('Test','C', null,
 232                                 array('enable_line_numbers' => true,
 233                                       'highlight_lines_extra' => array(1))
 234                                 )),
 235              array('p_open',array()),
 236              array('cdata',array(' Bar')),
 237              array('p_close',array()),
 238              array('document_end',array()),
 239          );
 240          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
 241      }
 242  
 243      function testCodeOptionsArray_HighlightLinesExtra3() {
 244          $this->P->parse('Foo <code C [enable_line_numbers highlight_lines_extra=""]>Test</code> Bar');
 245          $calls = array (
 246              array('document_start',array()),
 247              array('p_open',array()),
 248              array('cdata',array("\n".'Foo ')),
 249              array('p_close',array()),
 250              array('code',array('Test','C', null,
 251                                 array('enable_line_numbers' => true,
 252                                       'highlight_lines_extra' => array(1))
 253                                 )),
 254              array('p_open',array()),
 255              array('cdata',array(' Bar')),
 256              array('p_close',array()),
 257              array('document_end',array()),
 258          );
 259          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
 260      }
 261  
 262      function testCodeOptionsArray_StartLineNumbersAt1() {
 263          $this->P->parse('Foo <code C [enable_line_numbers [enable_line_numbers start_line_numbers_at="42"]]>Test</code> Bar');
 264          $calls = array (
 265              array('document_start',array()),
 266              array('p_open',array()),
 267              array('cdata',array("\n".'Foo ')),
 268              array('p_close',array()),
 269              array('code',array('Test','C', null,
 270                                 array('enable_line_numbers' => true,
 271                                       'start_line_numbers_at' => 42)
 272                                 )),
 273              array('p_open',array()),
 274              array('cdata',array(' Bar')),
 275              array('p_close',array()),
 276              array('document_end',array()),
 277          );
 278          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
 279      }
 280  
 281      function testCodeOptionsArray_StartLineNumbersAt2() {
 282          $this->P->parse('Foo <code C [enable_line_numbers [enable_line_numbers start_line_numbers_at]]>Test</code> Bar');
 283          $calls = array (
 284              array('document_start',array()),
 285              array('p_open',array()),
 286              array('cdata',array("\n".'Foo ')),
 287              array('p_close',array()),
 288              array('code',array('Test','C', null,
 289                                 array('enable_line_numbers' => true,
 290                                       'start_line_numbers_at' => 1)
 291                                 )),
 292              array('p_open',array()),
 293              array('cdata',array(' Bar')),
 294              array('p_close',array()),
 295              array('document_end',array()),
 296          );
 297          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
 298      }
 299  
 300      function testCodeOptionsArray_StartLineNumbersAt3() {
 301          $this->P->parse('Foo <code C [enable_line_numbers [enable_line_numbers start_line_numbers_at=""]]>Test</code> Bar');
 302          $calls = array (
 303              array('document_start',array()),
 304              array('p_open',array()),
 305              array('cdata',array("\n".'Foo ')),
 306              array('p_close',array()),
 307              array('code',array('Test','C', null,
 308                                 array('enable_line_numbers' => true,
 309                                       'start_line_numbers_at' => 1)
 310                                 )),
 311              array('p_open',array()),
 312              array('cdata',array(' Bar')),
 313              array('p_close',array()),
 314              array('document_end',array()),
 315          );
 316          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
 317      }
 318  
 319      function testCodeOptionsArray_EnableKeywordLinks1() {
 320          $this->P->parse('Foo <code C [enable_keyword_links="false"]>Test</code> Bar');
 321          $calls = array (
 322              array('document_start',array()),
 323              array('p_open',array()),
 324              array('cdata',array("\n".'Foo ')),
 325              array('p_close',array()),
 326              array('code',array('Test','C', null,
 327                                 array('enable_keyword_links' => false)
 328                                 )),
 329              array('p_open',array()),
 330              array('cdata',array(' Bar')),
 331              array('p_close',array()),
 332              array('document_end',array()),
 333          );
 334          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
 335      }
 336  
 337      function testCodeOptionsArray_EnableKeywordLinks2() {
 338          $this->P->parse('Foo <code C [enable_keyword_links="true"]>Test</code> Bar');
 339          $calls = array (
 340              array('document_start',array()),
 341              array('p_open',array()),
 342              array('cdata',array("\n".'Foo ')),
 343              array('p_close',array()),
 344              array('code',array('Test','C', null,
 345                                 array('enable_keyword_links' => true)
 346                                 )),
 347              array('p_open',array()),
 348              array('cdata',array(' Bar')),
 349              array('p_close',array()),
 350              array('document_end',array()),
 351          );
 352          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
 353      }
 354  
 355  }
 356