[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

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

   1  <?php
   2  
   3  use dokuwiki\Parsing\ParserMode\Code;
   4  use dokuwiki\Parsing\ParserMode\Eol;
   5  use dokuwiki\Parsing\ParserMode\File;
   6  use dokuwiki\Parsing\ParserMode\Header;
   7  use dokuwiki\Parsing\ParserMode\Html;
   8  use dokuwiki\Parsing\ParserMode\Listblock;
   9  use dokuwiki\Parsing\ParserMode\Php;
  10  use dokuwiki\Parsing\ParserMode\Preformatted;
  11  
  12  require_once  'parser.inc.php';
  13  
  14  class TestOfDoku_Parser_Preformatted extends TestOfDoku_Parser {
  15  
  16      function testFile() {
  17          $this->P->addMode('file',new File());
  18          $this->P->parse('Foo <file>testing</file> Bar');
  19          $calls = array (
  20              array('document_start',array()),
  21              array('p_open',array()),
  22              array('cdata',array("\n".'Foo ')),
  23              array('p_close',array()),
  24              array('file',array('testing',null,null)),
  25              array('p_open',array()),
  26              array('cdata',array(' Bar')),
  27              array('p_close',array()),
  28              array('document_end',array()),
  29          );
  30  
  31          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
  32      }
  33  
  34      function testCode() {
  35          $this->P->addMode('code',new Code());
  36          $this->P->parse('Foo <code>testing</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('testing', null, 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 testCodeWhitespace() {
  52          $this->P->addMode('code',new Code());
  53          $this->P->parse("Foo <code \n>testing</code> Bar");
  54          $calls = array (
  55              array('document_start',array()),
  56              array('p_open',array()),
  57              array('cdata',array("\n".'Foo ')),
  58              array('p_close',array()),
  59              array('code',array('testing', null, null)),
  60              array('p_open',array()),
  61              array('cdata',array(' Bar')),
  62              array('p_close',array()),
  63              array('document_end',array()),
  64          );
  65          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
  66      }
  67  
  68      function testCodeLang() {
  69          $this->P->addMode('code',new Code());
  70          $this->P->parse("Foo <code php>testing</code> Bar");
  71          $calls = array (
  72              array('document_start',array()),
  73              array('p_open',array()),
  74              array('cdata',array("\n".'Foo ')),
  75              array('p_close',array()),
  76              array('code',array('testing', 'php', null)),
  77              array('p_open',array()),
  78              array('cdata',array(' Bar')),
  79              array('p_close',array()),
  80              array('document_end',array()),
  81          );
  82          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
  83      }
  84  
  85      function testPreformatted() {
  86          $this->P->addMode('preformatted',new Preformatted());
  87          $this->P->parse("F  oo\n  x  \n    y  \nBar\n");
  88          $calls = array (
  89              array('document_start',array()),
  90              array('p_open',array()),
  91              array('cdata',array("\nF  oo")),
  92              array('p_close',array()),
  93              array('preformatted',array("x  \n  y  ")),
  94              array('p_open',array()),
  95              array('cdata',array('Bar')),
  96              array('p_close',array()),
  97              array('document_end',array()),
  98          );
  99          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
 100      }
 101  
 102      function testPreformattedWinEOL() {
 103          $this->P->addMode('preformatted',new Preformatted());
 104          $this->P->parse("F  oo\r\n  x  \r\n    y  \r\nBar\r\n");
 105          $calls = array (
 106              array('document_start',array()),
 107              array('p_open',array()),
 108              array('cdata',array("\nF  oo")),
 109              array('p_close',array()),
 110              array('preformatted',array("x  \n  y  ")),
 111              array('p_open',array()),
 112              array('cdata',array('Bar')),
 113              array('p_close',array()),
 114              array('document_end',array()),
 115          );
 116          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
 117      }
 118  
 119      function testPreformattedTab() {
 120          $this->P->addMode('preformatted',new Preformatted());
 121          $this->P->parse("F  oo\n\tx\t\n\t\ty\t\nBar\n");
 122          $calls = array (
 123              array('document_start',array()),
 124              array('p_open',array()),
 125              array('cdata',array("\nF  oo")),
 126              array('p_close',array()),
 127              array('preformatted',array("x\t\n\ty\t")),
 128              array('p_open',array()),
 129              array('cdata',array("Bar")),
 130              array('p_close',array()),
 131              array('document_end',array()),
 132          );
 133          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
 134      }
 135  
 136      function testPreformattedTabWinEOL() {
 137          $this->P->addMode('preformatted',new Preformatted());
 138          $this->P->parse("F  oo\r\n\tx\t\r\n\t\ty\t\r\nBar\r\n");
 139          $calls = array (
 140              array('document_start',array()),
 141              array('p_open',array()),
 142              array('cdata',array("\nF  oo")),
 143              array('p_close',array()),
 144              array('preformatted',array("x\t\n\ty\t")),
 145              array('p_open',array()),
 146              array('cdata',array("Bar")),
 147              array('p_close',array()),
 148              array('document_end',array()),
 149          );
 150          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
 151      }
 152  
 153      function testPreformattedList() {
 154          $this->P->addMode('preformatted',new Preformatted());
 155          $this->P->addMode('listblock',new Listblock());
 156          $this->P->parse("  - x \n  * y \nF  oo\n  x  \n    y  \n  -X\n  *Y\nBar\n");
 157          $calls = array (
 158              array('document_start',array()),
 159              array('listo_open',array()),
 160              array('listitem_open',array(1)),
 161              array('listcontent_open',array()),
 162              array('cdata',array(" x ")),
 163              array('listcontent_close',array()),
 164              array('listitem_close',array()),
 165              array('listo_close',array()),
 166              array('listu_open',array()),
 167              array('listitem_open',array(1)),
 168              array('listcontent_open',array()),
 169              array('cdata',array(" y ")),
 170              array('listcontent_close',array()),
 171              array('listitem_close',array()),
 172              array('listu_close',array()),
 173              array('p_open',array()),
 174              array('cdata',array("F  oo")),
 175              array('p_close',array()),
 176              array('preformatted',array("x  \n  y  \n-X\n*Y")),
 177              array('p_open',array()),
 178              array('cdata',array("Bar")),
 179              array('p_close',array()),
 180              array('document_end',array()),
 181          );
 182          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
 183      }
 184  
 185      // test for php
 186      function testPHP() {
 187  
 188          $this->P->addMode('php',new Php());
 189          $this->P->parse('Foo <php>testing</php> Bar');
 190          $calls = array (
 191              array('document_start',array()),
 192              array('p_open',array()),
 193              array('cdata',array("\n".'Foo ')),
 194              array('php',array('testing')),
 195              array('cdata',array(' Bar')),
 196              array('p_close',array()),
 197              array('document_end',array()),
 198          );
 199          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
 200      }
 201  
 202      // test with for HTML
 203      function testHTML() {
 204  
 205          $this->P->addMode('html',new Html());
 206          $this->P->parse('Foo <html>testing</html> Bar');
 207          $calls = array (
 208              array('document_start',array()),
 209              array('p_open',array()),
 210              array('cdata',array("\n".'Foo ')),
 211              array('html',array('testing')),
 212              array('cdata',array(' Bar')),
 213              array('p_close',array()),
 214              array('document_end',array()),
 215          );
 216          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
 217      }
 218  
 219  
 220  
 221      function testPreformattedPlusHeaderAndEol() {
 222          // Note that EOL must come after preformatted!
 223          $this->P->addMode('preformatted',new Preformatted());
 224          $this->P->addMode('header',new Header());
 225          $this->P->addMode('eol',new Eol());
 226          $this->P->parse("F  oo\n  ==Test==\n    y  \nBar\n");
 227          $calls = array (
 228              array('document_start',array()),
 229              array('p_open',array()),
 230              array('cdata',array("F  oo")),
 231              array('p_close',array()),
 232              array('preformatted',array("==Test==\n  y  ")),
 233              array('p_open',array()),
 234              array('cdata',array('Bar')),
 235              array('p_close',array()),
 236              array('document_end',array()),
 237          );
 238          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
 239      }
 240  }
 241