]> git.agnieray.net Git - galette.git/blob - tests/Galette/Core/tests/units/Plugins.php
Check MySQL warning in tests suite
[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 $method Method tested
93 *
94 * @return void
95 */
96 public function beforeTestMethod($method)
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 * Tear down tests
109 *
110 * @param string $method Calling method
111 *
112 * @return void
113 */
114 public function afterTestMethod($method)
115 {
116 if (TYPE_DB === 'mysql') {
117 $this->array($this->zdb->getWarnings())->isIdenticalTo([]);
118 }
119 }
120
121 /**
122 * Tests plugins load
123 *
124 * @return void
125 */
126 public function testLoadModules()
127 {
128 $plugins = $this->getPlugins();
129
130 $this->array($this->plugins->getModules())
131 ->hasSize(3);
132
133 $loaded_plugin = $this->plugins->getModules('plugin-test2');
134 $loaded_plugin['date'] = $this->plugin2['date'];
135
136 $this->variable($loaded_plugin)
137 ->isIdenticalTo($this->plugin2);
138 }
139
140 /**
141 * Test module existence
142 *
143 * @return void
144 */
145 public function testModuleExists()
146 {
147 $this->boolean($this->plugins->moduleExists('plugin-test2'))
148 ->isTrue();
149 $this->boolean($this->plugins->moduleExists('plugin-disabled'))
150 ->isFalse();
151 }
152
153 /**
154 * Test disabled plugin
155 *
156 * @return void
157 */
158 public function testDisabledModules()
159 {
160 $this->array($this->plugins->getDisabledModules())
161 ->hasKeys(
162 array(
163 'plugin-disabled',
164 'plugin-unversionned',
165 'plugin-oldversion'
166 )
167 );
168 }
169
170 /**
171 * Test module root
172 *
173 * @return void
174 */
175 public function testModuleRoot()
176 {
177 $this->variable($this->plugins->moduleRoot('plugin-test2'))
178 ->isIdenticalTo($this->plugin2['root']);
179 }
180
181 /**
182 * Test templates path
183 *
184 * @return void
185 */
186 /*public function testGetTemplatesPath()
187 {
188 //FIXME:
189 // - at the moment, there is no config for preferences, so default theme is empty
190 // - remove global $preferences to have this one working as expected...
191 $this->variable($this->plugins->getTemplatesPath('plugin-test2'))
192 ->isIdenticalTo($this->plugin2['root'] . '/templates/');
193 }*/
194
195 /**
196 * Test reset modules list
197 *
198 * @return void
199 */
200 public function testResetModulesList()
201 {
202 $this->plugins->resetModulesList();
203
204 $this->array($this->plugins->getModules())
205 ->isempty();
206 }
207
208 /**
209 * Test plugin (des)activation
210 *
211 * @return void
212 */
213 public function testModuleActivation()
214 {
215 $plugins = $this->getPlugins();
216 $this->array($plugins->getModules())
217 ->hasSize(3)
218 ->hasKey('plugin-test2');
219 $plugins->deactivateModule('plugin-test2');
220
221 $plugins = $this->getPlugins();
222 $this->array($plugins->getModules())
223 ->hasSize(2)
224 ->notHasKey('plugin-test2');
225 $plugins->activateModule('plugin-test2');
226
227 $plugins = $this->getPlugins();
228 $this->array($plugins->getModules())
229 ->hasSize(3)
230 ->hasKey('plugin-test2');
231
232 $this->exception(
233 function () {
234 $plugins = $this->getPlugins();
235 $plugins->deactivateModule('nonexistant');
236 }
237 )->hasMessage(_T('No such module.'));
238
239 $this->exception(
240 function () {
241 $plugins = $this->getPlugins();
242 $plugins->activateModule('nonexistant');
243 }
244 )->hasMessage(_T('No such module.'));
245 }
246
247 /**
248 * Test if plugin needs database
249 *
250 * @return void
251 */
252 public function testNeedDatabse()
253 {
254 $this->boolean($this->plugins->needsDatabase('plugin-db'))
255 ->isTrue();
256 $this->boolean($this->plugins->needsDatabase('plugin-test2'))
257 ->isFalse();
258
259 $this->exception(
260 function () {
261 $plugins = $this->getPlugins();
262 $plugins->needsDatabase('nonexistant');
263 }
264 )->hasMessage(_T('Module does not exists!'));
265 }
266 }