aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/render/ThemeUtilsTest.php
blob: 58e3426b2de3670ab40a2c12bc385c2b308652d8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php

namespace Shaarli\Render;

/**
 * Class ThemeUtilsTest
 *
 * @package Shaarli
 */
class ThemeUtilsTest extends \PHPUnit\Framework\TestCase
{
    /**
     * Test getThemes() with existing theme directories.
     */
    public function testGetThemes()
    {
        $themes = ['theme1', 'default', 'Bl1p_- bL0p'];
        foreach ($themes as $theme) {
            mkdir('sandbox/tpl/'. $theme, 0755, true);
        }

        // include a file which should be ignored
        touch('sandbox/tpl/supertheme');

        $res = ThemeUtils::getThemes('sandbox/tpl/');
        foreach ($res as $theme) {
            $this->assertTrue(in_array($theme, $themes));
        }
        $this->assertFalse(in_array('supertheme', $res));

        foreach ($themes as $theme) {
            rmdir('sandbox/tpl/'. $theme);
        }
        unlink('sandbox/tpl/supertheme');
        rmdir('sandbox/tpl');
    }

    /**
     * Test getThemes() without any theme dir.
     */
    public function testGetThemesEmpty()
    {
        mkdir('sandbox/tpl/', 0755, true);
        $this->assertEquals([], ThemeUtils::getThemes('sandbox/tpl/'));
        rmdir('sandbox/tpl/');
    }

    /**
     * Test getThemes() with an invalid path.
     */
    public function testGetThemesInvalid()
    {
        $this->assertEquals([], ThemeUtils::getThemes('nope'));
    }
}