1<?php
2
3/**
4 * tests for the fetchmedia plugin
5 *
6 * @group plugin_fetchmedia
7 * @group plugins
8 */
9class FindMediaLinks_plugin_fetchmedia_test extends DokuWikiTest {
10    /**
11     * tests can override this
12     *
13     * @var array plugins to enable for test class
14     */
15    protected $pluginsEnabled = array('fetchmedia');
16
17    public function test_findmedialinks() {
18        /** @var action_plugin_fetchmedia_ajax $plugin */
19        $plugin = plugin_load('action', 'fetchmedia_ajax');
20        $actual_links = $plugin->findExternalMediaFiles('wiki', 'all');
21        $expected_links = [
22            'wiki:syntax' =>
23                [
24                    '\\\\server\\share',
25                    'http://php.net/images/php.gif',
26                ],
27        ];
28        $this->assertEquals($expected_links, $actual_links);
29    }
30
31    public function test_filenameConstruction() {
32        /** @var action_plugin_fetchmedia_ajax $plugin */
33        $plugin = plugin_load('action', 'fetchmedia_ajax');
34        $actual_filename = $plugin->constructFileName('http://php.net/images/php.gif');
35        $expected_filename = 'php.gif';
36        $this->assertEquals($expected_filename, $actual_filename);
37
38        $actual_filename = $plugin->constructFileName('\\\\server\\share\\file.pdf');
39        $expected_filename = 'file.pdf';
40        $this->assertEquals($expected_filename, $actual_filename);
41    }
42
43    public function test_replaceLinksInText_externalMedia() {
44        /** @var action_plugin_fetchmedia_ajax $plugin */
45        $plugin = plugin_load('action', 'fetchmedia_ajax');
46        $text = '
47Resized external image:           {{http://php.net/images/php.gif?200x50}}
48
49  Real size:                        {{wiki:dokuwiki-128.png}}';
50        $actual_text = $plugin->replaceLinkInText($text, 'http://php.net/images/php.gif', 'wiki:php.gif');
51        $expected_text = '
52Resized external image:           {{wiki:php.gif?200x50}}
53
54  Real size:                        {{wiki:dokuwiki-128.png}}';
55        $this->assertEquals($expected_text, $actual_text);
56    }
57
58    public function test_replaceLinksInText_windowsShare() {
59        /** @var action_plugin_fetchmedia_ajax $plugin */
60        $plugin = plugin_load('action', 'fetchmedia_ajax');
61        $text = 'Windows shares like [[\\\\server\\share\\file.pdf|this]] are recognized, too. Please note that these only make sense in a homogeneous user group like a corporate [[wp>Intranet]].
62
63  Windows Shares like [[\\\\server\\share\\file.pdf|this]] are recognized, too.';
64        $actual_text = $plugin->replaceLinkInText($text, '\\\\server\\share\\file.pdf', 'wiki:file.pdf');
65        $expected_text = 'Windows shares like {{wiki:file.pdf|this}} are recognized, too. Please note that these only make sense in a homogeneous user group like a corporate [[wp>Intranet]].
66
67  Windows Shares like [[\\\\server\\share\\file.pdf|this]] are recognized, too.';
68        $this->assertEquals($expected_text, $actual_text);
69    }
70}
71