]> git.agnieray.net Git - galette.git/blob - tests/Galette/Core/tests/units/Install.php
2c26198606a00cc42a4c403951db61202757e350
[galette.git] / tests / Galette / Core / tests / units / Install.php
1 <?php
2
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5 /**
6 * Install tests
7 *
8 * PHP version 5
9 *
10 * Copyright © 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 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 2014-01-03
36 */
37
38 namespace Galette\Core\test\units;
39
40 use \atoum;
41
42 /**
43 * Install tests class
44 *
45 * @category Core
46 * @name Db
47 * @package GaletteTests
48 * @author Johan Cwiklinski <johan@x-tnd.be>
49 * @copyright 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 2014-01-03
53 */
54 class Install extends atoum
55 {
56 private $install;
57
58 /**
59 * Set up tests
60 *
61 * @param stgring $testMethod Method tested
62 *
63 * @return void
64 */
65 public function beforeTestMethod($testMethod)
66 {
67 setlocale(LC_ALL, 'en_US');
68 $this->install = new \Galette\Core\Install();
69 }
70
71 /**
72 * Test constructor
73 *
74 * @return void
75 */
76 public function testConstructor()
77 {
78 $install = new \Galette\Core\Install();
79
80 $step = $install->isCheckStep();
81 $this->boolean($step)->isTrue();
82
83 $mode = $install->getMode();
84 $this->variable($mode)->isNull();
85
86 $is_install = $install->isInstall();
87 $this->boolean($is_install)->isFalse();
88
89 $is_upgrade = $install->isUpgrade();
90 $this->boolean($is_upgrade)->isFalse();
91
92 $connected = $install->isDbConnected();
93 $this->boolean($connected)->isFalse();
94
95 $title = $install->getStepTitle();
96 $this->string($title)->isIdenticalTo('Checks');
97 }
98
99 /**
100 * Tests update scripts list
101 *
102 * @return void
103 */
104 public function testGetUpgradeScripts()
105 {
106 $update_scripts = \Galette\Core\Install::getUpdateScripts(
107 GALETTE_BASE_PATH . '/install',
108 'pgsql',
109 '0.6'
110 );
111
112 $knowns = array(
113 '0.60' => 'upgrade-to-0.60-pgsql.sql',
114 '0.61' => 'upgrade-to-0.61-pgsql.sql',
115 '0.62' => 'upgrade-to-0.62-pgsql.sql',
116 '0.63' => 'upgrade-to-0.63-pgsql.sql',
117 '0.70' => 'upgrade-to-0.70.php',
118 '0.71' => 'upgrade-to-0.71-pgsql.sql',
119 '0.74' => 'upgrade-to-0.74-pgsql.sql',
120 '0.75' => 'upgrade-to-0.75-pgsql.sql',
121 '0.76' => 'upgrade-to-0.76-pgsql.sql',
122 '0.8' => 'upgrade-to-0.8.php',
123 '0.81' => 'upgrade-to-0.81-pgsql.sql',
124 '0.82' => 'upgrade-to-0.82-pgsql.sql',
125 '0.91' => 'upgrade-to-0.91-pgsql.sql',
126 '0.92' => 'upgrade-to-0.92-pgsql.sql',
127 '0.93' => 'upgrade-to-0.93-pgsql.sql',
128 '0.931' => 'upgrade-to-0.931-pgsql.sql',
129 '0.94' => 'upgrade-to-0.94-pgsql.sql'
130 );
131
132 $this->array($update_scripts)
133 ->hasSize(count($knowns))
134 ->isIdenticalTo($knowns);
135
136 $update_scripts = \Galette\Core\Install::getUpdateScripts(
137 GALETTE_BASE_PATH . '/install',
138 'pgsql',
139 '0.7'
140 );
141
142 //if we're from 0.7.0, there are only 6 update scripts left
143 $this->array($update_scripts)
144 ->hasSize(count($knowns) - 4);
145
146 $update_scripts = \Galette\Core\Install::getUpdateScripts(
147 GALETTE_BASE_PATH . '/install'
148 );
149
150 //without specifying database nor version, we got 10 update scripts total
151 $this->array(array_values($update_scripts))
152 ->hasSize(count($knowns))
153 ->isEqualTo(array_keys($knowns));
154
155 $this->install->setMode(\Galette\Core\Install::UPDATE);
156 $errors = array();
157 $this->install->setDbType(\Galette\Core\Db::PGSQL, $errors);
158 $this->install->setInstalledVersion('0.6');
159 $update_scripts = $this->install->getScripts(
160 GALETTE_BASE_PATH . '/install'
161 );
162
163 $this->array($update_scripts)
164 ->hasSize(count($knowns))
165 ->isIdenticalTo($knowns);
166
167 $this->install->setMode(\Galette\Core\Install::INSTALL);
168 $update_scripts = $this->install->getScripts(
169 GALETTE_BASE_PATH . '/install'
170 );
171
172 $this->array($update_scripts)
173 ->hasSize(1)
174 ->hasKey('current')
175 ->strictlyContains(\Galette\Core\Db::PGSQL . '.sql');
176 }
177
178 /**
179 * Test type step
180 *
181 * @return void
182 */
183 public function testTypeStep()
184 {
185 $this->install->atTypeStep();
186
187 $step = $this->install->isTypeStep();
188 $this->boolean($step)->isTrue();
189
190 $title = $this->install->getStepTitle();
191 $this->string($title)->isIdenticalTo('Installation mode');
192 }
193
194 /**
195 * Test DB installation step
196 *
197 * @return void
198 */
199 public function testInstallDbStep()
200 {
201 $this->install->setMode(\Galette\Core\Install::INSTALL);
202 $this->install->atDbStep();
203
204 $is_install = $this->install->isInstall();
205 $is_upgrade = $this->install->isUpgrade();
206
207 $this->boolean($is_install)->isTrue();
208 $this->boolean($is_upgrade)->isFalse();
209
210 $title = $this->install->getStepTitle();
211 $this->string($title)->isIdenticalTo('Database');
212
213 $this->install->atPreviousStep();
214 $step = $this->install->isTypeStep();
215 $this->boolean($step)->isTrue();
216 }
217
218 /**
219 * Test DB upgrade step
220 *
221 * @return void
222 */
223 public function testUpgradeDbStep()
224 {
225 $this->install->setMode(\Galette\Core\Install::UPDATE);
226 $this->install->atDbStep();
227
228 $is_install = $this->install->isInstall();
229 $is_upgrade = $this->install->isUpgrade();
230
231 $this->boolean($is_install)->isFalse();
232 $this->boolean($is_upgrade)->isTrue();
233
234 $title = $this->install->getStepTitle();
235 $this->string($title)->isIdenticalTo('Database');
236
237 $this->install->atPreviousStep();
238 $step = $this->install->isTypeStep();
239
240 $this->boolean($step)->isTrue();
241 }
242
243 /**
244 * Test unknown mode
245 *
246 * @return void
247 */
248 public function testUnknownMode()
249 {
250 $this->exception(
251 function () {
252 $this->install->setMode('nonsense');
253 }
254 )->hasMessage('Unknown mode "nonsense"');
255 }
256
257 /**
258 * Test Db types
259 *
260 * @return void
261 */
262 public function testSetDbType()
263 {
264 $types = array(
265 \Galette\Core\Db::MYSQL,
266 \Galette\Core\Db::PGSQL
267 );
268
269 foreach ($types as $t) {
270 $errors = array();
271
272 $this->install->setDbType(\Galette\Core\Db::MYSQL, $errors);
273 $type = $this->install->getDbType();
274
275 $this->variable($type)->isIdenticalTo(\Galette\Core\Db::MYSQL);
276 $this->array($errors)->hasSize(0);
277 }
278
279 $errors = array();
280 $this->install->setDbType('nonsense', $errors);
281
282 $this->array($errors)->hasSize(1)
283 ->strictlyContains('Database type unknown');
284
285 $post_check = $this->install->postCheckDb();
286 $this->boolean($post_check)->isFalse();
287 }
288
289 /**
290 * Test Db chack step (same for install and upgrade)
291 *
292 * @return void
293 */
294 public function testDbCheckStep()
295 {
296 $errors = array();
297 $this->install->setDbType(TYPE_DB, $errors);
298 $this->install->setDsn(
299 HOST_DB,
300 PORT_DB,
301 NAME_DB,
302 USER_DB,
303 PWD_DB
304 );
305 $this->install->setTablesPrefix(
306 PREFIX_DB
307 );
308 $this->install->atDbCheckStep();
309
310 $step = $this->install->isDbCheckStep();
311 $this->boolean($step)->isTrue();
312
313 $title = $this->install->getStepTitle();
314 $this->string($title)->isIdenticalTo('Database access and permissions');
315
316 $connected = $this->install->testDbConnexion();
317 $this->boolean($connected)->isTrue();
318
319 $host = $this->install->getDbHost();
320 $this->string($host)->isIdenticalTo(HOST_DB);
321
322 $port = $this->install->getDbPort();
323 $this->variable($port)->isIdenticalTo(PORT_DB);
324
325 $name = $this->install->getDbName();
326 $this->variable($name)->isIdenticalTo(NAME_DB);
327
328 $user = $this->install->getDbUser();
329 $this->variable($user)->isIdenticalTo(USER_DB);
330
331 $prefix = $this->install->getTablesPrefix();
332 $this->variable($prefix)->isIdenticalTo(PREFIX_DB);
333
334 $pass = $this->install->getDbPass();
335 $this->variable($pass)->isIdenticalTo(PWD_DB);
336
337 $post_check = $this->install->postCheckDb();
338 $this->boolean($post_check)->isFalse();
339
340 $this->install->atPreviousStep();
341 $step = $this->install->isDbStep();
342 $this->boolean($step)->isTrue();
343 }
344
345 /**
346 * Test db install step
347 *
348 * @return void
349 */
350 public function testDbInstallStep()
351 {
352 $this->install->setDbType(TYPE_DB, $errors);
353 $this->install->setDsn(
354 HOST_DB,
355 PORT_DB,
356 NAME_DB,
357 USER_DB,
358 PWD_DB
359 );
360 $this->install->setTablesPrefix(
361 PREFIX_DB
362 );
363
364 $this->install->atDbInstallStep();
365
366 $step = $this->install->isDbinstallStep();
367 $this->boolean($step)->isTrue();
368
369 $title = $this->install->getStepTitle();
370 $this->string($title)->isIdenticalTo('Tables Creation');
371
372 $post_check = $this->install->postCheckDb();
373 $this->boolean($post_check)->isTrue();
374
375 $this->install->atPreviousStep();
376 $step = $this->install->isDbCheckStep();
377 $this->boolean($step)->isTrue();
378 }
379
380 /**
381 * Test admin step
382 *
383 * @return void
384 */
385 public function testAdminStep()
386 {
387 $this->install->atAdminStep();
388
389 $step = $this->install->isAdminStep();
390 $this->boolean($step)->isTrue();
391
392 $title = $this->install->getStepTitle();
393 $this->string($title)->isIdenticalTo('Admin parameters');
394
395 $post_check = $this->install->postCheckDb();
396 $this->boolean($post_check)->isTrue();
397
398 $this->install->atPreviousStep();
399 //db install cannot be run twice, step is still Admin
400 $step = $this->install->isAdminStep();
401 $this->boolean($step)->isTrue();
402 }
403
404 /**
405 * Test galette initialization
406 *
407 * @return void
408 */
409 public function testInitStep()
410 {
411 $this->install->atGaletteInitStep();
412
413 $step = $this->install->isGaletteInitStep();
414 $this->boolean($step)->isTrue();
415
416 $title = $this->install->getStepTitle();
417 $this->string($title)->isIdenticalTo('Galette initialization');
418
419 $post_check = $this->install->postCheckDb();
420 $this->boolean($post_check)->isTrue();
421 }
422 }