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