diff options
Diffstat (limited to 'tests')
-rw-r--r--[-rwxr-xr-x] | tests/ConfigTest.php | 354 | ||||
-rw-r--r--[-rwxr-xr-x] | tests/PluginManagerTest.php | 12 | ||||
-rw-r--r--[-rwxr-xr-x] | tests/RouterTest.php | 2 | ||||
-rw-r--r--[-rwxr-xr-x] | tests/plugins/test/test.php | 0 |
4 files changed, 184 insertions, 184 deletions
diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index a239d8b7..adebfcc3 100755..100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php | |||
@@ -1,177 +1,177 @@ | |||
1 | <?php | 1 | <?php |
2 | /** | 2 | /** |
3 | * Config' tests | 3 | * Config' tests |
4 | */ | 4 | */ |
5 | 5 | ||
6 | require_once 'application/Config.php'; | 6 | require_once 'application/Config.php'; |
7 | 7 | ||
8 | /** | 8 | /** |
9 | * Unitary tests for Shaarli config related functions | 9 | * Unitary tests for Shaarli config related functions |
10 | */ | 10 | */ |
11 | class ConfigTest extends PHPUnit_Framework_TestCase | 11 | class ConfigTest extends PHPUnit_Framework_TestCase |
12 | { | 12 | { |
13 | // Configuration input set. | 13 | // Configuration input set. |
14 | private static $_configFields; | 14 | private static $configFields; |
15 | 15 | ||
16 | /** | 16 | /** |
17 | * Executed before each test. | 17 | * Executed before each test. |
18 | */ | 18 | */ |
19 | public function setUp() | 19 | public function setUp() |
20 | { | 20 | { |
21 | self::$_configFields = array( | 21 | self::$configFields = array( |
22 | 'login' => 'login', | 22 | 'login' => 'login', |
23 | 'hash' => 'hash', | 23 | 'hash' => 'hash', |
24 | 'salt' => 'salt', | 24 | 'salt' => 'salt', |
25 | 'timezone' => 'Europe/Paris', | 25 | 'timezone' => 'Europe/Paris', |
26 | 'title' => 'title', | 26 | 'title' => 'title', |
27 | 'titleLink' => 'titleLink', | 27 | 'titleLink' => 'titleLink', |
28 | 'redirector' => '', | 28 | 'redirector' => '', |
29 | 'disablesessionprotection' => false, | 29 | 'disablesessionprotection' => false, |
30 | 'privateLinkByDefault' => false, | 30 | 'privateLinkByDefault' => false, |
31 | 'config' => array( | 31 | 'config' => array( |
32 | 'CONFIG_FILE' => 'tests/config.php', | 32 | 'CONFIG_FILE' => 'tests/config.php', |
33 | 'DATADIR' => 'tests', | 33 | 'DATADIR' => 'tests', |
34 | 'config1' => 'config1data', | 34 | 'config1' => 'config1data', |
35 | 'config2' => 'config2data', | 35 | 'config2' => 'config2data', |
36 | ) | 36 | ) |
37 | ); | 37 | ); |
38 | } | 38 | } |
39 | 39 | ||
40 | /** | 40 | /** |
41 | * Executed after each test. | 41 | * Executed after each test. |
42 | * | 42 | * |
43 | * @return void | 43 | * @return void |
44 | */ | 44 | */ |
45 | public function tearDown() | 45 | public function tearDown() |
46 | { | 46 | { |
47 | if (is_file(self::$_configFields['config']['CONFIG_FILE'])) { | 47 | if (is_file(self::$configFields['config']['CONFIG_FILE'])) { |
48 | unlink(self::$_configFields['config']['CONFIG_FILE']); | 48 | unlink(self::$configFields['config']['CONFIG_FILE']); |
49 | } | 49 | } |
50 | } | 50 | } |
51 | 51 | ||
52 | /** | 52 | /** |
53 | * Test writeConfig function, valid use case, while being logged in. | 53 | * Test writeConfig function, valid use case, while being logged in. |
54 | */ | 54 | */ |
55 | public function testWriteConfig() | 55 | public function testWriteConfig() |
56 | { | 56 | { |
57 | writeConfig(self::$_configFields, true); | 57 | writeConfig(self::$configFields, true); |
58 | 58 | ||
59 | include self::$_configFields['config']['CONFIG_FILE']; | 59 | include self::$configFields['config']['CONFIG_FILE']; |
60 | $this->assertEquals(self::$_configFields['login'], $GLOBALS['login']); | 60 | $this->assertEquals(self::$configFields['login'], $GLOBALS['login']); |
61 | $this->assertEquals(self::$_configFields['hash'], $GLOBALS['hash']); | 61 | $this->assertEquals(self::$configFields['hash'], $GLOBALS['hash']); |
62 | $this->assertEquals(self::$_configFields['salt'], $GLOBALS['salt']); | 62 | $this->assertEquals(self::$configFields['salt'], $GLOBALS['salt']); |
63 | $this->assertEquals(self::$_configFields['timezone'], $GLOBALS['timezone']); | 63 | $this->assertEquals(self::$configFields['timezone'], $GLOBALS['timezone']); |
64 | $this->assertEquals(self::$_configFields['title'], $GLOBALS['title']); | 64 | $this->assertEquals(self::$configFields['title'], $GLOBALS['title']); |
65 | $this->assertEquals(self::$_configFields['titleLink'], $GLOBALS['titleLink']); | 65 | $this->assertEquals(self::$configFields['titleLink'], $GLOBALS['titleLink']); |
66 | $this->assertEquals(self::$_configFields['redirector'], $GLOBALS['redirector']); | 66 | $this->assertEquals(self::$configFields['redirector'], $GLOBALS['redirector']); |
67 | $this->assertEquals(self::$_configFields['disablesessionprotection'], $GLOBALS['disablesessionprotection']); | 67 | $this->assertEquals(self::$configFields['disablesessionprotection'], $GLOBALS['disablesessionprotection']); |
68 | $this->assertEquals(self::$_configFields['privateLinkByDefault'], $GLOBALS['privateLinkByDefault']); | 68 | $this->assertEquals(self::$configFields['privateLinkByDefault'], $GLOBALS['privateLinkByDefault']); |
69 | $this->assertEquals(self::$_configFields['config']['config1'], $GLOBALS['config']['config1']); | 69 | $this->assertEquals(self::$configFields['config']['config1'], $GLOBALS['config']['config1']); |
70 | $this->assertEquals(self::$_configFields['config']['config2'], $GLOBALS['config']['config2']); | 70 | $this->assertEquals(self::$configFields['config']['config2'], $GLOBALS['config']['config2']); |
71 | } | 71 | } |
72 | 72 | ||
73 | /** | 73 | /** |
74 | * Test writeConfig option while logged in: | 74 | * Test writeConfig option while logged in: |
75 | * 1. init fields. | 75 | * 1. init fields. |
76 | * 2. update fields, add new sub config, add new root config. | 76 | * 2. update fields, add new sub config, add new root config. |
77 | * 3. rewrite config. | 77 | * 3. rewrite config. |
78 | * 4. check result. | 78 | * 4. check result. |
79 | */ | 79 | */ |
80 | public function testWriteConfigFieldUpdate() | 80 | public function testWriteConfigFieldUpdate() |
81 | { | 81 | { |
82 | writeConfig(self::$_configFields, true); | 82 | writeConfig(self::$configFields, true); |
83 | self::$_configFields['title'] = 'ok'; | 83 | self::$configFields['title'] = 'ok'; |
84 | self::$_configFields['config']['config1'] = 'ok'; | 84 | self::$configFields['config']['config1'] = 'ok'; |
85 | self::$_configFields['config']['config_new'] = 'ok'; | 85 | self::$configFields['config']['config_new'] = 'ok'; |
86 | self::$_configFields['new'] = 'should not be saved'; | 86 | self::$configFields['new'] = 'should not be saved'; |
87 | writeConfig(self::$_configFields, true); | 87 | writeConfig(self::$configFields, true); |
88 | 88 | ||
89 | include self::$_configFields['config']['CONFIG_FILE']; | 89 | include self::$configFields['config']['CONFIG_FILE']; |
90 | $this->assertEquals('ok', $GLOBALS['title']); | 90 | $this->assertEquals('ok', $GLOBALS['title']); |
91 | $this->assertEquals('ok', $GLOBALS['config']['config1']); | 91 | $this->assertEquals('ok', $GLOBALS['config']['config1']); |
92 | $this->assertEquals('ok', $GLOBALS['config']['config_new']); | 92 | $this->assertEquals('ok', $GLOBALS['config']['config_new']); |
93 | $this->assertFalse(isset($GLOBALS['new'])); | 93 | $this->assertFalse(isset($GLOBALS['new'])); |
94 | } | 94 | } |
95 | 95 | ||
96 | /** | 96 | /** |
97 | * Test writeConfig function with an empty array. | 97 | * Test writeConfig function with an empty array. |
98 | * | 98 | * |
99 | * @expectedException MissingFieldConfigException | 99 | * @expectedException MissingFieldConfigException |
100 | */ | 100 | */ |
101 | public function testWriteConfigEmpty() | 101 | public function testWriteConfigEmpty() |
102 | { | 102 | { |
103 | writeConfig(array(), true); | 103 | writeConfig(array(), true); |
104 | } | 104 | } |
105 | 105 | ||
106 | /** | 106 | /** |
107 | * Test writeConfig function with a missing mandatory field. | 107 | * Test writeConfig function with a missing mandatory field. |
108 | * | 108 | * |
109 | * @expectedException MissingFieldConfigException | 109 | * @expectedException MissingFieldConfigException |
110 | */ | 110 | */ |
111 | public function testWriteConfigMissingField() | 111 | public function testWriteConfigMissingField() |
112 | { | 112 | { |
113 | unset(self::$_configFields['login']); | 113 | unset(self::$configFields['login']); |
114 | writeConfig(self::$_configFields, true); | 114 | writeConfig(self::$configFields, true); |
115 | } | 115 | } |
116 | 116 | ||
117 | /** | 117 | /** |
118 | * Test writeConfig function while being logged out, and there is no config file existing. | 118 | * Test writeConfig function while being logged out, and there is no config file existing. |
119 | */ | 119 | */ |
120 | public function testWriteConfigLoggedOutNoFile() | 120 | public function testWriteConfigLoggedOutNoFile() |
121 | { | 121 | { |
122 | writeConfig(self::$_configFields, false); | 122 | writeConfig(self::$configFields, false); |
123 | } | 123 | } |
124 | 124 | ||
125 | /** | 125 | /** |
126 | * Test writeConfig function while being logged out, and a config file already exists. | 126 | * Test writeConfig function while being logged out, and a config file already exists. |
127 | * | 127 | * |
128 | * @expectedException UnauthorizedConfigException | 128 | * @expectedException UnauthorizedConfigException |
129 | */ | 129 | */ |
130 | public function testWriteConfigLoggedOutWithFile() | 130 | public function testWriteConfigLoggedOutWithFile() |
131 | { | 131 | { |
132 | file_put_contents(self::$_configFields['config']['CONFIG_FILE'], ''); | 132 | file_put_contents(self::$configFields['config']['CONFIG_FILE'], ''); |
133 | writeConfig(self::$_configFields, false); | 133 | writeConfig(self::$configFields, false); |
134 | } | 134 | } |
135 | 135 | ||
136 | /** | 136 | /** |
137 | * Test mergeDeprecatedConfig while being logged in: | 137 | * Test mergeDeprecatedConfig while being logged in: |
138 | * 1. init a config file. | 138 | * 1. init a config file. |
139 | * 2. init a options.php file with update value. | 139 | * 2. init a options.php file with update value. |
140 | * 3. merge. | 140 | * 3. merge. |
141 | * 4. check updated value in config file. | 141 | * 4. check updated value in config file. |
142 | */ | 142 | */ |
143 | public function testMergeDeprecatedConfig() | 143 | public function testMergeDeprecatedConfig() |
144 | { | 144 | { |
145 | // init | 145 | // init |
146 | writeConfig(self::$_configFields, true); | 146 | writeConfig(self::$configFields, true); |
147 | $configCopy = self::$_configFields; | 147 | $configCopy = self::$configFields; |
148 | $invert = !$configCopy['privateLinkByDefault']; | 148 | $invert = !$configCopy['privateLinkByDefault']; |
149 | $configCopy['privateLinkByDefault'] = $invert; | 149 | $configCopy['privateLinkByDefault'] = $invert; |
150 | 150 | ||
151 | // Use writeConfig to create a options.php | 151 | // Use writeConfig to create a options.php |
152 | $configCopy['config']['CONFIG_FILE'] = 'tests/options.php'; | 152 | $configCopy['config']['CONFIG_FILE'] = 'tests/options.php'; |
153 | writeConfig($configCopy, true); | 153 | writeConfig($configCopy, true); |
154 | 154 | ||
155 | $this->assertTrue(is_file($configCopy['config']['CONFIG_FILE'])); | 155 | $this->assertTrue(is_file($configCopy['config']['CONFIG_FILE'])); |
156 | 156 | ||
157 | // merge configs | 157 | // merge configs |
158 | mergeDeprecatedConfig(self::$_configFields, true); | 158 | mergeDeprecatedConfig(self::$configFields, true); |
159 | 159 | ||
160 | // make sure updated field is changed | 160 | // make sure updated field is changed |
161 | include self::$_configFields['config']['CONFIG_FILE']; | 161 | include self::$configFields['config']['CONFIG_FILE']; |
162 | $this->assertEquals($invert, $GLOBALS['privateLinkByDefault']); | 162 | $this->assertEquals($invert, $GLOBALS['privateLinkByDefault']); |
163 | $this->assertFalse(is_file($configCopy['config']['CONFIG_FILE'])); | 163 | $this->assertFalse(is_file($configCopy['config']['CONFIG_FILE'])); |
164 | } | 164 | } |
165 | 165 | ||
166 | /** | 166 | /** |
167 | * Test mergeDeprecatedConfig while being logged in without options file. | 167 | * Test mergeDeprecatedConfig while being logged in without options file. |
168 | */ | 168 | */ |
169 | public function testMergeDeprecatedConfigNoFile() | 169 | public function testMergeDeprecatedConfigNoFile() |
170 | { | 170 | { |
171 | writeConfig(self::$_configFields, true); | 171 | writeConfig(self::$configFields, true); |
172 | mergeDeprecatedConfig(self::$_configFields, true); | 172 | mergeDeprecatedConfig(self::$configFields, true); |
173 | 173 | ||
174 | include self::$_configFields['config']['CONFIG_FILE']; | 174 | include self::$configFields['config']['CONFIG_FILE']; |
175 | $this->assertEquals(self::$_configFields['login'], $GLOBALS['login']); | 175 | $this->assertEquals(self::$configFields['login'], $GLOBALS['login']); |
176 | } | 176 | } |
177 | } | 177 | } |
diff --git a/tests/PluginManagerTest.php b/tests/PluginManagerTest.php index 749ce2b5..df2614b5 100755..100644 --- a/tests/PluginManagerTest.php +++ b/tests/PluginManagerTest.php | |||
@@ -13,15 +13,15 @@ class PluginManagerTest extends PHPUnit_Framework_TestCase | |||
13 | { | 13 | { |
14 | /** | 14 | /** |
15 | * Path to tests plugin. | 15 | * Path to tests plugin. |
16 | * @var string $_PLUGIN_PATH | 16 | * @var string $pluginPath |
17 | */ | 17 | */ |
18 | private static $_PLUGIN_PATH = 'tests/plugins'; | 18 | private static $pluginPath = 'tests/plugins'; |
19 | 19 | ||
20 | /** | 20 | /** |
21 | * Test plugin. | 21 | * Test plugin. |
22 | * @var string $_PLUGIN_NAME | 22 | * @var string $pluginName |
23 | */ | 23 | */ |
24 | private static $_PLUGIN_NAME = 'test'; | 24 | private static $pluginName = 'test'; |
25 | 25 | ||
26 | /** | 26 | /** |
27 | * Test plugin loading and hook execution. | 27 | * Test plugin loading and hook execution. |
@@ -32,8 +32,8 @@ class PluginManagerTest extends PHPUnit_Framework_TestCase | |||
32 | { | 32 | { |
33 | $pluginManager = PluginManager::getInstance(); | 33 | $pluginManager = PluginManager::getInstance(); |
34 | 34 | ||
35 | PluginManager::$PLUGINS_PATH = self::$_PLUGIN_PATH; | 35 | PluginManager::$PLUGINS_PATH = self::$pluginPath; |
36 | $pluginManager->load(array(self::$_PLUGIN_NAME)); | 36 | $pluginManager->load(array(self::$pluginName)); |
37 | 37 | ||
38 | $this->assertTrue(function_exists('hook_test_random')); | 38 | $this->assertTrue(function_exists('hook_test_random')); |
39 | 39 | ||
diff --git a/tests/RouterTest.php b/tests/RouterTest.php index 8838bc8d..544bcf9c 100755..100644 --- a/tests/RouterTest.php +++ b/tests/RouterTest.php | |||
@@ -512,4 +512,4 @@ class RouterTest extends PHPUnit_Framework_TestCase | |||
512 | Router::findPage('whatever', array(), true) | 512 | Router::findPage('whatever', array(), true) |
513 | ); | 513 | ); |
514 | } | 514 | } |
515 | } \ No newline at end of file | 515 | } |
diff --git a/tests/plugins/test/test.php b/tests/plugins/test/test.php index 3d750c90..3d750c90 100755..100644 --- a/tests/plugins/test/test.php +++ b/tests/plugins/test/test.php | |||