xref: /dokuwiki/_test/tests/inc/parser/parser_media.test.php (revision db42b6f8860359481248e9bc847b111497511d03) !
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
33912be8f6SMichael Große        $a_first_part = '<a href="/./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">';
35912be8f6SMichael Große        $this->assertEquals(substr($url,132,45),$a_first_part);
36912be8f6SMichael Große        $this->assertEquals(substr($url,183,121),$a_second_part);
37912be8f6SMichael Große        $rest = 'away.ogv</a></video>'."\n";
38912be8f6SMichael Große        $this->assertEquals(substr($url,304),$rest);
39912be8f6SMichael Große    }
40912be8f6SMichael Große
41912be8f6SMichael Große    /**
42912be8f6SMichael Große     * unknown extension of external media file
43912be8f6SMichael Große     */
44912be8f6SMichael Große    function testVideoVIDExternal() {
45912be8f6SMichael Große        $file = 'http://some.where.far/away.vid';
46912be8f6SMichael Große        $parser_response = p_get_instructions('{{' . $file . '}}');
47912be8f6SMichael Große
48912be8f6SMichael Große        $calls = array(
49912be8f6SMichael Große            array('document_start', array()),
50912be8f6SMichael Große            array('p_open', array()),
51912be8f6SMichael Große            array('externalmedia', array($file, null, null, null, null, 'cache', 'details')),
52912be8f6SMichael Große            array('cdata', array(null)),
53912be8f6SMichael Große            array('p_close', array()),
54912be8f6SMichael Große            array('document_end', array()),
55912be8f6SMichael Große        );
56912be8f6SMichael Große        $this->assertEquals(array_map('stripbyteindex', $parser_response), $calls);
57912be8f6SMichael Große
58912be8f6SMichael Große        $Renderer = new Doku_Renderer_xhtml();
59912be8f6SMichael Große        $url = $Renderer->externalmedia($file, null, null, null, null, 'cache', 'details', true);
60912be8f6SMichael Große        // work around random token
61912be8f6SMichael Große        $a_first_part = '<a href="/./lib/exe/fetch.php?tok=';
62912be8f6SMichael 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">';
63912be8f6SMichael Große        $this->assertEquals(substr($url,0,34),$a_first_part);
64912be8f6SMichael Große        $this->assertEquals(substr($url,40,121),$a_second_part);
65912be8f6SMichael Große        $rest = 'away.vid</a>';
66912be8f6SMichael Große        $this->assertEquals(substr($url,161),$rest);
67912be8f6SMichael Große    }
68*db42b6f8SMichael Große
69*db42b6f8SMichael Große
70*db42b6f8SMichael Große    function testVideoOGVInternal() {
71*db42b6f8SMichael Große        $file = 'wiki:kind_zu_katze.ogv';
72*db42b6f8SMichael Große        $parser_response = p_get_instructions('{{' . $file . '}}');
73*db42b6f8SMichael Große
74*db42b6f8SMichael Große        $calls = array (
75*db42b6f8SMichael Große            array('document_start',array()),
76*db42b6f8SMichael Große            array('p_open',array()),
77*db42b6f8SMichael Große            array('internalmedia',array($file,null,null,null,null,'cache','details')),
78*db42b6f8SMichael Große            array('cdata',array(null)),
79*db42b6f8SMichael Große            array('p_close',array()),
80*db42b6f8SMichael Große            array('document_end',array()),
81*db42b6f8SMichael Große        );
82*db42b6f8SMichael Große        $this->assertEquals(array_map('stripbyteindex',$parser_response),$calls);
83*db42b6f8SMichael Große
84*db42b6f8SMichael Große        $Renderer = new Doku_Renderer_xhtml();
85*db42b6f8SMichael Große        $url = $Renderer->externalmedia($file,null,null,null,null,'cache','details',true);
86*db42b6f8SMichael Große
87*db42b6f8SMichael Große        $video = '<video class="media" width="320" height="240" controls="controls" poster="/./lib/exe/fetch.php?media=wiki:kind_zu_katze.png">';
88*db42b6f8SMichael Große        $this->assertEquals(substr($url,0,125),$video);
89*db42b6f8SMichael Große
90*db42b6f8SMichael Große        $source_webm = '<source src="/./lib/exe/fetch.php?media=wiki:kind_zu_katze.webm" type="video/webm" />';
91*db42b6f8SMichael Große        $this->assertEquals(substr($url,126,85),$source_webm);
92*db42b6f8SMichael Große        $source_ogv = '<source src="/./lib/exe/fetch.php?media=wiki:kind_zu_katze.ogv" type="video/ogg" />';
93*db42b6f8SMichael Große        $this->assertEquals(substr($url,212,83),$source_ogv);
94*db42b6f8SMichael Große
95*db42b6f8SMichael Große        $a_webm = '<a href="/./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.2 KB)">kind_zu_katze.webm</a>';
96*db42b6f8SMichael Große        $a_ogv = '<a href="/./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>';
97*db42b6f8SMichael Große        $this->assertEquals(substr($url,296,176),$a_webm);
98*db42b6f8SMichael Große        $this->assertEquals(substr($url,472,172),$a_ogv);
99*db42b6f8SMichael Große
100*db42b6f8SMichael Große        $rest = '</video>'."\n";
101*db42b6f8SMichael Große        $this->assertEquals(substr($url,644),$rest);
102*db42b6f8SMichael Große    }
103912be8f6SMichael Große}
104912be8f6SMichael Große
105912be8f6SMichael Große/**
106912be8f6SMichael Große * .oga:
107912be8f6SMichael Große * http://upload.wikimedia.org/wikipedia/commons/6/6b/Meow_of_a_pleading_cat.oga
108912be8f6SMichael Große *
109912be8f6SMichael Große * .wav:
110912be8f6SMichael Große * http://upload.wikimedia.org/wikipedia/commons/8/81/Meow_of_a_Siamese_cat_-_freemaster2.wav
111912be8f6SMichael Große *
112912be8f6SMichael Große *
113912be8f6SMichael Große */
114