4 * Copyright © 2003-2024 The Galette Team
6 * This file is part of Galette (https://galette.eu).
8 * Galette is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * Galette is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
22 namespace Galette\Core\test\units
;
25 use PHPUnit\Framework\TestCase
;
30 * @author Johan Cwiklinski <johan@x-tnd.be>
32 class Install
extends TestCase
34 private \Galette\Core\Db
$zdb;
35 private array $flash_data;
36 private \Slim\Flash\Messages
$flash;
37 private \DI\Container
$container;
44 public function setUp(): void
46 setlocale(LC_ALL
, 'en_US');
49 $this->flash_data
= &$flash_data;
50 $this->flash
= new \Slim\Flash\
Messages($flash_data);
52 $gapp = new \Galette\Core\
SlimApp();
53 $app = $gapp->getApp();
54 $plugins = new \Galette\Core\
Plugins();
55 require GALETTE_BASE_PATH
. '/includes/dependencies.php';
56 $container = $app->getContainer();
57 $_SERVER['HTTP_HOST'] = '';
59 $container->set('flash', $this->flash
);
60 $container->set(Slim\Flash\Messages
::class, $this->flash
);
62 $this->container
= $container;
64 $this->zdb
= $container->get('zdb');
72 public function tearDown(): void
74 if (TYPE_DB
=== 'mysql') {
75 $this->assertSame([], $this->zdb
->getWarnings());
80 * Test if current database version is supported
84 public function testDbSupport()
86 $this->assertTrue($this->zdb
->isEngineSUpported());
94 public function testUpdates()
96 $install = new \Galette\Core\
Install();
97 $update_scripts = \Galette\Core\Install
::getUpdateScripts(
98 GALETTE_BASE_PATH
. '/install',
102 $this->assertGreaterThan(5, count($update_scripts));
104 $install->setMode(\Galette\Core\Install
::UPDATE
);
106 $install->setDbType($this->zdb
->type_db
, $errors);
107 $this->assertSame([], $errors);
109 $install->setInstalledVersion('0.60');
110 $install->setTablesPrefix(PREFIX_DB
);
111 $exec = $install->executeScripts($this->zdb
, GALETTE_BASE_PATH
. '/install');
113 $report = $install->getInitializationReport();
114 foreach ($report as $entry) {
117 ($entry['debug'] ??
'') . "\n" . ($entry['query'] ??
'')
121 $this->assertTrue($exec);
122 $this->assertSame(GALETTE_DB_VERSION
, $this->zdb
->getDbVersion());