]> git.agnieray.net Git - galette.git/commitdiff
Add test on update process
authorJohan Cwiklinski <johan@x-tnd.be>
Wed, 5 May 2021 14:19:10 +0000 (16:19 +0200)
committerJohan Cwiklinski <johan@x-tnd.be>
Sat, 8 May 2021 09:28:19 +0000 (11:28 +0200)
Based on the original 0.60 installation script with a few modifications
in order to get it working on recent servers:
- added "IF EXISTS" on DROPs
- removed accents (Incorrect string value: '\xE9siden...')
- renamed TYPE= to ENGINE=

More accurate comments
Change scripts path for tests

.github/workflows/ci-linux.yml
galette/lib/Galette/Core/Install.php
tests/Galette/Core/tests/units/Install.php
tests/GaletteUpdate/Core/tests/units/Install.php [new file with mode: 0644]
tests/mysql_06.sql [new file with mode: 0644]
tests/pgsql_06.sql [new file with mode: 0644]

index 51ed1a59865ac148ffdfaf48d77b82a63c6c7951..a053a667f3681991bf419899f502cbecb35814fb 100644 (file)
@@ -108,6 +108,24 @@ jobs:
           galette/vendor/bin/composer-require-checker check --config-file=.composer-require-checker.config.json galette/composer.json
         if: matrix.php-versions == '7.4'
 
+      - name: Init for PostgreSQL (update)
+        env:
+          POSTGRES_HOST: localhost
+          POSTGRES_PORT: 5432
+        run: |
+          PGPASSWORD=g@l3tte psql -d galette_tests -a -f tests/pgsql_06.sql -U galette_tests -h localhost
+        if: startsWith(matrix.db-image, 'postgres')
+
+      - name: Init for MariaDB (update)
+        run: |
+          mysql -e 'create database IF NOT EXISTS galette_tests;' -u galette_tests --password=g@l3tte -h 127.0.0.1 -P 3306
+          mysql -e 'use galette_tests; source tests/mysql_06.sql;' -u galette_tests --password=g@l3tte -h 127.0.0.1 -P 3306
+        if: startsWith(matrix.db-image, 'mysql') || startsWith(matrix.db-image, 'mariadb')
+
+      - name: Update database tests
+        run: galette/vendor/bin/atoum -mcn 1 -bf tests/TestsBootstrap.php --no-cc -d tests/GaletteUpdate/
+        if: matrix.coverage != 'xdebug'
+
       - name: Init for PostgreSQL
         env:
           POSTGRES_HOST: localhost
index 0a0bf4f6c5f3b26d859534502050f223c58e33f2..da143c87b898f4208a642990e3115dbb64ae0ccb 100644 (file)
@@ -621,17 +621,18 @@ class Install
     /**
      * Execute SQL scripts
      *
-     * @param Galette\Core\Db $zdb Database instance
+     * @param Galette\Core\Db $zdb   Database instance
+     * @param string          $spath Path to scripts
      *
      * @return boolean
      */
-    public function executeScripts($zdb)
+    public function executeScripts($zdb, $spath = null)
     {
         $queries_results = array();
         $fatal_error = false;
-        $update_scripts = $this->getScripts();
+        $update_scripts = $this->getScripts($spath);
         $this->_report = array();
-        $scripts_path = GALETTE_ROOT . '/install/scripts/';
+        $scripts_path = ($spath ?? GALETTE_ROOT . '/install') . '/scripts/';
 
         foreach ($update_scripts as $key => $val) {
             $sql_query = '';
index c87a52c49fe0fdcb9dc4b0b4ea51c308654b25e6..261e95dcc378275a7a926ec1acd27f15259bb17e 100644 (file)
@@ -139,7 +139,7 @@ class Install extends atoum
             '0.7'
         );
 
-        //if we're from 0.7.0, there are only 6 update scripts left
+        //if we're from 0.7.0, there are 4 less update scripts
         $this->array($update_scripts)
             ->hasSize(count($knowns) - 4);
 
@@ -147,7 +147,7 @@ class Install extends atoum
             GALETTE_BASE_PATH . '/install'
         );
 
-        //without specifying database nor version, we got 10 update scripts total
+        //without specifying database nor version, we got all update scripts
         $all_knowns = ['0.60' => 'upgrade-to-0.60-pgsql.sql'] + $knowns;
         $this->array(array_values($update_scripts))
             ->hasSize(count($all_knowns))
@@ -165,6 +165,7 @@ class Install extends atoum
             ->hasSize(count($knowns))
             ->isIdenticalTo($knowns);
 
+        //for installation, only one script is present :)
         $this->install->setMode(\Galette\Core\Install::INSTALL);
         $update_scripts = $this->install->getScripts(
             GALETTE_BASE_PATH . '/install'
diff --git a/tests/GaletteUpdate/Core/tests/units/Install.php b/tests/GaletteUpdate/Core/tests/units/Install.php
new file mode 100644 (file)
index 0000000..b07c7e1
--- /dev/null
@@ -0,0 +1,130 @@
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Update tests
+ *
+ * PHP version 5
+ *
+ * Copyright © 2021 The Galette Team
+ *
+ * This file is part of Galette (http://galette.tuxfamily.org).
+ *
+ * Galette is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Galette is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Galette. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category  Core
+ * @package   GaletteTests
+ *
+ * @author    Johan Cwiklinski <johan@x-tnd.be>
+ * @copyright 2021 The Galette Team
+ * @license   http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
+ * @version   SVN: $Id$
+ * @link      http://galette.tuxfamily.org
+ * @since     2021-05-06
+ */
+
+namespace Galette\Core\test\units;
+
+use atoum;
+
+/**
+ * Update tests
+ *
+ * @category  Core
+ * @name      Install
+ * @package   GaletteTests
+ * @author    Johan Cwiklinski <johan@x-tnd.be>
+ * @copyright 2021 The Galette Team
+ * @license   http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
+ * @link      http://galette.tuxfamily.org
+ * @since     2021-05-06
+ */
+class Install extends atoum
+{
+    private $install;
+    private $zdb;
+    private $flash_data;
+    private $flash;
+    private $mocked_router;
+    private $container;
+
+    /**
+     * Set up tests
+     *
+     * @param stgring $testMethod Method tested
+     *
+     * @return void
+     */
+    public function beforeTestMethod($testMethod)
+    {
+        setlocale(LC_ALL, 'en_US');
+
+        $this->mocked_router = new \mock\Slim\Router();
+        $this->calling($this->mocked_router)->pathFor = function ($name, $params) {
+            return $name;
+        };
+        $flash_data = [];
+        $this->flash_data = &$flash_data;
+        $this->flash = new \Slim\Flash\Messages($flash_data);
+
+        $app =  new \Galette\Core\SlimApp();
+        $plugins = new \Galette\Core\Plugins();
+        require GALETTE_BASE_PATH . '/includes/dependencies.php';
+        $container = $app->getContainer();
+        $_SERVER['HTTP_HOST'] = '';
+
+        $container->set('flash', $this->flash);
+        $container->set(Slim\Flash\Messages::class, $this->flash);
+        $container->set('router', $this->mocked_router);
+        $container->set(Slim\Router::class, $this->mocked_router);
+
+        $this->container = $container;
+
+        $this->zdb = $container->get('zdb');
+    }
+
+    /**
+     * Test updates
+     *
+     * @return void
+     */
+    public function testUpdates()
+    {
+        $install = new \Galette\Core\Install();
+        $update_scripts = \Galette\Core\Install::getUpdateScripts(
+            GALETTE_BASE_PATH . '/install',
+            $this->zdb->type_db,
+            '0.6'
+        );
+        $this->array($update_scripts)->size->isGreaterThan(5);
+
+        $install->setMode(\Galette\Core\Install::UPDATE);
+        $errors = [];
+        $install->setDbType($this->zdb->type_db, $errors);
+        $this->array($errors)->isIdenticalTo([]);
+
+        $install->setInstalledVersion('0.60');
+        $install->setTablesPrefix(PREFIX_DB);
+        $exec = $install->executeScripts($this->zdb, GALETTE_BASE_PATH . '/install');
+
+        $report = $install->getInitializationReport();
+        foreach ($report as $entry) {
+            $this->boolean($entry['res'])->isTrue(($entry['debug'] ?? '') . "\n" . ($entry['query'] ?? ''));
+        }
+
+        $this->boolean($exec)->isTrue();
+        $this->string($this->zdb->getDbVersion())->isIdenticalTo(GALETTE_DB_VERSION);
+    }
+}
diff --git a/tests/mysql_06.sql b/tests/mysql_06.sql
new file mode 100644 (file)
index 0000000..ac91093
--- /dev/null
@@ -0,0 +1,117 @@
+DROP TABLE IF EXISTS adherents;
+CREATE TABLE adherents (
+  id_adh int(10) unsigned NOT NULL auto_increment,
+  id_statut int(10) unsigned NOT NULL default '4',
+  nom_adh varchar(20) NOT NULL default '',
+  prenom_adh varchar(20) default NULL,
+  pseudo_adh varchar(20) default NULL,
+  titre_adh tinyint(3) unsigned NOT NULL default '0',
+  ddn_adh date default NULL,
+  adresse_adh varchar(150) NOT NULL default '',
+  adresse2_adh varchar(150) default NULL,
+  cp_adh varchar(10) NOT NULL default '',
+  ville_adh varchar(50) NOT NULL default '',
+  pays_adh varchar(50) default NULL,
+  tel_adh varchar(20) default NULL,
+  gsm_adh varchar(20) default NULL,
+  email_adh varchar(150) default NULL,
+  url_adh varchar(200) default NULL,
+  icq_adh varchar(20) default NULL,
+  msn_adh varchar(150) default NULL,
+  jabber_adh varchar(150) default NULL,
+  info_adh text,
+  info_public_adh text,
+  prof_adh varchar(150) default NULL,
+  login_adh varchar(20) NOT NULL default '',
+  mdp_adh varchar(20) NOT NULL default '',
+  date_crea_adh date NOT NULL default '0000-00-00',
+  activite_adh enum('0','1') NOT NULL default '0',
+  bool_admin_adh enum('1') default NULL,
+  bool_exempt_adh enum('1') default NULL,
+  bool_display_info enum('1') default NULL,
+  date_echeance date default NULL,
+  PRIMARY KEY  (id_adh)
+) ENGINE=MyISAM;
+
+DROP TABLE IF EXISTS cotisations;
+CREATE TABLE cotisations (
+  id_cotis int(10) unsigned NOT NULL auto_increment,
+  id_adh int(10) unsigned NOT NULL default '0',
+  id_type_cotis int(10) unsigned NOT NULL default '0',
+  montant_cotis float unsigned default '0',
+  info_cotis text,
+  duree_mois_cotis tinyint(3) unsigned NOT NULL default '12',
+  date_cotis date NOT NULL default '0000-00-00',
+  PRIMARY KEY  (id_cotis)
+) ENGINE=MyISAM;
+
+DROP TABLE IF EXISTS statuts;
+CREATE TABLE statuts (
+  id_statut int(10) unsigned NOT NULL auto_increment,
+  libelle_statut varchar(20) NOT NULL default '',
+  priorite_statut tinyint(4) NOT NULL default '0',
+  PRIMARY KEY  (id_statut)
+) ENGINE=MyISAM;
+
+
+INSERT INTO statuts VALUES (1,'President',0);
+INSERT INTO statuts VALUES (10,'Vice-president',5);
+INSERT INTO statuts VALUES (2,'Tresorier',10);
+INSERT INTO statuts VALUES (4,'Membre actif',30);
+INSERT INTO statuts VALUES (5,'Membre bienfaiteur',40);
+INSERT INTO statuts VALUES (6,'Membre fondateur',50);
+INSERT INTO statuts VALUES (3,'Secretaire',20);
+INSERT INTO statuts VALUES (7,'Ancien',60);
+INSERT INTO statuts VALUES (8,'Personne morale',70);
+INSERT INTO statuts VALUES (9,'Non membre',80);
+
+DROP TABLE IF EXISTS types_cotisation;
+CREATE TABLE types_cotisation (
+  id_type_cotis int(10) unsigned NOT NULL auto_increment,
+  libelle_type_cotis varchar(30) NOT NULL default '',
+  PRIMARY KEY  (id_type_cotis)
+) ENGINE=MyISAM;
+
+
+INSERT INTO types_cotisation VALUES (1,'Cotisation annuelle normale');
+INSERT INTO types_cotisation VALUES (2,'Cotisation annuelle reduite');
+INSERT INTO types_cotisation VALUES (3,'Cotisation entreprise');
+INSERT INTO types_cotisation VALUES (4,'Donation en nature');
+INSERT INTO types_cotisation VALUES (5,'Donation pecuniere');
+INSERT INTO types_cotisation VALUES (6,'Partenariat');
+
+DROP TABLE IF EXISTS preferences;
+CREATE TABLE preferences (
+  pref_nom varchar(40) NOT NULL default '',
+  pref_adresse varchar(150) NOT NULL default '',
+  pref_adresse2 varchar(150) default NULL,
+  pref_cp varchar(10) NOT NULL default '',
+  pref_ville varchar(50) NOT NULL default '',
+  pref_pays varchar(50) default NULL,
+  pref_lang varchar(20) NOT NULL default '',
+  pref_numrows int(10) unsigned NOT NULL default '30',
+  pref_log enum('0','1','2') NOT NULL default '1',
+  pref_email_nom varchar(20) NOT NULL default '',
+  pref_email varchar(150) NOT NULL default '',
+  pref_etiq_marges int(10) unsigned NOT NULL default '0',
+  pref_etiq_hspace int(10) unsigned NOT NULL default '0',
+  pref_etiq_vspace int(10) unsigned NOT NULL default '0',
+  pref_etiq_hsize int(10) unsigned NOT NULL default '0',
+  pref_etiq_vsize int(10) unsigned NOT NULL default '0',
+  pref_etiq_cols int(10) unsigned NOT NULL default '0',
+  pref_etiq_rows int(10) unsigned NOT NULL default '0',
+  pref_etiq_corps int(10) unsigned NOT NULL default '0',
+  pref_admin_login varchar(20) NOT NULL default '',
+  pref_admin_pass varchar(20) NOT NULL default ''
+) ENGINE=MyISAM;
+
+DROP TABLE IF EXISTS logs;
+CREATE TABLE logs (
+  id_log int(10) unsigned NOT NULL auto_increment,
+  date_log datetime NOT NULL,
+  ip_log varchar(30) NOT NULL default '',
+  adh_log varchar(41) NOT NULL default '',
+  text_log text,
+  PRIMARY KEY  (id_log)
+) ENGINE=MyISAM;
+
diff --git a/tests/pgsql_06.sql b/tests/pgsql_06.sql
new file mode 100644 (file)
index 0000000..54eb5a3
--- /dev/null
@@ -0,0 +1,135 @@
+DROP SEQUENCE adherents_id_seq;
+CREATE SEQUENCE adherents_id_seq
+    START 1
+    INCREMENT 1
+    MAXVALUE 2147483647
+    MINVALUE 1
+    CACHE 1;
+
+DROP SEQUENCE cotisations_id_seq;
+CREATE SEQUENCE cotisations_id_seq
+    START 1
+    INCREMENT 1
+    MAXVALUE 2147483647
+    MINVALUE 1
+    CACHE 1;
+
+DROP TABLE adherents;
+CREATE TABLE adherents (
+    id_adh integer DEFAULT nextval('adherents_id_seq'::text) NOT NULL,
+    id_statut integer DEFAULT '4' NOT NULL,
+    nom_adh character varying(20) DEFAULT '' NOT NULL,
+    prenom_adh character varying(20) DEFAULT NULL,
+    pseudo_adh character varying(20) DEFAULT NULL,
+    titre_adh smallint DEFAULT '0' NOT NULL,
+    ddn_adh date,
+    adresse_adh character varying(150) DEFAULT '' NOT NULL,
+    adresse2_adh character varying(150) DEFAULT NULL,
+    cp_adh character varying(10) DEFAULT '' NOT NULL,
+    ville_adh character varying(50) DEFAULT '' NOT NULL,
+    pays_adh character varying(50) DEFAULT NULL,
+    tel_adh character varying(20),
+    gsm_adh character varying(20),
+    email_adh character varying(150),
+    url_adh character varying(200),
+    icq_adh character varying(20),
+    msn_adh character varying(150),
+    jabber_adh character varying(150),
+    info_adh text,
+    info_public_adh text,
+    prof_adh character varying(150),
+    login_adh character varying(20) DEFAULT '' NOT NULL,
+    mdp_adh character varying(20) DEFAULT '' NOT NULL,
+    date_crea_adh date NOT NULL,
+    activite_adh character(1) DEFAULT '0' NOT NULL,
+    bool_admin_adh character(1) DEFAULT NULL,
+    bool_exempt_adh character(1) DEFAULT NULL,
+    bool_display_info character(1) DEFAULT NULL,
+    date_echeance date
+);
+
+DROP TABLE cotisations;
+CREATE TABLE cotisations (
+    id_cotis integer DEFAULT nextval('cotisations_id_seq'::text)  NOT NULL,
+    id_adh integer DEFAULT '0' NOT NULL,
+    id_type_cotis integer DEFAULT '0' NOT NULL,
+    montant_cotis real DEFAULT '0',
+    info_cotis text,
+    duree_mois_cotis smallint DEFAULT '12' NOT NULL,
+    date_cotis date NOT NULL
+);
+
+DROP TABLE statuts;
+CREATE TABLE statuts (
+  id_statut integer NOT NULL,
+  libelle_statut  character varying(20) DEFAULT '' NOT NULL,
+  priorite_statut smallint DEFAULT '0' NOT NULL
+);
+
+INSERT INTO statuts VALUES (1,'Président',0);
+INSERT INTO statuts VALUES (2,'Trésorier',10);
+INSERT INTO statuts VALUES (4,'Membre actif',30);
+INSERT INTO statuts VALUES (5,'Membre bienfaiteur',40);
+INSERT INTO statuts VALUES (6,'Membre fondateur',50);
+INSERT INTO statuts VALUES (3,'Secrétaire',20);
+INSERT INTO statuts VALUES (7,'Ancien',60);
+INSERT INTO statuts VALUES (8,'Personne morale',70);
+INSERT INTO statuts VALUES (9,'Non membre',80);
+INSERT INTO statuts VALUES (10,'Vice-président',5);
+
+DROP TABLE types_cotisation;
+CREATE TABLE types_cotisation (
+  id_type_cotis integer NOT NULL,
+  libelle_type_cotis character varying(30) DEFAULT '' NOT NULL
+);
+
+INSERT INTO types_cotisation VALUES (1,'Cotisation annuelle normale');
+INSERT INTO types_cotisation VALUES (2,'Cotisation annuelle réduite');
+INSERT INTO types_cotisation VALUES (3,'Cotisation entreprise');
+INSERT INTO types_cotisation VALUES (4,'Donation en nature');
+INSERT INTO types_cotisation VALUES (5,'Donation pécunière');
+INSERT INTO types_cotisation VALUES (6,'Partenariat');
+
+DROP TABLE preferences;
+CREATE TABLE preferences (
+  pref_nom character varying(40) DEFAULT '' NOT NULL,
+  pref_adresse character varying(150) DEFAULT '' NOT NULL,
+  pref_adresse2 character varying(150) DEFAULT NULL,
+  pref_cp character varying(10) DEFAULT '' NOT NULL,
+  pref_ville character varying(50) DEFAULT '' NOT NULL,
+  pref_pays character varying(50) DEFAULT NULL,
+  pref_lang character varying(20) DEFAULT '' NOT NULL,
+  pref_numrows integer DEFAULT '30' NOT NULL,
+  pref_log character(1) DEFAULT '1' NOT NULL,
+  pref_email_nom character varying(20) DEFAULT '' NOT NULL,
+  pref_email character varying(150) DEFAULT '' NOT NULL,
+  pref_etiq_marges integer DEFAULT '0' NOT NULL,
+  pref_etiq_hspace integer DEFAULT '0' NOT NULL,
+  pref_etiq_vspace integer DEFAULT '0' NOT NULL,
+  pref_etiq_hsize integer DEFAULT '0' NOT NULL,
+  pref_etiq_vsize integer DEFAULT '0' NOT NULL,
+  pref_etiq_cols integer DEFAULT '0' NOT NULL,
+  pref_etiq_rows integer DEFAULT '0' NOT NULL,
+  pref_etiq_corps integer DEFAULT '0' NOT NULL,
+  pref_admin_login character varying(20) DEFAULT '' NOT NULL,
+  pref_admin_pass character varying(20) DEFAULT '' NOT NULL
+);
+
+DROP SEQUENCE logs_id_seq;
+CREATE SEQUENCE logs_id_seq
+    START 1
+    INCREMENT 1
+    MAXVALUE 2147483647
+    MINVALUE 1
+    CACHE 1;
+
+DROP TABLE logs;
+CREATE TABLE logs (
+  id_log integer DEFAULT nextval('logs_id_seq'::text) NOT NULL,
+  date_log timestamp NOT NULL,
+  ip_log character varying(30) DEFAULT '' NOT NULL,
+  adh_log character varying(41) DEFAULT '' NOT NULL,
+  text_log text
+);
+
+