[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

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

   1  <?php
   2  
   3  use dokuwiki\Parsing\ParserMode\Camelcaselink;
   4  use dokuwiki\Parsing\ParserMode\Emaillink;
   5  use dokuwiki\Parsing\ParserMode\Externallink;
   6  use dokuwiki\Parsing\ParserMode\Filelink;
   7  use dokuwiki\Parsing\ParserMode\Internallink;
   8  use dokuwiki\Parsing\ParserMode\Media;
   9  use dokuwiki\Parsing\ParserMode\Windowssharelink;
  10  
  11  require_once  'parser.inc.php';
  12  
  13  /**
  14   * Tests for the implementation of link syntax
  15   *
  16   * @group parser_links
  17  */
  18  class TestOfDoku_Parser_Links extends TestOfDoku_Parser {
  19  
  20      function testExternalLinkSimple() {
  21          $this->P->addMode('externallink',new Externallink());
  22          $this->P->parse("Foo http://www.google.com Bar");
  23          $calls = array (
  24              array('document_start',array()),
  25              array('p_open',array()),
  26              array('cdata',array("\n".'Foo ')),
  27              array('externallink',array('http://www.google.com', NULL)),
  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 testExternalLinkCase() {
  36          $this->P->addMode('externallink',new Externallink());
  37          $this->P->parse("Foo HTTP://WWW.GOOGLE.COM Bar");
  38          $calls = array (
  39              array('document_start',array()),
  40              array('p_open',array()),
  41              array('cdata',array("\n".'Foo ')),
  42              array('externallink',array('HTTP://WWW.GOOGLE.COM', NULL)),
  43              array('cdata',array(' Bar')),
  44              array('p_close',array()),
  45              array('document_end',array()),
  46          );
  47          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
  48      }
  49  
  50      function testExternalIPv4() {
  51          $this->P->addMode('externallink',new Externallink());
  52          $this->P->parse("Foo http://123.123.3.21/foo Bar");
  53          $calls = array (
  54              array('document_start',array()),
  55              array('p_open',array()),
  56              array('cdata',array("\n".'Foo ')),
  57              array('externallink',array('http://123.123.3.21/foo', NULL)),
  58              array('cdata',array(' Bar')),
  59              array('p_close',array()),
  60              array('document_end',array()),
  61          );
  62          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
  63      }
  64  
  65      function testExternalIPv6() {
  66          $this->P->addMode('externallink',new Externallink());
  67          $this->P->parse("Foo http://[3ffe:2a00:100:7031::1]/foo Bar");
  68          $calls = array (
  69              array('document_start',array()),
  70              array('p_open',array()),
  71              array('cdata',array("\n".'Foo ')),
  72              array('externallink',array('http://[3ffe:2a00:100:7031::1]/foo', NULL)),
  73              array('cdata',array(' Bar')),
  74              array('p_close',array()),
  75              array('document_end',array()),
  76          );
  77          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
  78      }
  79  
  80      function testExternalMulti(){
  81          $this->teardown();
  82  
  83          $links = array(
  84              'http://www.google.com',
  85              'HTTP://WWW.GOOGLE.COM',
  86              'http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html',
  87              'http://[1080:0:0:0:8:800:200C:417A]/index.html',
  88              'http://[3ffe:2a00:100:7031::1]',
  89              'http://[1080::8:800:200C:417A]/foo',
  90              'http://[::192.9.5.5]/ipng',
  91              'http://[::FFFF:129.144.52.38]:80/index.html',
  92              'http://[2010:836B:4179::836B:4179]',
  93          );
  94          $titles = array(false,null,'foo bar');
  95          foreach($links as $link){
  96              foreach($titles as $title){
  97                  if($title === false){
  98                      $source = $link;
  99                      $name   = null;
 100                  }elseif($title === null){
 101                      $source = "[[$link]]";
 102                      $name   = null;
 103                  }else{
 104                      $source = "[[$link|$title]]";
 105                      $name   = $title;
 106                  }
 107                  $this->setup();
 108                  $this->P->addMode('internallink',new Internallink());
 109                  $this->P->addMode('externallink',new Externallink());
 110                  $this->P->parse("Foo $source Bar");
 111                  $calls = array (
 112                      array('document_start',array()),
 113                      array('p_open',array()),
 114                      array('cdata',array("\n".'Foo ')),
 115                      array('externallink',array($link, $name)),
 116                      array('cdata',array(' Bar')),
 117                      array('p_close',array()),
 118                      array('document_end',array()),
 119                  );
 120                  $this->assertEquals(array_map('stripByteIndex',$this->H->calls), $calls, $source);
 121                  $this->teardown();
 122              }
 123          }
 124  
 125          $this->setup();
 126      }
 127  
 128      function testExternalLinkJavascript() {
 129          $this->P->addMode('externallink',new Externallink());
 130          $this->P->parse("Foo javascript:alert('XSS'); Bar");
 131          $calls = array (
 132              array('document_start',array()),
 133              array('p_open',array()),
 134              array('cdata',array("\nFoo javascript:alert('XSS'); Bar")),
 135              array('p_close',array()),
 136              array('document_end',array()),
 137          );
 138          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 139      }
 140  
 141      function testExternalWWWLink() {
 142          $this->P->addMode('externallink',new Externallink());
 143          $this->P->parse("Foo www.google.com Bar");
 144          $calls = array (
 145              array('document_start',array()),
 146              array('p_open',array()),
 147              array('cdata',array("\n".'Foo ')),
 148              array('externallink',array('http://www.google.com', 'www.google.com')),
 149              array('cdata',array(' Bar')),
 150              array('p_close',array()),
 151              array('document_end',array()),
 152          );
 153          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 154      }
 155  
 156      function testExternalWWWLinkInPath() {
 157          $this->P->addMode('externallink',new Externallink());
 158          // See issue #936. Should NOT generate a link!
 159          $this->P->parse("Foo /home/subdir/www/www.something.de/somedir/ Bar");
 160          $calls = array (
 161              array('document_start',array()),
 162              array('p_open',array()),
 163              array('cdata',array("\n".'Foo /home/subdir/www/www.something.de/somedir/ Bar')),
 164              array('p_close',array()),
 165              array('document_end',array()),
 166          );
 167          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 168      }
 169  
 170      function testExternalWWWLinkFollowingPath() {
 171          $this->P->addMode('externallink',new Externallink());
 172          $this->P->parse("Foo /home/subdir/www/ www.something.de/somedir/ Bar");
 173          $calls = array (
 174              array('document_start',array()),
 175              array('p_open',array()),
 176              array('cdata',array("\n".'Foo /home/subdir/www/ ')),
 177              array('externallink',array('http://www.something.de/somedir/', 'www.something.de/somedir/')),
 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      function testExternalFTPLink() {
 186          $this->P->addMode('externallink',new Externallink());
 187          $this->P->parse("Foo ftp.sunsite.com Bar");
 188          $calls = array (
 189              array('document_start',array()),
 190              array('p_open',array()),
 191              array('cdata',array("\n".'Foo ')),
 192              array('externallink',array('ftp://ftp.sunsite.com', 'ftp.sunsite.com')),
 193              array('cdata',array(' Bar')),
 194              array('p_close',array()),
 195              array('document_end',array()),
 196          );
 197          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 198      }
 199  
 200      function testExternalFTPLinkInPath() {
 201          $this->P->addMode('externallink',new Externallink());
 202          // See issue #936. Should NOT generate a link!
 203          $this->P->parse("Foo /home/subdir/www/ftp.something.de/somedir/ Bar");
 204          $calls = array (
 205              array('document_start',array()),
 206              array('p_open',array()),
 207              array('cdata',array("\n".'Foo /home/subdir/www/ftp.something.de/somedir/ Bar')),
 208              array('p_close',array()),
 209              array('document_end',array()),
 210          );
 211          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 212      }
 213  
 214      function testExternalFTPLinkFollowingPath() {
 215          $this->P->addMode('externallink',new Externallink());
 216          $this->P->parse("Foo /home/subdir/www/ ftp.something.de/somedir/ Bar");
 217          $calls = array (
 218              array('document_start',array()),
 219              array('p_open',array()),
 220              array('cdata',array("\n".'Foo /home/subdir/www/ ')),
 221              array('externallink',array('ftp://ftp.something.de/somedir/', 'ftp.something.de/somedir/')),
 222              array('cdata',array(' Bar')),
 223              array('p_close',array()),
 224              array('document_end',array()),
 225          );
 226          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 227      }
 228  
 229      function testEmail() {
 230          $this->P->addMode('emaillink',new Emaillink());
 231          $this->P->parse("Foo <bugs@php.net> Bar");
 232          $calls = array (
 233              array('document_start',array()),
 234              array('p_open',array()),
 235              array('cdata',array("\n".'Foo ')),
 236              array('emaillink',array('bugs@php.net', NULL)),
 237              array('cdata',array(' Bar')),
 238              array('p_close',array()),
 239              array('document_end',array()),
 240          );
 241          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 242      }
 243  
 244      function testEmailRFC2822() {
 245          $this->P->addMode('emaillink',new Emaillink());
 246          $this->P->parse("Foo <~fix+bug's.for/ev{e}r@php.net> Bar");
 247          $calls = array (
 248              array('document_start',array()),
 249              array('p_open',array()),
 250              array('cdata',array("\n".'Foo ')),
 251              array('emaillink',array("~fix+bug's.for/ev{e}r@php.net", NULL)),
 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 testEmailCase() {
 260          $this->P->addMode('emaillink',new Emaillink());
 261          $this->P->parse("Foo <bugs@pHp.net> Bar");
 262          $calls = array (
 263              array('document_start',array()),
 264              array('p_open',array()),
 265              array('cdata',array("\n".'Foo ')),
 266              array('emaillink',array('bugs@pHp.net', NULL)),
 267              array('cdata',array(' Bar')),
 268              array('p_close',array()),
 269              array('document_end',array()),
 270          );
 271          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 272      }
 273  
 274  
 275      function testInternalLinkOneChar() {
 276          $this->P->addMode('internallink',new Internallink());
 277          $this->P->parse("Foo [[l]] Bar");
 278          $calls = array (
 279              array('document_start',array()),
 280              array('p_open',array()),
 281              array('cdata',array("\n".'Foo ')),
 282              array('internallink',array('l',NULL)),
 283              array('cdata',array(' Bar')),
 284              array('p_close',array()),
 285              array('document_end',array()),
 286          );
 287          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 288      }
 289  
 290      function testInternalLinkNoChar() {
 291          $this->P->addMode('internallink',new Internallink());
 292          $this->P->parse("Foo [[]] Bar");
 293          $calls = array (
 294              array('document_start',array()),
 295              array('p_open',array()),
 296              array('cdata',array("\n".'Foo ')),
 297              array('internallink',array('',NULL)),
 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 testInternalLinkNamespaceNoTitle() {
 306          $this->P->addMode('internallink',new Internallink());
 307          $this->P->parse("Foo [[foo:bar]] Bar");
 308          $calls = array (
 309              array('document_start',array()),
 310              array('p_open',array()),
 311              array('cdata',array("\n".'Foo ')),
 312              array('internallink',array('foo:bar',NULL)),
 313              array('cdata',array(' Bar')),
 314              array('p_close',array()),
 315              array('document_end',array()),
 316          );
 317          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 318      }
 319  
 320      function testInternalLinkNamespace() {
 321          $this->P->addMode('internallink',new Internallink());
 322          $this->P->parse("Foo [[x:1:y:foo_bar:z|Test]] Bar");
 323          $calls = array (
 324              array('document_start',array()),
 325              array('p_open',array()),
 326              array('cdata',array("\n".'Foo ')),
 327              array('internallink',array('x:1:y:foo_bar:z','Test')),
 328              array('cdata',array(' Bar')),
 329              array('p_close',array()),
 330              array('document_end',array()),
 331          );
 332          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 333      }
 334  
 335      function testInternalLinkSectionRef() {
 336          $this->P->addMode('internallink',new Internallink());
 337          $this->P->parse("Foo [[wiki:syntax#internal|Syntax]] Bar");
 338          $calls = array (
 339              array('document_start',array()),
 340              array('p_open',array()),
 341              array('cdata',array("\n".'Foo ')),
 342              array('internallink',array('wiki:syntax#internal','Syntax')),
 343              array('cdata',array(' Bar')),
 344              array('p_close',array()),
 345              array('document_end',array()),
 346          );
 347          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 348      }
 349  
 350      function testInternalLinkCodeFollows() {
 351          $this->P->addMode('internallink',new Internallink());
 352          $this->P->parse("Foo [[wiki:internal:link|Test]] Bar <code>command [arg1 [arg2 [arg3]]]</code>");
 353          $calls = array (
 354              array('document_start',array()),
 355              array('p_open',array()),
 356              array('cdata',array("\n".'Foo ')),
 357              array('internallink',array('wiki:internal:link','Test')),
 358              array('cdata',array(' Bar <code>command [arg1 [arg2 [arg3]]]</code>')),
 359              array('p_close',array()),
 360              array('document_end',array()),
 361          );
 362          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 363      }
 364  
 365      function testInternalLinkCodeFollows2() {
 366          $this->P->addMode('internallink',new Internallink());
 367          $this->P->parse("Foo [[wiki:internal:link|[Square brackets in title] Test]] Bar <code>command [arg1 [arg2 [arg3]]]</code>");
 368          $calls = array (
 369              array('document_start',array()),
 370              array('p_open',array()),
 371              array('cdata',array("\n".'Foo ')),
 372              array('internallink',array('wiki:internal:link','[Square brackets in title] Test')),
 373              array('cdata',array(' Bar <code>command [arg1 [arg2 [arg3]]]</code>')),
 374              array('p_close',array()),
 375              array('document_end',array()),
 376          );
 377          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 378      }
 379  
 380      function testExternalInInternalLink() {
 381          $this->P->addMode('internallink',new Internallink());
 382          $this->P->parse("Foo [[http://www.google.com|Google]] Bar");
 383          $calls = array (
 384              array('document_start',array()),
 385              array('p_open',array()),
 386              array('cdata',array("\n".'Foo ')),
 387              array('externallink',array('http://www.google.com','Google')),
 388              array('cdata',array(' Bar')),
 389              array('p_close',array()),
 390              array('document_end',array()),
 391          );
 392          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 393      }
 394  
 395      function testExternalInInternalLink2() {
 396          $this->P->addMode('internallink',new Internallink());
 397          $this->P->parse("Foo [[http://www.google.com?test[]=squarebracketsinurl|Google]] Bar");
 398          $calls = array (
 399              array('document_start',array()),
 400              array('p_open',array()),
 401              array('cdata',array("\n".'Foo ')),
 402              array('externallink',array('http://www.google.com?test[]=squarebracketsinurl','Google')),
 403              array('cdata',array(' Bar')),
 404              array('p_close',array()),
 405              array('document_end',array()),
 406          );
 407          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 408      }
 409  
 410      function testExternalInInternalLink2CodeFollows() {
 411          $this->P->addMode('internallink',new Internallink());
 412          $this->P->parse("Foo [[http://www.google.com?test[]=squarebracketsinurl|Google]] Bar <code>command [arg1 [arg2 [arg3]]]</code>");
 413          $calls = array (
 414              array('document_start',array()),
 415              array('p_open',array()),
 416              array('cdata',array("\n".'Foo ')),
 417              array('externallink',array('http://www.google.com?test[]=squarebracketsinurl','Google')),
 418              array('cdata',array(' Bar <code>command [arg1 [arg2 [arg3]]]</code>')),
 419              array('p_close',array()),
 420              array('document_end',array()),
 421          );
 422          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 423      }
 424  
 425      function testTwoInternalLinks() {
 426          $this->P->addMode('internallink',new Internallink());
 427          $this->P->parse("Foo [[foo:bar|one]] and [[bar:foo|two]] Bar");
 428          $calls = array (
 429              array('document_start',array()),
 430              array('p_open',array()),
 431              array('cdata',array("\n".'Foo ')),
 432              array('internallink',array('foo:bar','one')),
 433              array('cdata',array(' and ')),
 434              array('internallink',array('bar:foo','two')),
 435              array('cdata',array(' Bar')),
 436              array('p_close',array()),
 437              array('document_end',array()),
 438          );
 439          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 440      }
 441  
 442  
 443      function testInterwikiLink() {
 444          $this->P->addMode('internallink',new Internallink());
 445          $this->P->parse("Foo [[iw>somepage|Some Page]] Bar");
 446          $calls = array (
 447              array('document_start',array()),
 448              array('p_open',array()),
 449              array('cdata',array("\n".'Foo ')),
 450              array('interwikilink',array('iw>somepage','Some Page','iw','somepage')),
 451              array('cdata',array(' Bar')),
 452              array('p_close',array()),
 453              array('document_end',array()),
 454          );
 455          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 456      }
 457  
 458      function testInterwikiLinkCase() {
 459          $this->P->addMode('internallink',new Internallink());
 460          $this->P->parse("Foo [[IW>somepage|Some Page]] Bar");
 461          $calls = array (
 462              array('document_start',array()),
 463              array('p_open',array()),
 464              array('cdata',array("\n".'Foo ')),
 465              array('interwikilink',array('IW>somepage','Some Page','iw','somepage')),
 466              array('cdata',array(' Bar')),
 467              array('p_close',array()),
 468              array('document_end',array()),
 469          );
 470          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 471      }
 472  
 473      function testInterwikiPedia() {
 474          $this->P->addMode('internallink',new Internallink());
 475          $this->P->parse("Foo [[wp>Callback_(computer_science)|callbacks]] Bar");
 476          $calls = array (
 477              array('document_start',array()),
 478              array('p_open',array()),
 479              array('cdata',array("\n".'Foo ')),
 480              array('interwikilink',array('wp>Callback_(computer_science)','callbacks','wp','Callback_(computer_science)')),
 481              array('cdata',array(' Bar')),
 482              array('p_close',array()),
 483              array('document_end',array()),
 484          );
 485          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 486      }
 487  
 488      function testCamelCase() {
 489          $this->P->addMode('camelcaselink',new Camelcaselink());
 490          $this->P->parse("Foo FooBar Bar");
 491          $calls = array (
 492              array('document_start',array()),
 493              array('p_open',array()),
 494              array('cdata',array("\n".'Foo ')),
 495              array('camelcaselink',array('FooBar')),
 496              array('cdata',array(' Bar')),
 497              array('p_close',array()),
 498              array('document_end',array()),
 499          );
 500          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 501      }
 502  
 503      function testFileLink() {
 504          $this->P->addMode('filelink',new FileLink());
 505          $this->P->parse('Foo file://temp/file.txt Bar');
 506          $calls = array (
 507              array('document_start',array()),
 508              array('p_open',array()),
 509              array('cdata',array("\n".'Foo ')),
 510              array('filelink',array('file://temp/file.txt ',NULL)),
 511              array('cdata',array('Bar')),
 512              array('p_close',array()),
 513              array('document_end',array()),
 514          );
 515          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 516      }
 517  
 518      function testFileLinkInternal() {
 519          $this->P->addMode('internallink',new Internallink());
 520          $this->P->parse('Foo [[file://temp/file.txt|Some File]] Bar');
 521          $calls = array (
 522              array('document_start',array()),
 523              array('p_open',array()),
 524              array('cdata',array("\n".'Foo ')),
 525              array('externallink',array('file://temp/file.txt','Some File')),
 526              array('cdata',array(' Bar')),
 527              array('p_close',array()),
 528              array('document_end',array()),
 529          );
 530          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 531      }
 532  
 533      function testWindowsShareLink() {
 534          $this->P->addMode('windowssharelink',new Windowssharelink());
 535          $this->P->parse('Foo \\\server\share Bar');
 536          $calls = array (
 537              array('document_start',array()),
 538              array('p_open',array()),
 539              array('cdata',array("\n".'Foo ')),
 540              array('windowssharelink',array('\\\server\share',NULL)),
 541              array('cdata',array(' Bar')),
 542              array('p_close',array()),
 543              array('document_end',array()),
 544          );
 545          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 546      }
 547  
 548      function testWindowsShareLinkHyphen() {
 549          $this->P->addMode('windowssharelink',new Windowssharelink());
 550          $this->P->parse('Foo \\\server\share-hyphen Bar');
 551          $calls = array (
 552          array('document_start',array()),
 553          array('p_open',array()),
 554          array('cdata',array("\n".'Foo ')),
 555          array('windowssharelink',array('\\\server\share-hyphen',NULL)),
 556          array('cdata',array(' Bar')),
 557          array('p_close',array()),
 558          array('document_end',array()),
 559          );
 560          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 561      }
 562  
 563      function testWindowsShareLinkInternal() {
 564          $this->P->addMode('internallink',new Internallink());
 565          $this->P->parse('Foo [[\\\server\share|My Documents]] Bar');
 566          $calls = array (
 567              array('document_start',array()),
 568              array('p_open',array()),
 569              array('cdata',array("\n".'Foo ')),
 570              array('windowssharelink',array('\\\server\share','My Documents')),
 571              array('cdata',array(' Bar')),
 572              array('p_close',array()),
 573              array('document_end',array()),
 574          );
 575          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 576      }
 577  
 578      function testMediaInternal() {
 579          $this->P->addMode('media',new Media());
 580          $this->P->parse('Foo {{img.gif}} Bar');
 581          $calls = array (
 582              array('document_start',array()),
 583              array('p_open',array()),
 584              array('cdata',array("\n".'Foo ')),
 585              array('internalmedia',array('img.gif',NULL,NULL,NULL,NULL,'cache','details')),
 586              array('cdata',array(' Bar')),
 587              array('p_close',array()),
 588              array('document_end',array()),
 589          );
 590          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 591      }
 592  
 593      function testMediaInternalLinkOnly() {
 594          $this->P->addMode('media',new Media());
 595          $this->P->parse('Foo {{img.gif?linkonly}} Bar');
 596          $calls = array (
 597              array('document_start',array()),
 598              array('p_open',array()),
 599              array('cdata',array("\n".'Foo ')),
 600              array('internalmedia',array('img.gif',NULL,NULL,NULL,NULL,'cache','linkonly')),
 601              array('cdata',array(' Bar')),
 602              array('p_close',array()),
 603              array('document_end',array()),
 604          );
 605          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 606      }
 607  
 608      function testMediaNotImage() {
 609          $this->P->addMode('media',new Media());
 610          $this->P->parse('Foo {{foo.txt?10x10|Some File}} Bar');
 611          $calls = array (
 612              array('document_start',array()),
 613              array('p_open',array()),
 614              array('cdata',array("\n".'Foo ')),
 615              array('internalmedia',array('foo.txt','Some File',null,10,10,'cache','details')),
 616              array('cdata',array(' Bar')),
 617              array('p_close',array()),
 618              array('document_end',array()),
 619          );
 620          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 621      }
 622  
 623      function testMediaInternalLAlign() {
 624          $this->P->addMode('media',new Media());
 625          $this->P->parse('Foo {{img.gif }} Bar');
 626          $calls = array (
 627              array('document_start',array()),
 628              array('p_open',array()),
 629              array('cdata',array("\n".'Foo ')),
 630              array('internalmedia',array('img.gif',NULL,'left',NULL,NULL,'cache','details')),
 631              array('cdata',array(' Bar')),
 632              array('p_close',array()),
 633              array('document_end',array()),
 634          );
 635          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 636      }
 637  
 638      function testMediaInternalRAlign() {
 639          $this->P->addMode('media',new Media());
 640          $this->P->parse('Foo {{ img.gif}} Bar');
 641          $calls = array (
 642              array('document_start',array()),
 643              array('p_open',array()),
 644              array('cdata',array("\n".'Foo ')),
 645              array('internalmedia',array('img.gif',NULL,'right',NULL,NULL,'cache','details')),
 646              array('cdata',array(' Bar')),
 647              array('p_close',array()),
 648              array('document_end',array()),
 649          );
 650          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 651      }
 652  
 653      function testMediaInternalCenter() {
 654          $this->P->addMode('media',new Media());
 655          $this->P->parse('Foo {{ img.gif }} Bar');
 656          $calls = array (
 657              array('document_start',array()),
 658              array('p_open',array()),
 659              array('cdata',array("\n".'Foo ')),
 660              array('internalmedia',array('img.gif',NULL,'center',NULL,NULL,'cache','details')),
 661              array('cdata',array(' Bar')),
 662              array('p_close',array()),
 663              array('document_end',array()),
 664          );
 665          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 666      }
 667  
 668      function testMediaInternalParams() {
 669          $this->P->addMode('media',new Media());
 670          $this->P->parse('Foo {{img.gif?50x100nocache}} Bar');
 671          $calls = array (
 672              array('document_start',array()),
 673              array('p_open',array()),
 674              array('cdata',array("\n".'Foo ')),
 675              array('internalmedia',array('img.gif',NULL,NULL,'50','100','nocache','details')),
 676              array('cdata',array(' Bar')),
 677              array('p_close',array()),
 678              array('document_end',array()),
 679          );
 680          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 681      }
 682  
 683      function testMediaInternalTitle() {
 684          $this->P->addMode('media',new Media());
 685          $this->P->parse('Foo {{img.gif?50x100|Some Image}} Bar');
 686          $calls = array (
 687              array('document_start',array()),
 688              array('p_open',array()),
 689              array('cdata',array("\n".'Foo ')),
 690              array('internalmedia',array('img.gif','Some Image',NULL,'50','100','cache','details')),
 691              array('cdata',array(' Bar')),
 692              array('p_close',array()),
 693              array('document_end',array()),
 694          );
 695          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 696      }
 697  
 698      function testMediaExternal() {
 699          $this->P->addMode('media',new Media());
 700          $this->P->parse('Foo {{http://www.google.com/img.gif}} Bar');
 701          $calls = array (
 702              array('document_start',array()),
 703              array('p_open',array()),
 704              array('cdata',array("\n".'Foo ')),
 705              array('externalmedia',array('http://www.google.com/img.gif',NULL,NULL,NULL,NULL,'cache','details')),
 706              array('cdata',array(' Bar')),
 707              array('p_close',array()),
 708              array('document_end',array()),
 709          );
 710          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 711      }
 712  
 713      function testMediaExternalParams() {
 714          $this->P->addMode('media',new Media());
 715          $this->P->parse('Foo {{http://www.google.com/img.gif?50x100nocache}} Bar');
 716          $calls = array (
 717              array('document_start',array()),
 718              array('p_open',array()),
 719              array('cdata',array("\n".'Foo ')),
 720              array('externalmedia',array('http://www.google.com/img.gif',NULL,NULL,'50','100','nocache','details')),
 721              array('cdata',array(' Bar')),
 722              array('p_close',array()),
 723              array('document_end',array()),
 724          );
 725          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 726      }
 727  
 728      function testMediaExternalTitle() {
 729          $this->P->addMode('media',new Media());
 730          $this->P->parse('Foo {{http://www.google.com/img.gif?50x100|Some Image}} Bar');
 731          $calls = array (
 732              array('document_start',array()),
 733              array('p_open',array()),
 734              array('cdata',array("\n".'Foo ')),
 735              array('externalmedia',
 736              array('http://www.google.com/img.gif','Some Image',NULL,'50','100','cache','details')),
 737              array('cdata',array(' Bar')),
 738              array('p_close',array()),
 739              array('document_end',array()),
 740          );
 741          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 742      }
 743  
 744      function testMediaInInternalLink() {
 745          $this->P->addMode('internallink',new Internallink());
 746          $this->P->parse("Foo [[x:1:y:foo_bar:z|{{img.gif?10x20nocache|Some Image}}]] Bar");
 747  
 748          $image = array(
 749              'type'=>'internalmedia',
 750              'src'=>'img.gif',
 751              'title'=>'Some Image',
 752              'align'=>NULL,
 753              'width'=>10,
 754              'height'=>20,
 755              'cache'=>'nocache',
 756              'linking'=>'details',
 757          );
 758  
 759          $calls = array (
 760              array('document_start',array()),
 761              array('p_open',array()),
 762              array('cdata',array("\n".'Foo ')),
 763              array('internallink',array('x:1:y:foo_bar:z',$image)),
 764              array('cdata',array(' Bar')),
 765              array('p_close',array()),
 766              array('document_end',array()),
 767          );
 768          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 769      }
 770  
 771      function testMediaNoImageInInternalLink() {
 772          $this->P->addMode('internallink',new Internallink());
 773          $this->P->parse("Foo [[x:1:y:foo_bar:z|{{foo.txt?10x20nocache|Some Image}}]] Bar");
 774  
 775          $image = array(
 776              'type'=>'internalmedia',
 777              'src'=>'foo.txt',
 778              'title'=>'Some Image',
 779              'align'=>NULL,
 780              'width'=>10,
 781              'height'=>20,
 782              'cache'=>'nocache',
 783              'linking'=>'details',
 784          );
 785  
 786          $calls = array (
 787              array('document_start',array()),
 788              array('p_open',array()),
 789              array('cdata',array("\n".'Foo ')),
 790              array('internallink',array('x:1:y:foo_bar:z',$image)),
 791              array('cdata',array(' Bar')),
 792              array('p_close',array()),
 793              array('document_end',array()),
 794          );
 795          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 796      }
 797  
 798      function testMediaInEmailLink() {
 799          $this->P->addMode('internallink',new Internallink());
 800          $this->P->parse("Foo [[foo@example.com|{{img.gif?10x20nocache|Some Image}}]] Bar");
 801  
 802          $image = array(
 803              'type'=>'internalmedia',
 804              'src'=>'img.gif',
 805              'title'=>'Some Image',
 806              'align'=>NULL,
 807              'width'=>10,
 808              'height'=>20,
 809              'cache'=>'nocache',
 810              'linking'=>'details',
 811          );
 812  
 813          $calls = array (
 814              array('document_start',array()),
 815              array('p_open',array()),
 816              array('cdata',array("\n".'Foo ')),
 817              array('emaillink',array('foo@example.com',$image)),
 818              array('cdata',array(' Bar')),
 819              array('p_close',array()),
 820              array('document_end',array()),
 821          );
 822          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 823      }
 824  
 825      function testNestedMedia() {
 826          $this->P->addMode('media',new Media());
 827          $this->P->parse('Foo {{img.gif|{{foo.gif|{{bar.gif|Bar}}}}}} Bar');
 828          $calls = array (
 829              array('document_start',array()),
 830              array('p_open',array()),
 831              array('cdata',array("\n".'Foo ')),
 832              array('internalmedia',
 833              array('img.gif','{{foo.gif|{{bar.gif|Bar',NULL,NULL,NULL,'cache','details')),
 834              array('cdata',array('}}}} Bar')),
 835              array('p_close',array()),
 836              array('document_end',array()),
 837          );
 838          $this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
 839      }
 840  
 841  }
 842