1<?php
2
3namespace dokuwiki\plugin\vshare\test;
4
5use DokuWikiTest;
6
7/**
8 * syntax handling tests for the vshare plugin
9 *
10 * @group plugin_vshare
11 * @group plugins
12 */
13class VideoSyntaxTest extends DokuWikiTest
14{
15
16    /**
17     * @return array[]
18     * @see testParseSize
19     */
20    public function provideParseSize()
21    {
22        return [
23            ['', 425, 239],
24            ['small', 255, 143],
25            ['Small', 255, 143],
26            ['178x123', 178, 123],
27            ['178X123', 178, 123],
28            ['small&medium', 255, 143, ['medium' => '']],
29            ['small&autoplay=false', 255, 143, ['autoplay' => 'false']],
30            ['178x123&autoplay=false', 178, 123, ['autoplay' => 'false']],
31            ['autoplay=false', 425, 239, ['autoplay' => 'false']],
32        ];
33    }
34
35    /**
36     * @dataProvider provideParseSize
37     * @param string $input
38     * @param int $ewidth
39     * @param int $eheight
40     * @param array $eparams
41     */
42    public function testParseSize($input, $ewidth, $eheight, $eparams = [])
43    {
44        $syntax = new \syntax_plugin_vshare_video();
45        parse_str($input, $params);
46        list($width, $height) = $syntax->parseSize($params);
47
48        $this->assertEquals($ewidth, $width, 'width');
49        $this->assertEquals($eheight, $height, 'height');
50        $this->assertEquals($eparams, $eparams, 'height');
51    }
52
53    /**
54     * @see testHandle
55     */
56    public function provideHandle()
57    {
58        return [
59            [
60                '{{youtube>L-WM8YxwqEU}}',
61                [
62                    'site' => 'youtube',
63                    'domain' => 'www.youtube-nocookie.com',
64                    'video' => 'L-WM8YxwqEU',
65                    'url' => '//www.youtube-nocookie.com/embed/L-WM8YxwqEU?',
66                    'align' => 'none',
67                    'width' => 425,
68                    'height' => 239,
69                    'title' => '',
70                ],
71            ],
72            [
73                '{{youtube>L-WM8YxwqEU?small&start=30&end=45|A random segment of 15 seconds}}',
74                [
75                    'site' => 'youtube',
76                    'domain' => 'www.youtube-nocookie.com',
77                    'video' => 'L-WM8YxwqEU',
78                    'url' => '//www.youtube-nocookie.com/embed/L-WM8YxwqEU?start=30&end=45',
79                    'align' => 'none',
80                    'width' => 255,
81                    'height' => 143,
82                    'title' => 'A random segment of 15 seconds',
83                ],
84            ],
85            // FIXME add more tests
86        ];
87    }
88
89    /**
90     * @dataProvider provideHandle
91     * @param string $input
92     * @param array $expect
93     */
94    public function testHandle($input, $expect)
95    {
96        $syntax = new \syntax_plugin_vshare_video();
97        $result = $syntax->handle($input, DOKU_LEXER_MATCHED, 0, new \Doku_Handler());
98        $this->assertEquals($expect, $result);
99    }
100}
101