[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

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

   1  <?php
   2  require_once  'parser.inc.php';
   3  
   4  /**
   5   * Tests for the implementation of audio and video files
   6   *
   7   * @group parser_media
   8   * @author  Michael Gro├če <grosse@cosmocode.de>
   9  */
  10  class TestOfDoku_Parser_Media extends TestOfDoku_Parser {
  11  
  12      function testVideoOGVExternal() {
  13          $file = 'http://some.where.far/away.ogv';
  14          $parser_response = p_get_instructions('{{' . $file . '}}');
  15  
  16          $calls = array (
  17              array('document_start',array()),
  18              array('p_open',array()),
  19              array('externalmedia',array($file,null,null,null,null,'cache','details')),
  20              array('cdata',array(null)),
  21              array('p_close',array()),
  22              array('document_end',array()),
  23          );
  24          $this->assertEquals(array_map('stripbyteindex',$parser_response),$calls);
  25  
  26          $Renderer = new Doku_Renderer_xhtml();
  27          $url = $Renderer->externalmedia($file,null,null,null,null,'cache','details',true);
  28          //print_r("url: " . $url);
  29          $video = '<video class="media" width="320" height="240" controls="controls">';
  30          $this->assertEquals(substr($url,0,66),$video);
  31          $source = '<source src="http://some.where.far/away.ogv" type="video/ogg" />';
  32          $this->assertEquals(substr($url,67,64),$source);
  33          // work around random token
  34          $a_first_part = '<a href="' . DOKU_BASE . 'lib/exe/fetch.php?cache=&amp;tok=';
  35          $a_second_part = '&amp;media=http%3A%2F%2Fsome.where.far%2Faway.ogv" class="media mediafile mf_ogv" title="http://some.where.far/away.ogv">';
  36  
  37          $substr_start = 132;
  38          $substr_len = strlen($a_first_part);
  39          $this->assertEquals($a_first_part, substr($url, $substr_start, $substr_len));
  40  
  41          $substr_start = strpos($url, '&amp;media', $substr_start + $substr_len);
  42          $this->assertNotSame(false, $substr_start, 'Substring not found.');
  43          $substr_len = strlen($a_second_part);
  44          $this->assertEquals($a_second_part, substr($url, $substr_start, $substr_len));
  45  
  46          $rest = 'away.ogv</a></video>'."\n";
  47          $substr_start = strlen($url) - strlen($rest);
  48          $this->assertEquals($rest, substr($url, $substr_start));
  49      }
  50  
  51      /**
  52       * unknown extension of external media file
  53       */
  54      function testVideoVIDExternal() {
  55          $file = 'http://some.where.far/away.vid';
  56          $parser_response = p_get_instructions('{{' . $file . '}}');
  57  
  58          $calls = array(
  59              array('document_start', array()),
  60              array('p_open', array()),
  61              array('externalmedia', array($file, null, null, null, null, 'cache', 'details')),
  62              array('cdata', array(null)),
  63              array('p_close', array()),
  64              array('document_end', array()),
  65          );
  66          $this->assertEquals(array_map('stripbyteindex', $parser_response), $calls);
  67  
  68          $Renderer = new Doku_Renderer_xhtml();
  69          $url = $Renderer->externalmedia($file, null, null, null, null, 'cache', 'details', true);
  70          // work around random token
  71          $a_first_part = '<a href="' . DOKU_BASE . 'lib/exe/fetch.php?tok=';
  72          $a_second_part = '&amp;media=http%3A%2F%2Fsome.where.far%2Faway.vid" class="media mediafile mf_vid" title="http://some.where.far/away.vid">';
  73  
  74          $substr_start = 0;
  75          $substr_len = strlen($a_first_part);
  76          $this->assertEquals($a_first_part, substr($url, $substr_start, $substr_len));
  77  
  78          $substr_start = strpos($url, '&amp;media', $substr_start + $substr_len);
  79          $this->assertNotSame(false, $substr_start, 'Substring not found.');
  80          $substr_len = strlen($a_second_part);
  81          $this->assertEquals($a_second_part, substr($url, $substr_start, $substr_len));
  82  
  83          $rest = 'away.vid</a>';
  84          $substr_start = strlen($url) - strlen($rest);
  85          $this->assertEquals($rest, substr($url, $substr_start));
  86      }
  87  
  88  
  89      function testVideoOGVInternal() {
  90          $file = 'wiki:kind_zu_katze.ogv';
  91          $parser_response = p_get_instructions('{{' . $file . '}}');
  92  
  93          $calls = array (
  94              array('document_start',array()),
  95              array('p_open',array()),
  96              array('internalmedia',array($file,null,null,null,null,'cache','details')),
  97              array('cdata',array(null)),
  98              array('p_close',array()),
  99              array('document_end',array()),
 100          );
 101          $this->assertEquals(array_map('stripbyteindex',$parser_response),$calls);
 102  
 103          $Renderer = new Doku_Renderer_xhtml();
 104          $url = $Renderer->externalmedia($file,null,null,null,null,'cache','details',true);
 105  
 106          $video = '<video class="media" width="320" height="240" controls="controls" poster="' . DOKU_BASE . 'lib/exe/fetch.php?media=wiki:kind_zu_katze.png">';
 107          $substr_start = 0;
 108          $substr_len = strlen($video);
 109          $this->assertEquals($video, substr($url, $substr_start, $substr_len));
 110  
 111          // find $source_webm in $url
 112          $source_webm = '<source src="' . DOKU_BASE . 'lib/exe/fetch.php?media=wiki:kind_zu_katze.webm" type="video/webm" />';
 113          $substr_start = strpos($url, $source_webm, $substr_start + $substr_len);
 114          $this->assertNotSame(false, $substr_start, 'Substring not found.');
 115  
 116          // find $source_ogv in $url
 117          $source_ogv = '<source src="' . DOKU_BASE . 'lib/exe/fetch.php?media=wiki:kind_zu_katze.ogv" type="video/ogg" />';
 118          $substr_start = strpos($url, $source_ogv, $substr_start + strlen($source_webm));
 119          $this->assertNotSame(false, $substr_start, 'Substring not found.');
 120  
 121          // find $a_webm in $url
 122          $a_webm = '<a href="' . DOKU_BASE . 'lib/exe/fetch.php?id=&amp;cache=&amp;media=wiki:kind_zu_katze.webm" class="media mediafile mf_webm" title="wiki:kind_zu_katze.webm (99.1'."\xC2\xA0".'KB)">kind_zu_katze.webm</a>';
 123          $substr_start = strpos($url, $a_webm, $substr_start + strlen($source_ogv));
 124          $this->assertNotSame(false, $substr_start, 'Substring not found.');
 125  
 126          // find $a_webm in $url
 127          $a_ogv = '<a href="' . DOKU_BASE . 'lib/exe/fetch.php?id=&amp;cache=&amp;media=wiki:kind_zu_katze.ogv" class="media mediafile mf_ogv" title="wiki:kind_zu_katze.ogv (44.8'."\xC2\xA0".'KB)">kind_zu_katze.ogv</a>';
 128          $substr_start = strpos($url, $a_ogv, $substr_start + strlen($a_webm));
 129          $this->assertNotSame(false, $substr_start, 'Substring not found.');
 130  
 131          $rest = '</video>'."\n";
 132          $substr_start = strlen($url) - strlen($rest);
 133          $this->assertEquals($rest, substr($url, $substr_start));
 134      }
 135  
 136      function testVideoInternalTitle() {
 137          $file = 'wiki:kind_zu_katze.ogv';
 138          $title = 'Single quote: \' Ampersand: &';
 139          
 140          $Renderer = new Doku_Renderer_xhtml();
 141          $url = $Renderer->externalmedia($file, $title, null, null, null, 'cache', 'details', true);
 142          
 143          // make sure the title is escaped just once
 144          $this->assertEquals(htmlspecialchars($title), substr($url, 28, 32));
 145      }
 146  
 147      function testSimpleLinkText() {
 148          $file = 'wiki:dokuwiki-128.png';
 149          $parser_response = p_get_instructions('{{' . $file . '|This is a simple text.}}');
 150  
 151          $calls = array (
 152              array('document_start',array()),
 153              array('p_open',array()),
 154              array('internalmedia',array($file,'This is a simple text.',null,null,null,'cache','details')),
 155              array('cdata',array(null)),
 156              array('p_close',array()),
 157              array('document_end',array()),
 158          );
 159          $this->assertEquals(array_map('stripbyteindex',$parser_response),$calls);
 160      }
 161  
 162      function testLinkTextWithWavedBrackets_1() {
 163          $file = 'wiki:dokuwiki-128.png';
 164          $parser_response = p_get_instructions('{{' . $file . '|We got a { here.}}');
 165  
 166          $calls = array (
 167              array('document_start',array()),
 168              array('p_open',array()),
 169              array('internalmedia',array($file,'We got a { here.',null,null,null,'cache','details')),
 170              array('cdata',array(null)),
 171              array('p_close',array()),
 172              array('document_end',array()),
 173          );
 174          $this->assertEquals(array_map('stripbyteindex',$parser_response),$calls);
 175      }
 176  
 177      function testLinkTextWithWavedBrackets_2() {
 178          $file = 'wiki:dokuwiki-128.png';
 179          $parser_response = p_get_instructions('{{' . $file . '|We got a } here.}}');
 180  
 181          $calls = array (
 182              array('document_start',array()),
 183              array('p_open',array()),
 184              array('internalmedia',array($file,'We got a } here.',null,null,null,'cache','details')),
 185              array('cdata',array(null)),
 186              array('p_close',array()),
 187              array('document_end',array()),
 188          );
 189          $this->assertEquals(array_map('stripbyteindex',$parser_response),$calls);
 190      }
 191  
 192      function testLinkTextWithWavedBrackets_3() {
 193          $file = 'wiki:dokuwiki-128.png';
 194          $parser_response = p_get_instructions('{{' . $file . '|We got a { and a } here.}}');
 195  
 196          $calls = array (
 197              array('document_start',array()),
 198              array('p_open',array()),
 199              array('internalmedia',array($file,'We got a { and a } here.',null,null,null,'cache','details')),
 200              array('cdata',array(null)),
 201              array('p_close',array()),
 202              array('document_end',array()),
 203          );
 204          $this->assertEquals(array_map('stripbyteindex',$parser_response),$calls);
 205      }
 206  }