xref: /dokuwiki/lib/plugins/extension/_test/InstallerTest.php (revision a1ef4d6260401c454faedc5d90cb3887bb07a19c)
1<?php
2
3namespace dokuwiki\plugin\extension\test;
4
5use dokuwiki\plugin\extension\Installer;
6use DokuWikiTest;
7
8/**
9 * Installer tests for the extension plugin
10 *
11 * @group plugin_extension
12 * @group plugins
13 */
14class InstallerTest extends DokuWikiTest
15{
16
17    /**
18     * Provide data for testFindExtensions
19     */
20    public function provideFindExtensionsData()
21    {
22        return [
23            'either1' => ['either1', ['either1' => 'plugin']],
24            'eithersub2' => ['eithersub2', ['either2' => 'plugin']],
25            'plgfoo5' => ['plgfoo5', ['plugin5' => 'plugin']],
26            'plgsub3' => ['plgsub3', ['plugin3' => 'plugin']],
27            'plgsub4' => ['plgsub4', ['plugin4' => 'plugin']],
28            'plgsub6' => ['plgsub6', ['plugin6' => 'plugin']],
29            'plugin1' => ['plugin1', ['plugin1' => 'plugin']],
30            'plugin2' => ['plugin2', ['plugin2' => 'plugin']],
31            'plugin3' => ['plugin3', ['foobar' => 'plugin']],
32            'template1' => ['template1', ['template1' => 'template']],
33            'tplfoo5' => ['tplfoo5', ['template5' => 'template']],
34            'tplsub3' => ['tplsub3', ['template3' => 'template']],
35            'tplsub4' => ['tplsub4', ['template4' => 'template']],
36            'tplsub6' => ['tplsub6', ['template6' => 'template']],
37            'multi' => ['multi', [
38                'multi1' => 'plugin',
39                'multi2' => 'plugin',
40                'multi3' => 'plugin',
41                'multi4' => 'template',
42                'multi5' => 'template'
43            ]],
44        ];
45    }
46
47    /**
48     * Test finding extensions in given directories
49     *
50     * @dataProvider provideFindExtensionsData
51     * @param string $dir
52     * @param array $expected
53     */
54    public function testFindExtensions($dir, $expected)
55    {
56        $installer = new Installer();
57        $list = $this->callInaccessibleMethod($installer, 'findExtensions', [__DIR__ . '/testdata/' . $dir]);
58        $this->assertEquals(count($expected), count($list), 'number of extensions found');
59
60        foreach ($list as $ext) {
61            $base = $ext->getBase();
62            $this->assertArrayHasKey($base, $expected, 'extension found');
63            $this->assertEquals($expected[$base], $ext->getType(), 'extension type');
64        }
65    }
66}
67