xref: /dokuwiki/lib/plugins/extension/_test/InstallerTest.php (revision c29b8642e5a33eeae1853c0734c5a02906442aa7)
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            'template1' => ['template1', ['template1' => 'template']],
32            'tplfoo5' => ['tplfoo5', ['template5' => 'template']],
33            'tplsub3' => ['tplsub3', ['template3' => 'template']],
34            'tplsub4' => ['tplsub4', ['template4' => 'template']],
35            'tplsub6' => ['tplsub6', ['template6' => 'template']],
36            'multi' => ['multi', [
37                'multi1' => 'plugin',
38                'multi2' => 'plugin',
39                'multi3' => 'plugin',
40                'multi4' => 'template',
41                'multi5' => 'template'
42            ]],
43        ];
44    }
45
46    /**
47     * Test finding extensions in given directories
48     *
49     * @dataProvider provideFindExtensionsData
50     * @param string $dir
51     * @param array $expected
52     */
53    public function testFindExtensions($dir, $expected)
54    {
55        $installer = new Installer();
56        $list = $this->callInaccessibleMethod($installer, 'findExtensions', [__DIR__ . '/testdata/' . $dir]);
57        $this->assertEquals(count($expected), count($list), 'number of extensions found');
58
59        foreach ($list as $ext) {
60            $base = $ext->getBase();
61            $this->assertArrayHasKey($base, $expected, 'extension found');
62            $this->assertEquals($expected[$base], $ext->getType(), 'extension type');
63        }
64    }
65}
66