xref: /dokuwiki/_test/tests/inc/parser/parser_media.test.php (revision 79fdbafce5bbc3655294f139c92a4ce5071de315)
1912be8f6SMichael Große<?php
2912be8f6SMichael Großerequire_once 'parser.inc.php';
3912be8f6SMichael Große
4912be8f6SMichael Große/**
5912be8f6SMichael Große * Tests for the implementation of audio and video files
6912be8f6SMichael Große *
7*79fdbafcSLarsDW223 * @group parser_media
8912be8f6SMichael Große * @author  Michael Große <grosse@cosmocode.de>
9912be8f6SMichael Große*/
10912be8f6SMichael Großeclass TestOfDoku_Parser_Media extends TestOfDoku_Parser {
11912be8f6SMichael Große
12912be8f6SMichael Große    function testVideoOGVExternal() {
13912be8f6SMichael Große        $file = 'http://some.where.far/away.ogv';
14912be8f6SMichael Große        $parser_response = p_get_instructions('{{' . $file . '}}');
15912be8f6SMichael Große
16912be8f6SMichael Große        $calls = array (
17912be8f6SMichael Große            array('document_start',array()),
18912be8f6SMichael Große            array('p_open',array()),
19912be8f6SMichael Große            array('externalmedia',array($file,null,null,null,null,'cache','details')),
20912be8f6SMichael Große            array('cdata',array(null)),
21912be8f6SMichael Große            array('p_close',array()),
22912be8f6SMichael Große            array('document_end',array()),
23912be8f6SMichael Große        );
24912be8f6SMichael Große        $this->assertEquals(array_map('stripbyteindex',$parser_response),$calls);
25912be8f6SMichael Große
26912be8f6SMichael Große        $Renderer = new Doku_Renderer_xhtml();
27912be8f6SMichael Große        $url = $Renderer->externalmedia($file,null,null,null,null,'cache','details',true);
28912be8f6SMichael Große        //print_r("url: " . $url);
29912be8f6SMichael Große        $video = '<video class="media" width="320" height="240" controls="controls">';
30912be8f6SMichael Große        $this->assertEquals(substr($url,0,66),$video);
31912be8f6SMichael Große        $source = '<source src="http://some.where.far/away.ogv" type="video/ogg" />';
32912be8f6SMichael Große        $this->assertEquals(substr($url,67,64),$source);
33912be8f6SMichael Große        // work around random token
34d09fc643SPhil Hopper        $a_first_part = '<a href="' . DOKU_BASE . 'lib/exe/fetch.php?cache=&amp;tok=';
35912be8f6SMichael Große        $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">';
36d09fc643SPhil Hopper
37d09fc643SPhil Hopper        $substr_start = 132;
38d09fc643SPhil Hopper        $substr_len = strlen($a_first_part);
39d09fc643SPhil Hopper        $this->assertEquals($a_first_part, substr($url, $substr_start, $substr_len));
40d09fc643SPhil Hopper
41d09fc643SPhil Hopper        $substr_start = strpos($url, '&amp;media', $substr_start + $substr_len);
42d09fc643SPhil Hopper        $this->assertNotSame(false, $substr_start, 'Substring not found.');
43d09fc643SPhil Hopper        $substr_len = strlen($a_second_part);
44d09fc643SPhil Hopper        $this->assertEquals($a_second_part, substr($url, $substr_start, $substr_len));
45d09fc643SPhil Hopper
46912be8f6SMichael Große        $rest = 'away.ogv</a></video>'."\n";
47d09fc643SPhil Hopper        $substr_start = strlen($url) - strlen($rest);
48d09fc643SPhil Hopper        $this->assertEquals($rest, substr($url, $substr_start));
49912be8f6SMichael Große    }
50912be8f6SMichael Große
51912be8f6SMichael Große    /**
52912be8f6SMichael Große     * unknown extension of external media file
53912be8f6SMichael Große     */
54912be8f6SMichael Große    function testVideoVIDExternal() {
55912be8f6SMichael Große        $file = 'http://some.where.far/away.vid';
56912be8f6SMichael Große        $parser_response = p_get_instructions('{{' . $file . '}}');
57912be8f6SMichael Große
58912be8f6SMichael Große        $calls = array(
59912be8f6SMichael Große            array('document_start', array()),
60912be8f6SMichael Große            array('p_open', array()),
61912be8f6SMichael Große            array('externalmedia', array($file, null, null, null, null, 'cache', 'details')),
62912be8f6SMichael Große            array('cdata', array(null)),
63912be8f6SMichael Große            array('p_close', array()),
64912be8f6SMichael Große            array('document_end', array()),
65912be8f6SMichael Große        );
66912be8f6SMichael Große        $this->assertEquals(array_map('stripbyteindex', $parser_response), $calls);
67912be8f6SMichael Große
68912be8f6SMichael Große        $Renderer = new Doku_Renderer_xhtml();
69912be8f6SMichael Große        $url = $Renderer->externalmedia($file, null, null, null, null, 'cache', 'details', true);
70912be8f6SMichael Große        // work around random token
71d09fc643SPhil Hopper        $a_first_part = '<a href="' . DOKU_BASE . 'lib/exe/fetch.php?tok=';
72912be8f6SMichael Große        $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">';
73d09fc643SPhil Hopper
74d09fc643SPhil Hopper        $substr_start = 0;
75d09fc643SPhil Hopper        $substr_len = strlen($a_first_part);
76d09fc643SPhil Hopper        $this->assertEquals($a_first_part, substr($url, $substr_start, $substr_len));
77d09fc643SPhil Hopper
78d09fc643SPhil Hopper        $substr_start = strpos($url, '&amp;media', $substr_start + $substr_len);
79d09fc643SPhil Hopper        $this->assertNotSame(false, $substr_start, 'Substring not found.');
80d09fc643SPhil Hopper        $substr_len = strlen($a_second_part);
81d09fc643SPhil Hopper        $this->assertEquals($a_second_part, substr($url, $substr_start, $substr_len));
82d09fc643SPhil Hopper
83912be8f6SMichael Große        $rest = 'away.vid</a>';
84d09fc643SPhil Hopper        $substr_start = strlen($url) - strlen($rest);
85d09fc643SPhil Hopper        $this->assertEquals($rest, substr($url, $substr_start));
86912be8f6SMichael Große    }
87db42b6f8SMichael Große
88db42b6f8SMichael Große
89db42b6f8SMichael Große    function testVideoOGVInternal() {
90db42b6f8SMichael Große        $file = 'wiki:kind_zu_katze.ogv';
91db42b6f8SMichael Große        $parser_response = p_get_instructions('{{' . $file . '}}');
92db42b6f8SMichael Große
93db42b6f8SMichael Große        $calls = array (
94db42b6f8SMichael Große            array('document_start',array()),
95db42b6f8SMichael Große            array('p_open',array()),
96db42b6f8SMichael Große            array('internalmedia',array($file,null,null,null,null,'cache','details')),
97db42b6f8SMichael Große            array('cdata',array(null)),
98db42b6f8SMichael Große            array('p_close',array()),
99db42b6f8SMichael Große            array('document_end',array()),
100db42b6f8SMichael Große        );
101db42b6f8SMichael Große        $this->assertEquals(array_map('stripbyteindex',$parser_response),$calls);
102db42b6f8SMichael Große
103db42b6f8SMichael Große        $Renderer = new Doku_Renderer_xhtml();
104db42b6f8SMichael Große        $url = $Renderer->externalmedia($file,null,null,null,null,'cache','details',true);
105db42b6f8SMichael Große
106d09fc643SPhil Hopper        $video = '<video class="media" width="320" height="240" controls="controls" poster="' . DOKU_BASE . 'lib/exe/fetch.php?media=wiki:kind_zu_katze.png">';
107d09fc643SPhil Hopper        $substr_start = 0;
108d09fc643SPhil Hopper        $substr_len = strlen($video);
109d09fc643SPhil Hopper        $this->assertEquals($video, substr($url, $substr_start, $substr_len));
110db42b6f8SMichael Große
111d09fc643SPhil Hopper        // find $source_webm in $url
112d09fc643SPhil Hopper        $source_webm = '<source src="' . DOKU_BASE . 'lib/exe/fetch.php?media=wiki:kind_zu_katze.webm" type="video/webm" />';
113d09fc643SPhil Hopper        $substr_start = strpos($url, $source_webm, $substr_start + $substr_len);
114d09fc643SPhil Hopper        $this->assertNotSame(false, $substr_start, 'Substring not found.');
115db42b6f8SMichael Große
116d09fc643SPhil Hopper        // find $source_ogv in $url
117d09fc643SPhil Hopper        $source_ogv = '<source src="' . DOKU_BASE . 'lib/exe/fetch.php?media=wiki:kind_zu_katze.ogv" type="video/ogg" />';
118d09fc643SPhil Hopper        $substr_start = strpos($url, $source_ogv, $substr_start + strlen($source_webm));
119d09fc643SPhil Hopper        $this->assertNotSame(false, $substr_start, 'Substring not found.');
120d09fc643SPhil Hopper
121d09fc643SPhil Hopper        // find $a_webm in $url
122ef08383eSAndreas Gohr        $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>';
123d09fc643SPhil Hopper        $substr_start = strpos($url, $a_webm, $substr_start + strlen($source_ogv));
124d09fc643SPhil Hopper        $this->assertNotSame(false, $substr_start, 'Substring not found.');
125d09fc643SPhil Hopper
126d09fc643SPhil Hopper        // find $a_webm in $url
127ef08383eSAndreas Gohr        $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>';
128d09fc643SPhil Hopper        $substr_start = strpos($url, $a_ogv, $substr_start + strlen($a_webm));
129d09fc643SPhil Hopper        $this->assertNotSame(false, $substr_start, 'Substring not found.');
130db42b6f8SMichael Große
131db42b6f8SMichael Große        $rest = '</video>'."\n";
132d09fc643SPhil Hopper        $substr_start = strlen($url) - strlen($rest);
133d09fc643SPhil Hopper        $this->assertEquals($rest, substr($url, $substr_start));
134db42b6f8SMichael Große    }
135*79fdbafcSLarsDW223
136*79fdbafcSLarsDW223    function testSimpleLinkText() {
137*79fdbafcSLarsDW223        $file = 'wiki:dokuwiki-128.png';
138*79fdbafcSLarsDW223        $parser_response = p_get_instructions('{{' . $file . '|This is a simple text.}}');
139*79fdbafcSLarsDW223
140*79fdbafcSLarsDW223        $calls = array (
141*79fdbafcSLarsDW223            array('document_start',array()),
142*79fdbafcSLarsDW223            array('p_open',array()),
143*79fdbafcSLarsDW223            array('internalmedia',array($file,'This is a simple text.',null,null,null,'cache','details')),
144*79fdbafcSLarsDW223            array('cdata',array(null)),
145*79fdbafcSLarsDW223            array('p_close',array()),
146*79fdbafcSLarsDW223            array('document_end',array()),
147*79fdbafcSLarsDW223        );
148*79fdbafcSLarsDW223        $this->assertEquals(array_map('stripbyteindex',$parser_response),$calls);
149*79fdbafcSLarsDW223    }
150*79fdbafcSLarsDW223
151*79fdbafcSLarsDW223    function testLinkTextWithWavedBrackets_1() {
152*79fdbafcSLarsDW223        $file = 'wiki:dokuwiki-128.png';
153*79fdbafcSLarsDW223        $parser_response = p_get_instructions('{{' . $file . '|We got a { here.}}');
154*79fdbafcSLarsDW223
155*79fdbafcSLarsDW223        $calls = array (
156*79fdbafcSLarsDW223            array('document_start',array()),
157*79fdbafcSLarsDW223            array('p_open',array()),
158*79fdbafcSLarsDW223            array('internalmedia',array($file,'We got a { here.',null,null,null,'cache','details')),
159*79fdbafcSLarsDW223            array('cdata',array(null)),
160*79fdbafcSLarsDW223            array('p_close',array()),
161*79fdbafcSLarsDW223            array('document_end',array()),
162*79fdbafcSLarsDW223        );
163*79fdbafcSLarsDW223        $this->assertEquals(array_map('stripbyteindex',$parser_response),$calls);
164*79fdbafcSLarsDW223    }
165*79fdbafcSLarsDW223
166*79fdbafcSLarsDW223    function testLinkTextWithWavedBrackets_2() {
167*79fdbafcSLarsDW223        $file = 'wiki:dokuwiki-128.png';
168*79fdbafcSLarsDW223        $parser_response = p_get_instructions('{{' . $file . '|We got a } here.}}');
169*79fdbafcSLarsDW223
170*79fdbafcSLarsDW223        $calls = array (
171*79fdbafcSLarsDW223            array('document_start',array()),
172*79fdbafcSLarsDW223            array('p_open',array()),
173*79fdbafcSLarsDW223            array('internalmedia',array($file,'We got a } here.',null,null,null,'cache','details')),
174*79fdbafcSLarsDW223            array('cdata',array(null)),
175*79fdbafcSLarsDW223            array('p_close',array()),
176*79fdbafcSLarsDW223            array('document_end',array()),
177*79fdbafcSLarsDW223        );
178*79fdbafcSLarsDW223        $this->assertEquals(array_map('stripbyteindex',$parser_response),$calls);
179*79fdbafcSLarsDW223    }
180*79fdbafcSLarsDW223
181*79fdbafcSLarsDW223    function testLinkTextWithWavedBrackets_3() {
182*79fdbafcSLarsDW223        $file = 'wiki:dokuwiki-128.png';
183*79fdbafcSLarsDW223        $parser_response = p_get_instructions('{{' . $file . '|We got a { and a } here.}}');
184*79fdbafcSLarsDW223
185*79fdbafcSLarsDW223        $calls = array (
186*79fdbafcSLarsDW223            array('document_start',array()),
187*79fdbafcSLarsDW223            array('p_open',array()),
188*79fdbafcSLarsDW223            array('internalmedia',array($file,'We got a { and a } here.',null,null,null,'cache','details')),
189*79fdbafcSLarsDW223            array('cdata',array(null)),
190*79fdbafcSLarsDW223            array('p_close',array()),
191*79fdbafcSLarsDW223            array('document_end',array()),
192*79fdbafcSLarsDW223        );
193*79fdbafcSLarsDW223        $this->assertEquals(array_map('stripbyteindex',$parser_response),$calls);
194*79fdbafcSLarsDW223    }
195912be8f6SMichael Große}
196