[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

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

   1  <?php
   2  
   3  use dokuwiki\Parsing\Handler\Lists;
   4  use dokuwiki\Parsing\ParserMode\Code;
   5  use dokuwiki\Parsing\ParserMode\Eol;
   6  use dokuwiki\Parsing\ParserMode\Footnote;
   7  use dokuwiki\Parsing\ParserMode\Formatting;
   8  use dokuwiki\Parsing\ParserMode\Hr;
   9  use dokuwiki\Parsing\ParserMode\Listblock;
  10  use dokuwiki\Parsing\ParserMode\Preformatted;
  11  use dokuwiki\Parsing\ParserMode\Quote;
  12  use dokuwiki\Parsing\ParserMode\Table;
  13  use dokuwiki\Parsing\ParserMode\Unformatted;
  14  
  15  require_once  'parser.inc.php';
  16  
  17  class TestOfDoku_Parser_Footnote extends TestOfDoku_Parser {
  18  
  19      function setUp() {
  20          parent::setUp();
  21          $this->P->addMode('footnote',new Footnote());
  22      }
  23  
  24      function testFootnote() {
  25          $this->P->parse('Foo (( testing )) Bar');
  26          $calls = array (
  27              array('document_start',array()),
  28              array('p_open',array()),
  29              array('cdata',array("\n".'Foo ')),
  30              array('nest', array ( array (
  31                array('footnote_open',array()),
  32                array('cdata',array(' testing ')),
  33                array('footnote_close',array()),
  34              ))),
  35              array('cdata',array(' Bar')),
  36              array('p_close',array()),
  37              array('document_end',array()),
  38          );
  39          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
  40      }
  41  
  42      function testNotAFootnote() {
  43          $this->P->parse("Foo (( testing\n Bar");
  44          $calls = array (
  45              array('document_start',array()),
  46              array('p_open',array()),
  47              array('cdata',array("\nFoo (( testing\n Bar")),
  48              array('p_close',array()),
  49              array('document_end',array()),
  50          );
  51          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
  52      }
  53  
  54      function testFootnoteLinefeed() {
  55          $this->P->addMode('eol',new Eol());
  56          $this->P->parse("Foo (( testing\ntesting )) Bar");
  57          $calls = array (
  58              array('document_start',array()),
  59              array('p_open',array()),
  60              array('cdata',array('Foo ')),
  61              array('nest', array ( array (
  62                array('footnote_open',array()),
  63                array('cdata',array(" testing\ntesting ")),
  64                array('footnote_close',array()),
  65              ))),
  66              array('cdata',array(' Bar')),
  67              array('p_close',array()),
  68              array('document_end',array()),
  69          );
  70          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
  71      }
  72  
  73      function testFootnoteNested() {
  74          $this->P->parse('Foo (( x((y))z )) Bar');
  75          $calls = array (
  76              array('document_start',array()),
  77              array('p_open',array()),
  78              array('cdata',array("\n".'Foo ')),
  79              array('nest', array ( array (
  80                array('footnote_open',array()),
  81                array('cdata',array(' x((y')),
  82                array('footnote_close',array()),
  83              ))),
  84              array('cdata',array('z )) Bar')),
  85              array('p_close',array()),
  86              array('document_end',array()),
  87          );
  88          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
  89      }
  90  
  91      function testFootnoteEol() {
  92          $this->P->addMode('eol',new Eol());
  93          $this->P->parse("Foo \nX(( test\ning ))Y\n Bar");
  94          $calls = array (
  95              array('document_start',array()),
  96              array('p_open',array()),
  97              array('cdata',array('Foo '.DOKU_PARSER_EOL.'X')),
  98              array('nest', array ( array (
  99                array('footnote_open',array()),
 100                array('cdata',array(" test\ning ")),
 101                array('footnote_close',array()),
 102              ))),
 103              array('cdata',array('Y'.DOKU_PARSER_EOL.' Bar')),
 104              array('p_close',array()),
 105              array('document_end',array()),
 106          );
 107          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
 108      }
 109  
 110      function testFootnoteStrong() {
 111          $this->P->addMode('strong',new Formatting('strong'));
 112          $this->P->parse('Foo (( **testing** )) Bar');
 113          $calls = array (
 114              array('document_start',array()),
 115              array('p_open',array()),
 116              array('cdata',array("\n".'Foo ')),
 117              array('nest', array ( array (
 118                array('footnote_open',array()),
 119                array('cdata',array(' ')),
 120                array('strong_open',array()),
 121                array('cdata',array('testing')),
 122                array('strong_close',array()),
 123                array('cdata',array(' ')),
 124                array('footnote_close',array()),
 125              ))),
 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 testFootnoteHr() {
 134          $this->P->addMode('hr',new Hr());
 135          $this->P->parse("Foo (( \n ---- \n )) Bar");
 136          $calls = array (
 137              array('document_start',array()),
 138              array('p_open',array()),
 139              array('cdata',array("\n".'Foo ')),
 140              array('nest', array ( array (
 141                array('footnote_open',array()),
 142                array('cdata',array(' ')),
 143                array('hr',array()),
 144                array('cdata',array("\n ")),
 145                array('footnote_close',array()),
 146              ))),
 147              array('cdata',array(' Bar')),
 148              array('p_close',array()),
 149              array('document_end',array()),
 150          );
 151          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
 152      }
 153  
 154      function testFootnoteCode() {
 155          $this->P->addMode('code',new Code());
 156          $this->P->parse("Foo (( <code>Test</code> )) Bar");
 157          $calls = array (
 158              array('document_start',array()),
 159              array('p_open',array()),
 160              array('cdata',array("\n".'Foo ')),
 161              array('nest', array ( array (
 162                array('footnote_open',array()),
 163                array('cdata',array(' ')),
 164                array('code',array('Test',null,null)),
 165                array('cdata',array(' ')),
 166                array('footnote_close',array()),
 167              ))),
 168              array('cdata',array(' Bar')),
 169              array('p_close',array()),
 170              array('document_end',array()),
 171          );
 172          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
 173      }
 174  
 175      function testFootnotePreformatted() {
 176          $this->P->addMode('preformatted',new Preformatted());
 177          $this->P->parse("Foo (( \n  Test\n )) Bar");
 178          $calls = array (
 179              array('document_start',array()),
 180              array('p_open',array()),
 181              array('cdata',array("\n".'Foo ')),
 182              array('nest', array ( array (
 183                array('footnote_open',array()),
 184                array('cdata',array(' ')),
 185                array('preformatted',array('Test')),
 186                array('cdata',array(' ')),
 187                array('footnote_close',array()),
 188              ))),
 189              array('cdata',array(' Bar')),
 190              array('p_close',array()),
 191              array('document_end',array()),
 192          );
 193          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
 194      }
 195  
 196      function testFootnotePreformattedEol() {
 197          $this->P->addMode('preformatted',new Preformatted());
 198          $this->P->addMode('eol',new Eol());
 199          $this->P->parse("Foo (( \n  Test\n )) Bar");
 200          $calls = array (
 201              array('document_start',array()),
 202              array('p_open',array()),
 203              array('cdata',array('Foo ')),
 204              array('nest', array ( array (
 205                array('footnote_open',array()),
 206                array('cdata',array(' ')),
 207                array('preformatted',array('Test')),
 208                array('cdata',array(' ')),
 209                array('footnote_close',array()),
 210              ))),
 211              array('cdata',array(' Bar')),
 212              array('p_close',array()),
 213              array('document_end',array()),
 214          );
 215  
 216          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
 217      }
 218  
 219      function testFootnoteUnformatted() {
 220          $this->P->addMode('unformatted',new Unformatted());
 221          $this->P->parse("Foo (( <nowiki>Test</nowiki> )) Bar");
 222          $calls = array (
 223              array('document_start',array()),
 224              array('p_open',array()),
 225              array('cdata',array("\n".'Foo ')),
 226              array('nest', array ( array (
 227                array('footnote_open',array()),
 228                array('cdata',array(' ')),
 229                array('unformatted',array('Test')),
 230                array('cdata',array(' ')),
 231                array('footnote_close',array()),
 232              ))),
 233              array('cdata',array(' Bar')),
 234              array('p_close',array()),
 235              array('document_end',array()),
 236          );
 237          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
 238      }
 239  
 240      function testFootnoteNotHeader() {
 241          $this->P->addMode('unformatted',new Unformatted());
 242          $this->P->parse("Foo (( \n====Test====\n )) Bar");
 243          $calls = array (
 244              array('document_start',array()),
 245              array('p_open',array()),
 246              array('cdata',array("\n".'Foo ')),
 247              array('nest', array ( array (
 248                array('footnote_open',array()),
 249                array('cdata',array(" \n====Test====\n ")),
 250                array('footnote_close',array()),
 251              ))),
 252              array('cdata',array(' Bar')),
 253              array('p_close',array()),
 254              array('document_end',array()),
 255          );
 256          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
 257      }
 258  
 259      function testFootnoteTable() {
 260          $this->P->addMode('table',new Table());
 261          $this->P->parse("Foo ((
 262  | Row 0 Col 1    | Row 0 Col 2     | Row 0 Col 3        |
 263  | Row 1 Col 1    | Row 1 Col 2     | Row 1 Col 3        |
 264   )) Bar");
 265          $calls = array (
 266              array('document_start',array()),
 267              array('p_open',array()),
 268              array('cdata',array("\n".'Foo ')),
 269              array('nest', array ( array (
 270                array('footnote_open',array()),
 271                array('table_open',array(3, 2, 8)),
 272                array('tablerow_open',array()),
 273                array('tablecell_open',array(1,'left',1)),
 274                array('cdata',array(' Row 0 Col 1    ')),
 275                array('tablecell_close',array()),
 276                array('tablecell_open',array(1,'left',1)),
 277                array('cdata',array(' Row 0 Col 2     ')),
 278                array('tablecell_close',array()),
 279                array('tablecell_open',array(1,'left',1)),
 280                array('cdata',array(' Row 0 Col 3        ')),
 281                array('tablecell_close',array()),
 282                array('tablerow_close',array()),
 283                array('tablerow_open',array()),
 284                array('tablecell_open',array(1,'left',1)),
 285                array('cdata',array(' Row 1 Col 1    ')),
 286                array('tablecell_close',array()),
 287                array('tablecell_open',array(1,'left',1)),
 288                array('cdata',array(' Row 1 Col 2     ')),
 289                array('tablecell_close',array()),
 290                array('tablecell_open',array(1,'left',1)),
 291                array('cdata',array(' Row 1 Col 3        ')),
 292                array('tablecell_close',array()),
 293                array('tablerow_close',array()),
 294                array('table_close',array(123)),
 295                array('cdata',array(' ')),
 296                array('footnote_close',array()),
 297              ))),
 298              array('cdata',array(' Bar')),
 299              array('p_close',array()),
 300              array('document_end',array()),
 301          );
 302          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
 303      }
 304  
 305      function testFootnoteList() {
 306          $this->P->addMode('listblock',new ListBlock());
 307          $this->P->parse("Foo ((
 308    *A
 309      * B
 310    * C
 311   )) Bar");
 312          $calls = array (
 313              array('document_start',array()),
 314              array('p_open',array()),
 315              array('cdata',array("\n".'Foo ')),
 316              array('nest', array ( array (
 317                array('footnote_open',array()),
 318                array('listu_open',array()),
 319                array('listitem_open',array(1,Lists::NODE)),
 320                array('listcontent_open',array()),
 321                array('cdata',array("A")),
 322                array('listcontent_close',array()),
 323                array('listu_open',array()),
 324                array('listitem_open',array(2)),
 325                array('listcontent_open',array()),
 326                array('cdata',array(' B')),
 327                array('listcontent_close',array()),
 328                array('listitem_close',array()),
 329                array('listu_close',array()),
 330                array('listitem_close',array()),
 331                array('listitem_open',array(1)),
 332                array('listcontent_open',array()),
 333                array('cdata',array(' C')),
 334                array('listcontent_close',array()),
 335                array('listitem_close',array()),
 336                array('listu_close',array()),
 337                array('cdata',array(' ')),
 338                array('footnote_close',array()),
 339              ))),
 340              array('cdata',array(' Bar')),
 341              array('p_close',array()),
 342              array('document_end',array()),
 343          );
 344          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
 345      }
 346  
 347      function testFootnoteQuote() {
 348          $this->P->addMode('quote',new Quote());
 349          $this->P->parse("Foo ((
 350  > def
 351  >>ghi
 352   )) Bar");
 353          $calls = array (
 354              array('document_start',array()),
 355              array('p_open',array()),
 356              array('cdata',array("\n".'Foo ')),
 357              array('nest', array ( array (
 358                array('footnote_open',array()),
 359                array('quote_open',array()),
 360                array('cdata',array(" def")),
 361                array('quote_open',array()),
 362                array('cdata',array("ghi")),
 363                array('quote_close',array()),
 364                array('quote_close',array()),
 365                array('cdata',array(' ')),
 366                array('footnote_close',array()),
 367              ))),
 368              array('cdata',array(' Bar')),
 369              array('p_close',array()),
 370              array('document_end',array()),
 371          );
 372  
 373          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
 374      }
 375  
 376      function testFootnoteNesting() {
 377          $this->P->addMode('strong',new Formatting('strong'));
 378          $this->P->parse("(( a ** (( b )) ** c ))");
 379  
 380          $calls = array(
 381              array('document_start',array()),
 382              array('p_open',array()),
 383              array('cdata',array("\n")),
 384              array('nest', array ( array (
 385                array('footnote_open',array()),
 386                array('cdata',array(' a ')),
 387                array('strong_open',array()),
 388                array('cdata',array(' (( b ')),
 389                array('footnote_close',array()),
 390              ))),
 391              array('cdata',array(" ")),
 392              array('strong_close',array()),
 393              array('cdata',array(" c ))")),
 394              array('p_close',array()),
 395              array('document_end',array()),
 396          );
 397  
 398          $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
 399      }
 400  }
 401