xref: /dokuwiki/_test/tests/inc/parser/parser_media.test.php (revision d09fc643d601f95006c6144c72bfde3e399ef811)
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 *
7912be8f6SMichael Große * @author  Michael Große <grosse@cosmocode.de>
8912be8f6SMichael Große*/
9912be8f6SMichael Großeclass TestOfDoku_Parser_Media extends TestOfDoku_Parser {
10912be8f6SMichael Große
11912be8f6SMichael Große    function testVideoOGVExternal() {
12912be8f6SMichael Große        $file = 'http://some.where.far/away.ogv';
13912be8f6SMichael Große        $parser_response = p_get_instructions('{{' . $file . '}}');
14912be8f6SMichael Große
15912be8f6SMichael Große        $calls = array (
16912be8f6SMichael Große            array('document_start',array()),
17912be8f6SMichael Große            array('p_open',array()),
18912be8f6SMichael Große            array('externalmedia',array($file,null,null,null,null,'cache','details')),
19912be8f6SMichael Große            array('cdata',array(null)),
20912be8f6SMichael Große            array('p_close',array()),
21912be8f6SMichael Große            array('document_end',array()),
22912be8f6SMichael Große        );
23912be8f6SMichael Große        $this->assertEquals(array_map('stripbyteindex',$parser_response),$calls);
24912be8f6SMichael Große
25912be8f6SMichael Große        $Renderer = new Doku_Renderer_xhtml();
26912be8f6SMichael Große        $url = $Renderer->externalmedia($file,null,null,null,null,'cache','details',true);
27912be8f6SMichael Große        //print_r("url: " . $url);
28912be8f6SMichael Große        $video = '<video class="media" width="320" height="240" controls="controls">';
29912be8f6SMichael Große        $this->assertEquals(substr($url,0,66),$video);
30912be8f6SMichael Große        $source = '<source src="http://some.where.far/away.ogv" type="video/ogg" />';
31912be8f6SMichael Große        $this->assertEquals(substr($url,67,64),$source);
32912be8f6SMichael Große        // work around random token
33*d09fc643SPhil Hopper        $a_first_part = '<a href="' . DOKU_BASE . 'lib/exe/fetch.php?cache=&amp;tok=';
34912be8f6SMichael 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">';
35*d09fc643SPhil Hopper
36*d09fc643SPhil Hopper        $substr_start = 132;
37*d09fc643SPhil Hopper        $substr_len = strlen($a_first_part);
38*d09fc643SPhil Hopper        $this->assertEquals($a_first_part, substr($url, $substr_start, $substr_len));
39*d09fc643SPhil Hopper
40*d09fc643SPhil Hopper        $substr_start = strpos($url, '&amp;media', $substr_start + $substr_len);
41*d09fc643SPhil Hopper        $this->assertNotSame(false, $substr_start, 'Substring not found.');
42*d09fc643SPhil Hopper        $substr_len = strlen($a_second_part);
43*d09fc643SPhil Hopper        $this->assertEquals($a_second_part, substr($url, $substr_start, $substr_len));
44*d09fc643SPhil Hopper
45912be8f6SMichael Große        $rest = 'away.ogv</a></video>'."\n";
46*d09fc643SPhil Hopper        $substr_start = strlen($url) - strlen($rest);
47*d09fc643SPhil Hopper        $this->assertEquals($rest, substr($url, $substr_start));
48912be8f6SMichael Große    }
49912be8f6SMichael Große
50912be8f6SMichael Große    /**
51912be8f6SMichael Große     * unknown extension of external media file
52912be8f6SMichael Große     */
53912be8f6SMichael Große    function testVideoVIDExternal() {
54912be8f6SMichael Große        $file = 'http://some.where.far/away.vid';
55912be8f6SMichael Große        $parser_response = p_get_instructions('{{' . $file . '}}');
56912be8f6SMichael Große
57912be8f6SMichael Große        $calls = array(
58912be8f6SMichael Große            array('document_start', array()),
59912be8f6SMichael Große            array('p_open', array()),
60912be8f6SMichael Große            array('externalmedia', array($file, null, null, null, null, 'cache', 'details')),
61912be8f6SMichael Große            array('cdata', array(null)),
62912be8f6SMichael Große            array('p_close', array()),
63912be8f6SMichael Große            array('document_end', array()),
64912be8f6SMichael Große        );
65912be8f6SMichael Große        $this->assertEquals(array_map('stripbyteindex', $parser_response), $calls);
66912be8f6SMichael Große
67912be8f6SMichael Große        $Renderer = new Doku_Renderer_xhtml();
68912be8f6SMichael Große        $url = $Renderer->externalmedia($file, null, null, null, null, 'cache', 'details', true);
69912be8f6SMichael Große        // work around random token
70*d09fc643SPhil Hopper        $a_first_part = '<a href="' . DOKU_BASE . 'lib/exe/fetch.php?tok=';
71912be8f6SMichael 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">';
72*d09fc643SPhil Hopper
73*d09fc643SPhil Hopper        $substr_start = 0;
74*d09fc643SPhil Hopper        $substr_len = strlen($a_first_part);
75*d09fc643SPhil Hopper        $this->assertEquals($a_first_part, substr($url, $substr_start, $substr_len));
76*d09fc643SPhil Hopper
77*d09fc643SPhil Hopper        $substr_start = strpos($url, '&amp;media', $substr_start + $substr_len);
78*d09fc643SPhil Hopper        $this->assertNotSame(false, $substr_start, 'Substring not found.');
79*d09fc643SPhil Hopper        $substr_len = strlen($a_second_part);
80*d09fc643SPhil Hopper        $this->assertEquals($a_second_part, substr($url, $substr_start, $substr_len));
81*d09fc643SPhil Hopper
82912be8f6SMichael Große        $rest = 'away.vid</a>';
83*d09fc643SPhil Hopper        $substr_start = strlen($url) - strlen($rest);
84*d09fc643SPhil Hopper        $this->assertEquals($rest, substr($url, $substr_start));
85912be8f6SMichael Große    }
86db42b6f8SMichael Große
87db42b6f8SMichael Große
88db42b6f8SMichael Große    function testVideoOGVInternal() {
89db42b6f8SMichael Große        $file = 'wiki:kind_zu_katze.ogv';
90db42b6f8SMichael Große        $parser_response = p_get_instructions('{{' . $file . '}}');
91db42b6f8SMichael Große
92db42b6f8SMichael Große        $calls = array (
93db42b6f8SMichael Große            array('document_start',array()),
94db42b6f8SMichael Große            array('p_open',array()),
95db42b6f8SMichael Große            array('internalmedia',array($file,null,null,null,null,'cache','details')),
96db42b6f8SMichael Große            array('cdata',array(null)),
97db42b6f8SMichael Große            array('p_close',array()),
98db42b6f8SMichael Große            array('document_end',array()),
99db42b6f8SMichael Große        );
100db42b6f8SMichael Große        $this->assertEquals(array_map('stripbyteindex',$parser_response),$calls);
101db42b6f8SMichael Große
102db42b6f8SMichael Große        $Renderer = new Doku_Renderer_xhtml();
103db42b6f8SMichael Große        $url = $Renderer->externalmedia($file,null,null,null,null,'cache','details',true);
104db42b6f8SMichael Große
105*d09fc643SPhil Hopper        $video = '<video class="media" width="320" height="240" controls="controls" poster="' . DOKU_BASE . 'lib/exe/fetch.php?media=wiki:kind_zu_katze.png">';
106*d09fc643SPhil Hopper        $substr_start = 0;
107*d09fc643SPhil Hopper        $substr_len = strlen($video);
108*d09fc643SPhil Hopper        $this->assertEquals($video, substr($url, $substr_start, $substr_len));
109db42b6f8SMichael Große
110*d09fc643SPhil Hopper        // find $source_webm in $url
111*d09fc643SPhil Hopper        $source_webm = '<source src="' . DOKU_BASE . 'lib/exe/fetch.php?media=wiki:kind_zu_katze.webm" type="video/webm" />';
112*d09fc643SPhil Hopper        $substr_start = strpos($url, $source_webm, $substr_start + $substr_len);
113*d09fc643SPhil Hopper        $this->assertNotSame(false, $substr_start, 'Substring not found.');
114db42b6f8SMichael Große
115*d09fc643SPhil Hopper        // find $source_ogv in $url
116*d09fc643SPhil Hopper        $source_ogv = '<source src="' . DOKU_BASE . 'lib/exe/fetch.php?media=wiki:kind_zu_katze.ogv" type="video/ogg" />';
117*d09fc643SPhil Hopper        $substr_start = strpos($url, $source_ogv, $substr_start + strlen($source_webm));
118*d09fc643SPhil Hopper        $this->assertNotSame(false, $substr_start, 'Substring not found.');
119*d09fc643SPhil Hopper
120*d09fc643SPhil Hopper        // find $a_webm in $url
121*d09fc643SPhil Hopper        $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 KB)">kind_zu_katze.webm</a>';
122*d09fc643SPhil Hopper        $substr_start = strpos($url, $a_webm, $substr_start + strlen($source_ogv));
123*d09fc643SPhil Hopper        $this->assertNotSame(false, $substr_start, 'Substring not found.');
124*d09fc643SPhil Hopper
125*d09fc643SPhil Hopper        // find $a_webm in $url
126*d09fc643SPhil Hopper        $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 KB)">kind_zu_katze.ogv</a>';
127*d09fc643SPhil Hopper        $substr_start = strpos($url, $a_ogv, $substr_start + strlen($a_webm));
128*d09fc643SPhil Hopper        $this->assertNotSame(false, $substr_start, 'Substring not found.');
129db42b6f8SMichael Große
130db42b6f8SMichael Große        $rest = '</video>'."\n";
131*d09fc643SPhil Hopper        $substr_start = strlen($url) - strlen($rest);
132*d09fc643SPhil Hopper        $this->assertEquals($rest, substr($url, $substr_start));
133db42b6f8SMichael Große    }
134912be8f6SMichael Große}
135