]> git.immae.eu Git - github/shaarli/Shaarli.git/blame - tests/ApplicationUtilsTest.php
Merge pull request #355 from ArthurHoaro/redirector-url
[github/shaarli/Shaarli.git] / tests / ApplicationUtilsTest.php
CommitLineData
2e28269b
V
1<?php
2/**
3 * ApplicationUtils' tests
4 */
5
6require_once 'application/ApplicationUtils.php';
7
8
9/**
10 * Unitary tests for Shaarli utilities
11 */
12class ApplicationUtilsTest extends PHPUnit_Framework_TestCase
13{
c9cf2715
V
14 /**
15 * Check supported PHP versions
16 */
17 public function testCheckSupportedPHPVersion()
18 {
19 $minVersion = '5.3';
20 ApplicationUtils::checkPHPVersion($minVersion, '5.4.32');
21 ApplicationUtils::checkPHPVersion($minVersion, '5.5');
22 ApplicationUtils::checkPHPVersion($minVersion, '5.6.10');
23 }
24
25 /**
26 * Check a unsupported PHP version
27 * @expectedException Exception
28 * @expectedExceptionMessageRegExp /Your PHP version is obsolete/
29 */
30 public function testCheckSupportedPHPVersion51()
31 {
32 ApplicationUtils::checkPHPVersion('5.3', '5.1.0');
33 }
34
35 /**
36 * Check another unsupported PHP version
37 * @expectedException Exception
38 * @expectedExceptionMessageRegExp /Your PHP version is obsolete/
39 */
40 public function testCheckSupportedPHPVersion52()
41 {
42 ApplicationUtils::checkPHPVersion('5.3', '5.2');
43 }
44
2e28269b
V
45 /**
46 * Checks resource permissions for the current Shaarli installation
47 */
48 public function testCheckCurrentResourcePermissions()
49 {
50 $config = array(
51 'CACHEDIR' => 'cache',
52 'CONFIG_FILE' => 'data/config.php',
53 'DATADIR' => 'data',
54 'DATASTORE' => 'data/datastore.php',
55 'IPBANS_FILENAME' => 'data/ipbans.php',
56 'LOG_FILE' => 'data/log.txt',
57 'PAGECACHE' => 'pagecache',
58 'RAINTPL_TMP' => 'tmp',
59 'RAINTPL_TPL' => 'tpl',
60 'UPDATECHECK_FILENAME' => 'data/lastupdatecheck.txt'
61 );
62 $this->assertEquals(
63 array(),
64 ApplicationUtils::checkResourcePermissions($config)
65 );
66 }
67
68 /**
69 * Checks resource permissions for a non-existent Shaarli installation
70 */
71 public function testCheckCurrentResourcePermissionsErrors()
72 {
73 $config = array(
74 'CACHEDIR' => 'null/cache',
75 'CONFIG_FILE' => 'null/data/config.php',
76 'DATADIR' => 'null/data',
77 'DATASTORE' => 'null/data/store.php',
78 'IPBANS_FILENAME' => 'null/data/ipbans.php',
79 'LOG_FILE' => 'null/data/log.txt',
80 'PAGECACHE' => 'null/pagecache',
81 'RAINTPL_TMP' => 'null/tmp',
82 'RAINTPL_TPL' => 'null/tpl',
83 'UPDATECHECK_FILENAME' => 'null/data/lastupdatecheck.txt'
84 );
85 $this->assertEquals(
86 array(
87 '"null/tpl" directory is not readable',
88 '"null/cache" directory is not readable',
89 '"null/cache" directory is not writable',
90 '"null/data" directory is not readable',
91 '"null/data" directory is not writable',
92 '"null/pagecache" directory is not readable',
93 '"null/pagecache" directory is not writable',
94 '"null/tmp" directory is not readable',
95 '"null/tmp" directory is not writable'
96 ),
97 ApplicationUtils::checkResourcePermissions($config)
98 );
99 }
100}