]> git.agnieray.net Git - galette.git/commitdiff
Create and load fixtures from file rather than rely on faker
authorJohan Cwiklinski <johan@x-tnd.be>
Mon, 15 Jun 2020 08:09:16 +0000 (10:09 +0200)
committerJohan Cwiklinski <johan@x-tnd.be>
Mon, 15 Jun 2020 19:28:02 +0000 (21:28 +0200)
tests/Galette/Repository/tests/units/Members.php
tests/TestsBootstrap.php
tests/fixtures/tests_members.json [new file with mode: 0644]

index b8555127764b8e9297de55c21ef07500512d945b..0cbfcee805789520082730de5f1163a3ae4d4e3f 100644 (file)
@@ -132,8 +132,73 @@ class Members extends atoum
             $this->boolean($res)->isTrue();
         }
 
-        $fakedata = new \Galette\Util\FakeData($this->zdb, $this->i18n);
 
+        $tests_members = json_decode(file_get_contents(GALETTE_TESTS_PATH . '/fixtures/tests_members.json'));
+
+        $mids = [];
+        $first = true;
+        foreach ($tests_members as $test_member) {
+            $test_member = (array)$test_member;
+            $member = new \Galette\Entity\Adherent($this->zdb);
+            $member->setDependencies(
+                $this->preferences,
+                $this->members_fields,
+                $this->history
+            );
+
+            $this->boolean($member->check($test_member, [], []))->isTrue();
+            $this->boolean($member->store())->isTrue();
+            $mids[] = $member->id;
+
+            //set first member displayed publically an active and up to date member
+            if ($member->appearsInMembersList() && !$member->isDueFree() && $first === true) {
+                $first = false;
+                $contrib = new \Galette\Entity\Contribution($this->zdb, $this->login);
+
+
+                $now = new \DateTime();
+                $bdate = clone $now;
+                $bdate->modify('-1 day');
+                $edate = clone $bdate;
+                $edate->modify('+1 year');
+
+                $cdata = [
+                    \Galette\Entity\Adherent::PK    => $member->id,
+                    'type_paiement_cotis'           => \Galette\Entity\PaymentType::CASH,
+                    'montant_cotis'                 => 20,
+                    'date_enreg'                    => $bdate->format('Y-m-d'),
+                    'date_debut_cotis'              => $bdate->format('Y-m-d'),
+                    'date_fin_cotis'                => $edate->format('Y-m-d'),
+                    \Galette\Entity\ContributionsTypes::PK  => \Galette\Entity\ContributionsTypes::DEFAULT_TYPE
+                ];
+                $check = $contrib->check($cdata, [], []);
+                $this->boolean($contrib->check($cdata, [], []))->isTrue();
+                $this->boolean($contrib->store())->isTrue();
+            }
+
+            //only one member is due free. add him a photo.
+            if ($member->isDueFree()) {
+                $file = GALETTE_TEMPIMAGES_PATH . 'fakephoto.jpg';
+                $url = GALETTE_ROOT . '../tests/fake_image.jpg';
+
+                $copied = copy($url, $file);
+                $this->boolean($copied)->isTrue();
+                $_FILES = array(
+                    'photo' => array(
+                        'name'      => 'fakephoto.jpg',
+                        'type'      => 'image/jpeg',
+                        'size'      => filesize($file),
+                        'tmp_name'  => $file,
+                        'error'     => 0
+                    )
+                );
+                $this->integer((int)$member->picture->store($_FILES['photo'], true))->isGreaterThan(0);
+            }
+        }
+
+        $this->mids = $mids;
+
+        /*$fakedata = new \Galette\Util\FakeData($this->zdb, $this->i18n);
         $fakedata
             ->setSeed($this->seed)
             ->setNbMembers(10)
@@ -156,7 +221,7 @@ class Members extends atoum
         $this->array($report['errors'])->hasSize(0);
         $this->array($report['warnings'])->hasSize(0);
 
-        $this->mids = $fakedata->getMembersIds();
+        $this->mids = $fakedata->getMembersIds();*/
     }
 
     /**
@@ -304,7 +369,7 @@ class Members extends atoum
         $members = new \Galette\Repository\Members();
 
         $list = $members->getPublicList(false);
-        $this->array($list)->hasSize(1);
+        $this->array($list)->hasSize(2);
 
         $adh = $list[0];
 
index bd85817c833ed7ec49dceed52edb3daf82ded03e..c46c01e85c349bbc0bba61aca83e2bae1bbc7fdc 100755 (executable)
@@ -33,11 +33,12 @@ if ($db === false || $db !== 'pgsql') {
 define('GALETTE_CONFIG_PATH', __DIR__ . '/config/' . $db . '/');
 define('GALETTE_BASE_PATH', $basepath);
 define('GALETTE_TESTS', true);
+define('GALETTE_TESTS_PATH', __DIR__);
 define('GALETTE_MODE', 'PROD');
-define('GALETTE_PLUGINS_PATH', __DIR__ . '/plugins/');
+define('GALETTE_PLUGINS_PATH', GALETTE_TESTS_PATH . '/plugins/');
 define('GALETTE_TPL_SUBDIR', 'templates/default/');
 define('GALETTE_THEME', 'themes/default/');
-define('GALETTE_DATA_PATH', __DIR__ . '/tests-data/');
+define('GALETTE_DATA_PATH', GALETTE_TESTS_PATH . '/tests-data/');
 if (is_dir(GALETTE_DATA_PATH)) {
     $files = new RecursiveIteratorIterator(
         new RecursiveDirectoryIterator(
diff --git a/tests/fixtures/tests_members.json b/tests/fixtures/tests_members.json
new file mode 100644 (file)
index 0000000..47b10df
--- /dev/null
@@ -0,0 +1,282 @@
+[
+    {
+        "nom_adh": "Bertrand",
+        "prenom_adh": "R\u00e9my",
+        "ville_adh": "Carlierdan",
+        "cp_adh": "26 422",
+        "adresse_adh": "94, boulevard Alphonse Giraud",
+        "email_adh": "alexandre.salmon@sfr.fr",
+        "login_adh": "honore.royer",
+        "mdp_adh": "hLF#r\"t|",
+        "mdp_adh2": "hLF#r\"t|",
+        "bool_admin_adh": false,
+        "bool_exempt_adh": false,
+        "bool_display_info": false,
+        "sexe_adh": 0,
+        "prof_adh": "H\u00f4te de caisse",
+        "titre_adh": null,
+        "ddn_adh": "2016-01-19",
+        "lieu_naissance": "PaulVille",
+        "pseudo_adh": "etienne25",
+        "pays_adh": null,
+        "tel_adh": "+33 2 93 73 14 36",
+        "url_adh": "http:\/\/www.perrin.net\/",
+        "activite_adh": true,
+        "id_statut": 9,
+        "date_crea_adh": "2017-08-07",
+        "pref_lang": "fr_FR",
+        "fingerprint": "FAKER335689"
+    },
+    {
+        "nom_adh": "Bertrand",
+        "prenom_adh": "R\u00e9my",
+        "ville_adh": "Deschampsdan",
+        "cp_adh": "95 474",
+        "adresse_adh": "3, rue de Delaunay",
+        "email_adh": "georges.didier@perrot.fr",
+        "login_adh": "tessier.laure",
+        "mdp_adh": "hLF#r\"t|",
+        "mdp_adh2": "hLF#r\"t|",
+        "bool_admin_adh": false,
+        "bool_exempt_adh": true,
+        "bool_display_info": true,
+        "sexe_adh": 1,
+        "prof_adh": "D\u00e9gustateur",
+        "titre_adh": null,
+        "ddn_adh": "1938-10-13",
+        "lieu_naissance": "Laporte",
+        "pseudo_adh": "margaret.courtois",
+        "pays_adh": "Bangladesh",
+        "tel_adh": "+33 (0)5 41 65 71 46",
+        "url_adh": "http:\/\/coulon.fr\/eos-nesciunt-consectetur-dolores-omnis-provident-explicabo",
+        "activite_adh": true,
+        "id_statut": 1,
+        "date_crea_adh": "2017-08-07",
+        "pref_lang": "de_DE",
+        "fingerprint": "FAKER335689"
+    },
+    {
+        "nom_adh": "Bertrand",
+        "prenom_adh": "R\u00e9my",
+        "ville_adh": "Mahe",
+        "cp_adh": "41657",
+        "adresse_adh": "374, chemin de Muller",
+        "email_adh": "laure.paul@richard.org",
+        "login_adh": "eric.adam",
+        "mdp_adh": "hLF#r\"t|",
+        "mdp_adh2": "hLF#r\"t|",
+        "bool_admin_adh": false,
+        "bool_exempt_adh": false,
+        "bool_display_info": false,
+        "sexe_adh": 1,
+        "prof_adh": "Plaquiste enduiseur",
+        "titre_adh": null,
+        "ddn_adh": "1951-11-09",
+        "lieu_naissance": "Giraud",
+        "pseudo_adh": "nleclerc",
+        "pays_adh": null,
+        "tel_adh": "0895352968",
+        "url_adh": null,
+        "activite_adh": true,
+        "id_statut": 9,
+        "date_crea_adh": "2017-08-07",
+        "pref_lang": "fr_FR",
+        "fingerprint": "FAKER335689"
+    },
+    {
+        "nom_adh": "Bertrand",
+        "prenom_adh": "R\u00e9my",
+        "ville_adh": "Loiseau",
+        "cp_adh": "53 280",
+        "adresse_adh": "76, rue Daniel Collin",
+        "email_adh": "gabriel.laporte@maillot.fr",
+        "login_adh": "elisabeth05",
+        "mdp_adh": "hLF#r\"t|",
+        "mdp_adh2": "hLF#r\"t|",
+        "bool_admin_adh": false,
+        "bool_exempt_adh": false,
+        "bool_display_info": true,
+        "sexe_adh": 1,
+        "prof_adh": "Juriste financier",
+        "titre_adh": null,
+        "ddn_adh": "2015-06-23",
+        "lieu_naissance": "Deschampsdan",
+        "pseudo_adh": "benjamin.germain",
+        "pays_adh": "Autriche",
+        "tel_adh": "+33 5 56 55 02 16",
+        "url_adh": "http:\/\/www.bourgeois.fr\/accusamus-sapiente-est-quia-facilis-quas-exercitationem.html",
+        "activite_adh": true,
+        "id_statut": 5,
+        "date_crea_adh": "2017-08-07",
+        "pref_lang": "en_US",
+        "fingerprint": "FAKER335689"
+    },
+    {
+        "nom_adh": "Bertrand",
+        "prenom_adh": "R\u00e9my",
+        "ville_adh": "Loiseau",
+        "cp_adh": "53 280",
+        "adresse_adh": "rue Collin",
+        "email_adh": "alphonse22@tele2.fr",
+        "login_adh": "josephine.vallet",
+        "mdp_adh": "hLF#r\"t|",
+        "mdp_adh2": "hLF#r\"t|",
+        "bool_admin_adh": false,
+        "bool_exempt_adh": false,
+        "bool_display_info": false,
+        "sexe_adh": 1,
+        "prof_adh": "Brigadier",
+        "titre_adh": null,
+        "ddn_adh": "1924-06-07",
+        "lieu_naissance": "Vasseur",
+        "pseudo_adh": "martine56",
+        "pays_adh": "Autriche",
+        "tel_adh": "+33 5 56 55 02 16",
+        "url_adh": "http:\/\/www.bourgeois.fr\/accusamus-sapiente-est-quia-facilis-quas-exercitationem.html",
+        "activite_adh": true,
+        "id_statut": 5,
+        "date_crea_adh": "2017-08-07",
+        "pref_lang": "en_US",
+        "fingerprint": "FAKER335689"
+    },
+    {
+        "nom_adh": "Bertrand",
+        "prenom_adh": "R\u00e9my",
+        "ville_adh": "Chretienboeuf",
+        "cp_adh": "62 309",
+        "adresse_adh": "1, avenue Marc Bourgeois",
+        "email_adh": "veronique74@deschamps.fr",
+        "login_adh": "benjamin.germain",
+        "mdp_adh": "hLF#r\"t|",
+        "mdp_adh2": "hLF#r\"t|",
+        "bool_admin_adh": false,
+        "bool_exempt_adh": false,
+        "bool_display_info": true,
+        "sexe_adh": 2,
+        "prof_adh": "Menuisier",
+        "titre_adh": null,
+        "ddn_adh": "1925-07-10",
+        "lieu_naissance": "Caron",
+        "pseudo_adh": "laetitia.sanchez",
+        "pays_adh": "Norv\u00e8ge",
+        "tel_adh": "0129447169",
+        "url_adh": null,
+        "activite_adh": true,
+        "id_statut": 9,
+        "date_crea_adh": "2017-08-07",
+        "pref_lang": "en_US",
+        "fingerprint": "FAKER335689"
+    },
+    {
+        "nom_adh": "Bertrand",
+        "prenom_adh": "R\u00e9my",
+        "ville_adh": "Voisin",
+        "cp_adh": "50 542",
+        "adresse_adh": "862, boulevard de Fleury",
+        "email_adh": "perrin.eugene@mahe.org",
+        "login_adh": "antoinette16",
+        "mdp_adh": "hLF#r\"t|",
+        "mdp_adh2": "hLF#r\"t|",
+        "bool_admin_adh": false,
+        "bool_exempt_adh": false,
+        "bool_display_info": false,
+        "sexe_adh": 1,
+        "prof_adh": "B\u00e2tonnier d'art",
+        "titre_adh": null,
+        "ddn_adh": "1997-12-23",
+        "lieu_naissance": "Lefevre",
+        "pseudo_adh": "elodie.bigot",
+        "pays_adh": "Montserrat",
+        "tel_adh": "+33 6 87 22 98 19",
+        "url_adh": null,
+        "activite_adh": false,
+        "id_statut": 4,
+        "date_crea_adh": "2017-08-07",
+        "pref_lang": "uk",
+        "fingerprint": "FAKER335689"
+    },
+    {
+        "nom_adh": "Bertrand",
+        "prenom_adh": "R\u00e9my",
+        "ville_adh": "Gillet",
+        "cp_adh": "92 731",
+        "adresse_adh": "35, chemin Emmanuelle Bazin",
+        "email_adh": "bertrand18@bouygtel.fr",
+        "login_adh": "cdelattre",
+        "mdp_adh": "hLF#r\"t|",
+        "mdp_adh2": "hLF#r\"t|",
+        "bool_admin_adh": false,
+        "bool_exempt_adh": false,
+        "bool_display_info": true,
+        "sexe_adh": 1,
+        "prof_adh": "Ma\u00efeuticien",
+        "titre_adh": null,
+        "ddn_adh": "1953-02-10",
+        "lieu_naissance": "Bourgeoisdan",
+        "pseudo_adh": "victoire64",
+        "pays_adh": null,
+        "tel_adh": "03 43 89 01 97",
+        "url_adh": null,
+        "activite_adh": true,
+        "id_statut": 9,
+        "date_crea_adh": "2017-08-07",
+        "pref_lang": "ca",
+        "fingerprint": "FAKER335689"
+    },
+    {
+        "nom_adh": "Bertrand",
+        "prenom_adh": "R\u00e9my",
+        "ville_adh": "Mace",
+        "cp_adh": "83 183",
+        "adresse_adh": "98, rue de Gillet",
+        "email_adh": "roger14@gmail.com",
+        "login_adh": "elodie.bigot",
+        "mdp_adh": "hLF#r\"t|",
+        "mdp_adh2": "hLF#r\"t|",
+        "bool_admin_adh": false,
+        "bool_exempt_adh": false,
+        "bool_display_info": true,
+        "sexe_adh": 2,
+        "prof_adh": "T\u00e9l\u00e9conseiller",
+        "titre_adh": null,
+        "ddn_adh": "1981-11-03",
+        "lieu_naissance": "Gaudin",
+        "pseudo_adh": "martin29",
+        "pays_adh": "Ouzb\u00e9kistan",
+        "tel_adh": "+33 (0)8 06 28 91 89",
+        "url_adh": "http:\/\/paris.net\/",
+        "activite_adh": true,
+        "id_statut": 9,
+        "date_crea_adh": "2017-08-07",
+        "pref_lang": "uk",
+        "fingerprint": "FAKER335689"
+    },
+    {
+        "nom_adh": "Bertrand",
+        "prenom_adh": "R\u00e9my",
+        "ville_adh": "Coulon",
+        "cp_adh": "70343",
+        "adresse_adh": "483, avenue de Paul",
+        "email_adh": "marc25@pires.org",
+        "login_adh": "qchretien",
+        "mdp_adh": "hLF#r\"t|",
+        "mdp_adh2": "hLF#r\"t|",
+        "bool_admin_adh": false,
+        "bool_exempt_adh": false,
+        "bool_display_info": true,
+        "sexe_adh": 0,
+        "prof_adh": "Mouliste drapeur",
+        "titre_adh": null,
+        "ddn_adh": "1943-02-28",
+        "lieu_naissance": "Prevostnec",
+        "pseudo_adh": "dramos",
+        "pays_adh": "Danemark",
+        "tel_adh": "+33 (0)1 03 04 16 21",
+        "url_adh": "http:\/\/www.lopes.com\/",
+        "activite_adh": true,
+        "id_statut": 6,
+        "date_crea_adh": "2017-08-07",
+        "pref_lang": "ca",
+        "fingerprint": "FAKER335689"
+    }
+]
\ No newline at end of file