]> git.agnieray.net Git - galette.git/blob - tests/Galette/Core/tests/units/Plugins.php
93adda18c22bac7406d497e7758a0ed771506928
[galette.git] / tests / Galette / Core / tests / units / Plugins.php
1 <?php
2
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5 /**
6 * Plugins tests
7 *
8 * PHP version 5
9 *
10 * Copyright © 2013-2014 The Galette Team
11 *
12 * This file is part of Galette (http://galette.tuxfamily.org).
13 *
14 * Galette is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * Galette is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
26 *
27 * @category Core
28 * @package GaletteTests
29 *
30 * @author Johan Cwiklinski <johan@x-tnd.be>
31 * @copyright 2013-2014 The Galette Team
32 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
33 * @version SVN: $Id$
34 * @link http://galette.tuxfamily.org
35 * @since 2013-01-13
36 */
37
38 namespace Galette\Core\test\units;
39
40 use atoum;
41
42 /**
43 * Plugins tests class
44 *
45 * @category Core
46 * @name Plugins
47 * @package GaletteTests
48 * @author Johan Cwiklinski <johan@x-tnd.be>
49 * @copyright 2013-2014 The Galette Team
50 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
51 * @link http://galette.tuxfamily.org
52 * @since 2013-01-13
53 */
54 class Plugins extends atoum
55 {
56 private $zdb;
57 private $preferences;
58 private $plugins;
59
60 private $plugin2 = array(
61 'root' => 'plugin-test2',
62 'name' => 'Galette Test2 Plugin',
63 'desc' => 'Test two plugin',
64 'author' => 'Johan Cwiklinski',
65 'version' => '1.0',
66 'acls' => [
67 'plugin2_root' => 'member',
68 'plugin2_admin' => 'staff'
69 ],
70 'date' => '2013-12-15',
71 'priority' => 1000,
72 'root_writable' => true,
73 'route' => 'plugin2'
74 );
75
76 /**
77 * Get instanciated plugins instance
78 *
79 * @return Galette\Core\Plugins
80 */
81 private function getPlugins()
82 {
83 $plugins = new \Galette\Core\Plugins();
84 $plugins->autoload(GALETTE_PLUGINS_PATH);
85 $plugins->loadModules($this->preferences, GALETTE_PLUGINS_PATH);
86 return $plugins;
87 }
88
89 /**
90 * Set up tests
91 *
92 * @param string $testMethod Method tested
93 *
94 * @return void
95 */
96 public function beforeTestMethod($testMethod)
97 {
98 $this->zdb = new \Galette\Core\Db();
99 $this->preferences = new \Galette\Core\Preferences($this->zdb);
100
101 $this->plugins = $this->getPlugins();
102
103 $this->plugin2['root'] = GALETTE_PLUGINS_PATH .
104 $this->plugin2['root'];
105 }
106
107
108 /**
109 * Tests plugins load
110 *
111 * @return void
112 */
113 public function testLoadModules()
114 {
115 $plugins = $this->getPlugins();
116
117 $this->array($this->plugins->getModules())
118 ->hasSize(3);
119
120 $loaded_plugin = $this->plugins->getModules('plugin-test2');
121 $loaded_plugin['date'] = $this->plugin2['date'];
122
123 $this->variable($loaded_plugin)
124 ->isIdenticalTo($this->plugin2);
125 }
126
127 /**
128 * Test module existence
129 *
130 * @return void
131 */
132 public function testModuleExists()
133 {
134 $this->boolean($this->plugins->moduleExists('plugin-test2'))
135 ->isTrue();
136 $this->boolean($this->plugins->moduleExists('plugin-disabled'))
137 ->isFalse();
138 }
139
140 /**
141 * Test disabled plugin
142 *
143 * @return void
144 */
145 public function testDisabledModules()
146 {
147 $this->array($this->plugins->getDisabledModules())
148 ->hasKeys(
149 array(
150 'plugin-disabled',
151 'plugin-unversionned',
152 'plugin-oldversion'
153 )
154 );
155 }
156
157 /**
158 * Test module root
159 *
160 * @return void
161 */
162 public function testModuleRoot()
163 {
164 $this->variable($this->plugins->moduleRoot('plugin-test2'))
165 ->isIdenticalTo($this->plugin2['root']);
166 }
167
168 /**
169 * Test templates path
170 *
171 * @return void
172 */
173 /*public function testGetTemplatesPath()
174 {
175 //FIXME:
176 // - at the moment, there is no config for preferences, so default theme is empty
177 // - remove global $preferences to have this one working as expected...
178 $this->variable($this->plugins->getTemplatesPath('plugin-test2'))
179 ->isIdenticalTo($this->plugin2['root'] . '/templates/');
180 }*/
181
182 /**
183 * Test reset modules list
184 *
185 * @return void
186 */
187 public function testResetModulesList()
188 {
189 $this->plugins->resetModulesList();
190
191 $this->array($this->plugins->getModules())
192 ->isempty();
193 }
194
195 /**
196 * Test plugin (des)activation
197 *
198 * @return void
199 */
200 public function testModuleActivation()
201 {
202 $plugins = $this->getPlugins();
203 $this->array($plugins->getModules())
204 ->hasSize(3)
205 ->hasKey('plugin-test2');
206 $plugins->deactivateModule('plugin-test2');
207
208 $plugins = $this->getPlugins();
209 $this->array($plugins->getModules())
210 ->hasSize(2)
211 ->notHasKey('plugin-test2');
212 $plugins->activateModule('plugin-test2');
213
214 $plugins = $this->getPlugins();
215 $this->array($plugins->getModules())
216 ->hasSize(3)
217 ->hasKey('plugin-test2');
218
219 $this->exception(
220 function () {
221 $plugins = $this->getPlugins();
222 $plugins->deactivateModule('nonexistant');
223 }
224 )->hasMessage(_T('No such module.'));
225
226 $this->exception(
227 function () {
228 $plugins = $this->getPlugins();
229 $plugins->activateModule('nonexistant');
230 }
231 )->hasMessage(_T('No such module.'));
232 }
233
234 /**
235 * Test if plugin needs database
236 *
237 * @return void
238 */
239 public function testNeedDatabse()
240 {
241 $this->boolean($this->plugins->needsDatabase('plugin-db'))
242 ->isTrue();
243 $this->boolean($this->plugins->needsDatabase('plugin-test2'))
244 ->isFalse();
245
246 $this->exception(
247 function () {
248 $plugins = $this->getPlugins();
249 $plugins->needsDatabase('nonexistant');
250 }
251 )->hasMessage(_T('Module does not exists!'));
252 }
253 }