]> git.agnieray.net Git - galette.git/blob - tests/GaletteUpdate/Core/tests/units/Install.php
Add test on update process
[galette.git] / tests / GaletteUpdate / Core / tests / units / Install.php
1 <?php
2
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5 /**
6 * Update tests
7 *
8 * PHP version 5
9 *
10 * Copyright © 2021 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 2021 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 2021-05-06
36 */
37
38 namespace Galette\Core\test\units;
39
40 use atoum;
41
42 /**
43 * Update tests
44 *
45 * @category Core
46 * @name Install
47 * @package GaletteTests
48 * @author Johan Cwiklinski <johan@x-tnd.be>
49 * @copyright 2021 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 2021-05-06
53 */
54 class Install extends atoum
55 {
56 private $install;
57 private $zdb;
58 private $flash_data;
59 private $flash;
60 private $mocked_router;
61 private $container;
62
63 /**
64 * Set up tests
65 *
66 * @param stgring $testMethod Method tested
67 *
68 * @return void
69 */
70 public function beforeTestMethod($testMethod)
71 {
72 setlocale(LC_ALL, 'en_US');
73
74 $this->mocked_router = new \mock\Slim\Router();
75 $this->calling($this->mocked_router)->pathFor = function ($name, $params) {
76 return $name;
77 };
78 $flash_data = [];
79 $this->flash_data = &$flash_data;
80 $this->flash = new \Slim\Flash\Messages($flash_data);
81
82 $app = new \Galette\Core\SlimApp();
83 $plugins = new \Galette\Core\Plugins();
84 require GALETTE_BASE_PATH . '/includes/dependencies.php';
85 $container = $app->getContainer();
86 $_SERVER['HTTP_HOST'] = '';
87
88 $container->set('flash', $this->flash);
89 $container->set(Slim\Flash\Messages::class, $this->flash);
90 $container->set('router', $this->mocked_router);
91 $container->set(Slim\Router::class, $this->mocked_router);
92
93 $this->container = $container;
94
95 $this->zdb = $container->get('zdb');
96 }
97
98 /**
99 * Test updates
100 *
101 * @return void
102 */
103 public function testUpdates()
104 {
105 $install = new \Galette\Core\Install();
106 $update_scripts = \Galette\Core\Install::getUpdateScripts(
107 GALETTE_BASE_PATH . '/install',
108 $this->zdb->type_db,
109 '0.6'
110 );
111 $this->array($update_scripts)->size->isGreaterThan(5);
112
113 $install->setMode(\Galette\Core\Install::UPDATE);
114 $errors = [];
115 $install->setDbType($this->zdb->type_db, $errors);
116 $this->array($errors)->isIdenticalTo([]);
117
118 $install->setInstalledVersion('0.60');
119 $install->setTablesPrefix(PREFIX_DB);
120 $exec = $install->executeScripts($this->zdb, GALETTE_BASE_PATH . '/install');
121
122 $report = $install->getInitializationReport();
123 foreach ($report as $entry) {
124 $this->boolean($entry['res'])->isTrue(($entry['debug'] ?? '') . "\n" . ($entry['query'] ?? ''));
125 }
126
127 $this->boolean($exec)->isTrue();
128 $this->string($this->zdb->getDbVersion())->isIdenticalTo(GALETTE_DB_VERSION);
129 }
130 }