aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/ApplicationUtilsTest.php
blob: 01301e689dec6bc47b12dc59aa68b585cd7cd860 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/**
 * ApplicationUtils' tests
 */

require_once 'application/ApplicationUtils.php';


/**
 * Unitary tests for Shaarli utilities
 */
class ApplicationUtilsTest extends PHPUnit_Framework_TestCase
{
    /**
     * Check supported PHP versions
     */
    public function testCheckSupportedPHPVersion()
    {
        $minVersion = '5.3';
        ApplicationUtils::checkPHPVersion($minVersion, '5.4.32');
        ApplicationUtils::checkPHPVersion($minVersion, '5.5');
        ApplicationUtils::checkPHPVersion($minVersion, '5.6.10');
    }

    /**
     * Check a unsupported PHP version
     * @expectedException              Exception
     * @expectedExceptionMessageRegExp /Your PHP version is obsolete/
     */
    public function testCheckSupportedPHPVersion51()
    {
        ApplicationUtils::checkPHPVersion('5.3', '5.1.0');
    }

    /**
     * Check another unsupported PHP version
     * @expectedException              Exception
     * @expectedExceptionMessageRegExp /Your PHP version is obsolete/
     */
    public function testCheckSupportedPHPVersion52()
    {
        ApplicationUtils::checkPHPVersion('5.3', '5.2');
    }

    /**
     * Checks resource permissions for the current Shaarli installation
     */
    public function testCheckCurrentResourcePermissions()
    {
        $config = array(
            'CACHEDIR' => 'cache',
            'CONFIG_FILE' => 'data/config.php',
            'DATADIR' => 'data',
            'DATASTORE' => 'data/datastore.php',
            'IPBANS_FILENAME' => 'data/ipbans.php',
            'LOG_FILE' => 'data/log.txt',
            'PAGECACHE' => 'pagecache',
            'RAINTPL_TMP' => 'tmp',
            'RAINTPL_TPL' => 'tpl',
            'UPDATECHECK_FILENAME' => 'data/lastupdatecheck.txt'
        );
        $this->assertEquals(
            array(),
            ApplicationUtils::checkResourcePermissions($config)
        );
    }

    /**
     * Checks resource permissions for a non-existent Shaarli installation
     */
    public function testCheckCurrentResourcePermissionsErrors()
    {
        $config = array(
            'CACHEDIR' => 'null/cache',
            'CONFIG_FILE' => 'null/data/config.php',
            'DATADIR' => 'null/data',
            'DATASTORE' => 'null/data/store.php',
            'IPBANS_FILENAME' => 'null/data/ipbans.php',
            'LOG_FILE' => 'null/data/log.txt',
            'PAGECACHE' => 'null/pagecache',
            'RAINTPL_TMP' => 'null/tmp',
            'RAINTPL_TPL' => 'null/tpl',
            'UPDATECHECK_FILENAME' => 'null/data/lastupdatecheck.txt'
        );
        $this->assertEquals(
            array(
                '"null/tpl" directory is not readable',
                '"null/cache" directory is not readable',
                '"null/cache" directory is not writable',
                '"null/data" directory is not readable',
                '"null/data" directory is not writable',
                '"null/pagecache" directory is not readable',
                '"null/pagecache" directory is not writable',
                '"null/tmp" directory is not readable',
                '"null/tmp" directory is not writable'
            ),
            ApplicationUtils::checkResourcePermissions($config)
        );
    }
}