1<?php
2
3namespace dokuwiki\plugin\dw2pdf\test;
4
5use dokuwiki\plugin\dw2pdf\DokuImageProcessorDecorator;
6use DokuWikiTest;
7
8/**
9 * General tests for the imagemap plugin
10 *
11 * @group plugin_dw2pdf
12 * @group plugins
13 */
14class DokuImageProcessorTest extends DokuWikiTest
15{
16    public static function setUpBeforeClass(): void
17    {
18        parent::setUpBeforeClass();
19        require_once __DIR__ . '/../vendor/autoload.php';
20    }
21
22
23    /**
24     * @return array the Testdata
25     */
26    public function provideGetImageTestdata() {
27        global $conf;
28
29        return [
30            [
31                DOKU_URL . 'lib/exe/fetch.php?tok=b0b7a3&media=http%3A%2F%2Fphp.net%2Fimages%2Fphp.gif',
32                DOKU_REL . 'lib/exe/fetch.php?tok=b0b7a3&media=http%3A%2F%2Fphp.net%2Fimages%2Fphp.gif',
33                'http://php.net/images/php.gif',
34                'http://php.net/images/php.gif',
35                'external image',
36            ],
37            [
38                DOKU_URL . 'lib/images/throbber.gif',
39                DOKU_REL . 'lib/images/throbber.gif',
40                DOKU_INC . 'lib/images/throbber.gif',
41                DOKU_INC . 'lib/images/throbber.gif',
42                'fixed standard image',
43            ],
44            [
45                DOKU_URL . 'lib/exe/fetch.php?media=wiki:dokuwiki-128.png',
46                DOKU_REL . 'lib/exe/fetch.php?media=wiki:dokuwiki-128.png',
47                $conf['mediadir'] . '/wiki/dokuwiki-128.png',
48                $conf['mediadir'] . '/wiki/dokuwiki-128.png',
49                'Internal image',
50            ],
51        ];
52    }
53
54    /**
55     * @dataProvider provideGetImageTestdata
56     *
57     * @param $input_file
58     * @param $input_orig_srcpath
59     * @param $expected_file
60     * @param $expected_orig_srcpath
61     * @param $msg
62     */
63    public function testGetImage($input_file, $input_orig_srcpath, $expected_file, $expected_orig_srcpath, $msg)
64    {
65
66        list($actual_file, $actual_orig_srcpath) = DokuImageProcessorDecorator::adjustGetImageLinks($input_file,
67            $input_orig_srcpath);
68
69        $this->assertEquals($expected_file, $actual_file,  '$file ' . $msg);
70        $this->assertEquals($expected_orig_srcpath, $actual_orig_srcpath,  '$orig_srcpath ' . $msg);
71    }
72
73}
74