]> git.agnieray.net Git - galette.git/blob - tests/GaletteUpdate/Core/tests/units/Install.php
7528e0e2e6112ae74827220ba9ce18c15011dac4
[galette.git] / tests / GaletteUpdate / Core / tests / units / Install.php
1 <?php
2
3 /**
4 * Copyright © 2003-2024 The Galette Team
5 *
6 * This file is part of Galette (https://galette.eu).
7 *
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.
12 *
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.
17 *
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/>.
20 */
21
22 namespace Galette\Core\test\units;
23
24 use atoum;
25 use PHPUnit\Framework\TestCase;
26
27 /**
28 * Update tests
29 *
30 * @author Johan Cwiklinski <johan@x-tnd.be>
31 */
32 class Install extends TestCase
33 {
34 private \Galette\Core\Db $zdb;
35 private array $flash_data;
36 private \Slim\Flash\Messages $flash;
37 private \DI\Container $container;
38
39 /**
40 * Set up tests
41 *
42 * @return void
43 */
44 public function setUp(): void
45 {
46 setlocale(LC_ALL, 'en_US');
47
48 $flash_data = [];
49 $this->flash_data = &$flash_data;
50 $this->flash = new \Slim\Flash\Messages($flash_data);
51
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'] = '';
58
59 $container->set('flash', $this->flash);
60 $container->set(Slim\Flash\Messages::class, $this->flash);
61
62 $this->container = $container;
63
64 $this->zdb = $container->get('zdb');
65 }
66
67 /**
68 * Tear down tests
69 *
70 * @return void
71 */
72 public function tearDown(): void
73 {
74 if (TYPE_DB === 'mysql') {
75 $this->assertSame([], $this->zdb->getWarnings());
76 }
77 }
78
79 /**
80 * Test if current database version is supported
81 *
82 * @return void
83 */
84 public function testDbSupport()
85 {
86 $this->assertTrue($this->zdb->isEngineSUpported());
87 }
88
89 /**
90 * Test updates
91 *
92 * @return void
93 */
94 public function testUpdates()
95 {
96 $install = new \Galette\Core\Install();
97 $update_scripts = \Galette\Core\Install::getUpdateScripts(
98 GALETTE_BASE_PATH . '/install',
99 $this->zdb->type_db,
100 '0.6'
101 );
102 $this->assertGreaterThan(5, count($update_scripts));
103
104 $install->setMode(\Galette\Core\Install::UPDATE);
105 $errors = [];
106 $install->setDbType($this->zdb->type_db, $errors);
107 $this->assertSame([], $errors);
108
109 $install->setInstalledVersion('0.60');
110 $install->setTablesPrefix(PREFIX_DB);
111 $exec = $install->executeScripts($this->zdb, GALETTE_BASE_PATH . '/install');
112
113 $report = $install->getInitializationReport();
114 foreach ($report as $entry) {
115 $this->assertTrue(
116 $entry['res'],
117 ($entry['debug'] ?? '') . "\n" . ($entry['query'] ?? '')
118 );
119 }
120
121 $this->assertTrue($exec);
122 $this->assertSame(GALETTE_DB_VERSION, $this->zdb->getDbVersion());
123 }
124 }