]> git.agnieray.net Git - galette.git/blob - tests/GaletteTestCase.php
Fix serialization issue when Replacements feature is used
[galette.git] / tests / GaletteTestCase.php
1 <?php
2
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5 /**
6 * Galette tests
7 *
8 * PHP version 5
9 *
10 * Copyright © 2020-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 2020-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 * @link http://galette.eu
34 * @since 2020-12-27
35 */
36
37 namespace Galette;
38
39 use atoum;
40 use Galette\Core\Db;
41 use Galette\Core\History;
42 use Galette\Core\I18n;
43 use Galette\Core\Login;
44 use Galette\Core\Preferences;
45 use Galette\Entity\Adherent;
46 use Galette\Entity\Contribution;
47
48 /**
49 * Galette tests case main class
50 *
51 * @category Core
52 * @name GaletteTestCase
53 * @package GaletteTests
54 * @author Johan Cwiklinski <johan@x-tnd.be>
55 * @copyright 2020 The Galette Team
56 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
57 * @link http://galette.eu
58 * @since 2020-12-27
59 */
60 abstract class GaletteTestCase extends atoum
61 {
62 /** @var Db */
63 protected $zdb;
64 protected $members_fields;
65 protected $members_fields_cats;
66 /** @var I18n */
67 protected $i18n;
68 /** @var Preferences */
69 protected $preferences;
70 protected $session;
71 /** @var Login */
72 protected $login;
73 /** @var History */
74 protected $history;
75 protected $logger_storage = '';
76
77 /** @var Adherent */
78 protected $adh;
79 /** @var Contribution */
80 protected $contrib;
81 protected $adh_ids = [];
82 protected $contrib_ids = [];
83 /** @var \mock\Slim\Router */
84 protected $mocked_router;
85 /** @var array */
86 protected $flash_data;
87 /** @var \Slim\Flash\Messages */
88 protected $flash;
89 protected $container;
90 protected $request;
91 protected $response;
92 protected $seed;
93 protected $excluded_after_methods = [];
94
95 /**
96 * Set up tests
97 *
98 * @param stgring $method Method tested
99 *
100 * @return void
101 */
102 public function beforeTestMethod($method)
103 {
104 $this->mocked_router = new \mock\Slim\Router();
105 $this->calling($this->mocked_router)->pathFor = function ($name, $params) {
106 return $name;
107 };
108 $flash_data = [];
109 $this->flash_data = &$flash_data;
110 $this->flash = new \Slim\Flash\Messages($flash_data);
111
112 $app = new \Galette\Core\SlimApp();
113 $plugins = new \Galette\Core\Plugins();
114 require GALETTE_BASE_PATH . '/includes/dependencies.php';
115 $container = $app->getContainer();
116 $_SERVER['HTTP_HOST'] = '';
117
118 $container->set('flash', $this->flash);
119 $container->set(Slim\Flash\Messages::class, $this->flash);
120 $container->set('router', $this->mocked_router);
121 $container->set(Slim\Router::class, $this->mocked_router);
122
123 $this->container = $container;
124
125 $this->zdb = $container->get('zdb');
126 $this->i18n = $container->get('i18n');
127 $this->login = $container->get('login');
128 $this->preferences = $container->get('preferences');
129 $this->history = $container->get('history');
130 $this->members_fields = $container->get('members_fields');
131 $this->members_fields_cats = $container->get('members_fields_cats');
132 $this->request = $container->get('request');
133 $this->response = $container->get('response');
134 $this->session = $container->get('session');
135
136 global $zdb, $login, $hist, $i18n, $container, $galette_log_var; // globals :(
137 $zdb = $this->zdb;
138 $login = $this->login;
139 $hist = $this->history;
140 $i18n = $this->i18n;
141 $container = $this->container;
142 $galette_log_var = $this->logger_storage;
143 }
144
145 /**
146 * Tear down tests
147 *
148 * @param string $method Calling method
149 *
150 * @return void
151 */
152 public function afterTestMethod($method)
153 {
154 if (TYPE_DB === 'mysql' && !in_array($method, $this->excluded_after_methods)) {
155 $this->array($this->zdb->getWarnings())->isIdenticalTo([]);
156 }
157 }
158
159 /**
160 * Loads member from a resultset
161 *
162 * @param integer $id Id
163 *
164 * @return void
165 */
166 protected function loadAdherent($id)
167 {
168 $this->adh = new \Galette\Entity\Adherent($this->zdb, (int)$id);
169 $this->adh->setDependencies(
170 $this->preferences,
171 $this->members_fields,
172 $this->history
173 );
174 }
175
176 /**
177 * Get Faker data for one member
178 *
179 * @return array
180 */
181 protected function dataAdherentOne(): array
182 {
183 $bdate = new \DateTime(date('Y') . '-12-26');
184 //member is expected to be 82 years old
185 $years = 82;
186 $now = new \DateTime();
187 if ($now <= $bdate) {
188 ++$years;
189 }
190 $bdate->sub(new \DateInterval('P' . $years . 'Y'));
191 $data = [
192 'nom_adh' => 'Durand',
193 'prenom_adh' => 'René',
194 'ville_adh' => 'Martel',
195 'cp_adh' => '39 069',
196 'adresse_adh' => '66, boulevard De Oliveira',
197 'email_adh' => 'meunier.josephine@ledoux.com',
198 'login_adh' => 'arthur.hamon',
199 'mdp_adh' => 'J^B-()f',
200 'mdp_adh2' => 'J^B-()f',
201 'bool_admin_adh' => false,
202 'bool_exempt_adh' => false,
203 'bool_display_info' => true,
204 'sexe_adh' => 0,
205 'prof_adh' => 'Chef de fabrication',
206 'titre_adh' => null,
207 'ddn_adh' => $bdate->format('Y-m-d'),
208 'lieu_naissance' => 'Gonzalez-sur-Meunier',
209 'pseudo_adh' => 'ubertrand',
210 'pays_adh' => 'Antarctique',
211 'tel_adh' => '0439153432',
212 'activite_adh' => true,
213 'id_statut' => 9,
214 'date_crea_adh' => '2020-06-10',
215 'pref_lang' => 'en_US',
216 'fingerprint' => 'FAKER' . $this->seed,
217 ];
218 return $data;
219 }
220
221 /**
222 * Get Faker data for second member
223 *
224 * @return array
225 */
226 protected function dataAdherentTwo(): array
227 {
228 $bdate = new \DateTime(date('Y') . '-09-13');
229 //member is expected to be 28 years old
230 $years = 28;
231 $now = new \DateTime();
232 if ($now <= $bdate) {
233 ++$years;
234 }
235 $bdate->sub(new \DateInterval('P' . $years . 'Y'));
236
237 $data = [
238 'nom_adh' => 'Hoarau',
239 'prenom_adh' => 'Lucas',
240 'ville_adh' => 'Reynaudnec',
241 'cp_adh' => '63077',
242 'adresse_adh' => '2, boulevard Legros',
243 'email_adh' => 'phoarau@tele2.fr',
244 'login_adh' => 'nathalie51',
245 'mdp_adh' => 'T.u!IbKOi|06',
246 'mdp_adh2' => 'T.u!IbKOi|06',
247 'bool_admin_adh' => false,
248 'bool_exempt_adh' => false,
249 'bool_display_info' => false,
250 'sexe_adh' => 1,
251 'prof_adh' => 'Extraction',
252 'titre_adh' => null,
253 'ddn_adh' => $bdate->format('Y-m-d'),
254 'lieu_naissance' => 'Fischer',
255 'pseudo_adh' => 'vallet.camille',
256 'pays_adh' => null,
257 'tel_adh' => '05 59 53 59 43',
258 'activite_adh' => true,
259 'id_statut' => 9,
260 'date_crea_adh' => '2019-05-20',
261 'pref_lang' => 'ca',
262 'fingerprint' => 'FAKER' . $this->seed,
263 'societe_adh' => 'Philippe',
264 'is_company' => true,
265 ];
266 return $data;
267 }
268
269 /**
270 * Create member from data
271 *
272 * @param array $data Data to use to create member
273 *
274 * @return \Galette\Entity\Adherent
275 */
276 public function createMember(array $data)
277 {
278 $this->adh = new \Galette\Entity\Adherent($this->zdb);
279 $this->adh->setDependencies(
280 $this->preferences,
281 $this->members_fields,
282 $this->history
283 );
284
285 $check = $this->adh->check($data, [], []);
286 if (is_array($check)) {
287 var_dump($check);
288 }
289 $this->boolean($check)->isTrue();
290
291 $store = $this->adh->store();
292 $this->boolean($store)->isTrue();
293
294 return $this->adh;
295 }
296
297 /**
298 * Check members expecteds
299 *
300 * @param Adherent $adh Member instance, if any
301 * @param array $new_expecteds Changes on expected values
302 *
303 * @return void
304 */
305 protected function checkMemberOneExpected($adh = null, $new_expecteds = [])
306 {
307 if ($adh === null) {
308 $adh = $this->adh;
309 }
310
311 $expecteds = [
312 'nom_adh' => 'Durand',
313 'prenom_adh' => 'René',
314 'ville_adh' => 'Martel',
315 'cp_adh' => '07 926',
316 'adresse_adh' => '66, boulevard De Oliveira',
317 'email_adh' => 'meunier.josephine@ledoux.com',
318 'login_adh' => 'arthur.hamon',
319 'mdp_adh' => 'J^B-()f',
320 'bool_admin_adh' => false,
321 'bool_exempt_adh' => false,
322 'bool_display_info' => true,
323 'sexe_adh' => 0,
324 'prof_adh' => 'Chef de fabrication',
325 'titre_adh' => null,
326 'ddn_adh' => 'NOT USED',
327 'lieu_naissance' => 'Gonzalez-sur-Meunier',
328 'pseudo_adh' => 'ubertrand',
329 'cp_adh' => '39 069',
330 'pays_adh' => 'Antarctique',
331 'tel_adh' => '0439153432',
332 'activite_adh' => true,
333 'id_statut' => 9,
334 'pref_lang' => 'en_US',
335 'fingerprint' => 'FAKER95842354',
336 'societe_adh' => ''
337 ];
338 $expecteds = array_merge($expecteds, $new_expecteds);
339
340 foreach ($expecteds as $key => $value) {
341 $property = $this->members_fields[$key]['propname'];
342 switch ($key) {
343 case 'bool_admin_adh':
344 $this->boolean($adh->isAdmin())->isIdenticalTo($value);
345 break;
346 case 'bool_exempt_adh':
347 $this->boolean($adh->isDueFree())->isIdenticalTo($value);
348 break;
349 case 'bool_display_info':
350 $this->boolean($adh->appearsInMembersList())->isIdenticalTo($value);
351 break;
352 case 'activite_adh':
353 $this->boolean($adh->isActive())->isIdenticalTo($value);
354 break;
355 case 'mdp_adh':
356 $pw_checked = password_verify($value, $adh->password);
357 $this->boolean($pw_checked)->isTrue();
358 break;
359 case 'ddn_adh':
360 //rely on age, not on birthdate
361 $this->variable($adh->$property)->isNotNull();
362 $this->string($adh->getAge())->isIdenticalTo(' (82 years old)');
363 break;
364 default:
365 $this->variable($adh->$property)->isIdenticalTo(
366 $value,
367 "$property expected {$value} got {$adh->$property}"
368 );
369
370 break;
371 }
372 }
373
374 $d = \DateTime::createFromFormat('Y-m-d', $expecteds['ddn_adh']);
375
376 $expected_str = ' (82 years old)';
377 $this->string($adh->getAge())->isIdenticalTo($expected_str);
378 $this->boolean($adh->hasChildren())->isFalse();
379 $this->boolean($adh->hasParent())->isFalse();
380 $this->boolean($adh->hasPicture())->isFalse();
381
382 $this->string($adh->sadmin)->isIdenticalTo('No');
383 $this->string($adh->sdue_free)->isIdenticalTo('No');
384 $this->string($adh->sappears_in_list)->isIdenticalTo('Yes');
385 $this->string($adh->sstaff)->isIdenticalTo('No');
386 $this->string($adh->sactive)->isIdenticalTo('Active');
387 $this->variable($adh->stitle)->isNull();
388 $this->string($adh->sstatus)->isIdenticalTo('Non-member');
389 $this->string($adh->sfullname)->isIdenticalTo('DURAND René');
390 $this->string($adh->saddress)->isIdenticalTo('66, boulevard De Oliveira');
391 $this->string($adh->sname)->isIdenticalTo('DURAND René');
392
393 $this->string($adh->getAddress())->isIdenticalTo($expecteds['adresse_adh']);
394 $this->string($adh->getAddressContinuation())->isEmpty();
395 $this->string($adh->getZipcode())->isIdenticalTo($expecteds['cp_adh']);
396 $this->string($adh->getTown())->isIdenticalTo($expecteds['ville_adh']);
397 $this->string($adh->getCountry())->isIdenticalTo($expecteds['pays_adh']);
398
399 $this->string($adh::getSName($this->zdb, $adh->id))->isIdenticalTo('DURAND René');
400 $this->string($adh->getRowClass())->isIdenticalTo('active cotis-never');
401 }
402
403 /**
404 * Check members expecteds
405 *
406 * @param Adherent $adh Member instance, if any
407 * @param array $new_expecteds Changes on expected values
408 *
409 * @return void
410 */
411 protected function checkMemberTwoExpected($adh = null, $new_expecteds = [])
412 {
413 if ($adh === null) {
414 $adh = $this->adh;
415 }
416
417 $expecteds = [
418 'nom_adh' => 'Hoarau',
419 'prenom_adh' => 'Lucas',
420 'ville_adh' => 'Reynaudnec',
421 'cp_adh' => '63077',
422 'adresse_adh' => '2, boulevard Legros',
423 'email_adh' => 'phoarau@tele2.fr',
424 'login_adh' => 'nathalie51',
425 'mdp_adh' => 'T.u!IbKOi|06',
426 'bool_admin_adh' => false,
427 'bool_exempt_adh' => false,
428 'bool_display_info' => false,
429 'sexe_adh' => 1,
430 'prof_adh' => 'Extraction',
431 'titre_adh' => null,
432 'ddn_adh' => 'NOT USED',
433 'lieu_naissance' => 'Fischer',
434 'pseudo_adh' => 'vallet.camille',
435 'pays_adh' => '',
436 'tel_adh' => '05 59 53 59 43',
437 'activite_adh' => true,
438 'id_statut' => 9,
439 'pref_lang' => 'ca',
440 'fingerprint' => 'FAKER' . $this->seed,
441 'societe_adh' => 'Philippe'
442 ];
443 $expecteds = array_merge($expecteds, $new_expecteds);
444
445 foreach ($expecteds as $key => $value) {
446 $property = $this->members_fields[$key]['propname'];
447 switch ($key) {
448 case 'bool_admin_adh':
449 $this->boolean($adh->isAdmin())->isIdenticalTo($value);
450 break;
451 case 'bool_exempt_adh':
452 $this->boolean($adh->isDueFree())->isIdenticalTo($value);
453 break;
454 case 'bool_display_info':
455 $this->boolean($adh->appearsInMembersList())->isIdenticalTo($value);
456 break;
457 case 'activite_adh':
458 $this->boolean($adh->isActive())->isIdenticalTo($value);
459 break;
460 case 'mdp_adh':
461 $pw_checked = password_verify($value, $adh->password);
462 $this->boolean($pw_checked)->isTrue();
463 break;
464 case 'ddn_adh':
465 //rely on age, not on birthdate
466 $this->variable($adh->$property)->isNotNull();
467 $this->string($adh->getAge())->isIdenticalTo(' (28 years old)');
468 break;
469 default:
470 $this->variable($adh->$property)->isIdenticalTo(
471 $value,
472 "$property expected {$value} got {$adh->$property}"
473 );
474 break;
475 }
476 }
477
478 $d = \DateTime::createFromFormat('Y-m-d', $expecteds['ddn_adh']);
479
480 $expected_str = ' (28 years old)';
481 $this->string($adh->getAge())->isIdenticalTo($expected_str);
482 $this->boolean($adh->hasChildren())->isFalse();
483 $this->boolean($adh->hasParent())->isFalse();
484 $this->boolean($adh->hasPicture())->isFalse();
485
486 $this->string($adh->sadmin)->isIdenticalTo('No');
487 $this->string($adh->sdue_free)->isIdenticalTo('No');
488 $this->string($adh->sappears_in_list)->isIdenticalTo('No');
489 $this->string($adh->sstaff)->isIdenticalTo('No');
490 $this->string($adh->sactive)->isIdenticalTo('Active');
491 $this->variable($adh->stitle)->isNull();
492 $this->string($adh->sstatus)->isIdenticalTo('Non-member');
493 $this->string($adh->sfullname)->isIdenticalTo('HOARAU Lucas');
494 $this->string($adh->saddress)->isIdenticalTo('2, boulevard Legros');
495 $this->string($adh->sname)->isIdenticalTo('HOARAU Lucas');
496
497 $this->string($adh->getAddress())->isIdenticalTo($expecteds['adresse_adh']);
498 $this->string($adh->getAddressContinuation())->isEmpty();
499 $this->string($adh->getZipcode())->isIdenticalTo($expecteds['cp_adh']);
500 $this->string($adh->getTown())->isIdenticalTo($expecteds['ville_adh']);
501 $this->string($adh->getCountry())->isIdenticalTo($expecteds['pays_adh']);
502
503 $this->string($adh::getSName($this->zdb, $adh->id))->isIdenticalTo('HOARAU Lucas');
504 $this->string($adh->getRowClass())->isIdenticalTo('active cotis-never');
505 }
506
507 /**
508 * Look in database if test member already exists
509 *
510 * @return false|ResultSet
511 */
512 protected function adhOneExists()
513 {
514 $mdata = $this->dataAdherentOne();
515 $select = $this->zdb->select(\Galette\Entity\Adherent::TABLE, 'a');
516 $select->where(
517 array(
518 'a.fingerprint' => 'FAKER' . $this->seed,
519 'a.login_adh' => $mdata['login_adh']
520 )
521 );
522
523 $results = $this->zdb->execute($select);
524 if ($results->count() === 0) {
525 return false;
526 } else {
527 return $results;
528 }
529 }
530
531 /**
532 * Look in database if test member already exists
533 *
534 * @return false|ResultSet
535 */
536 protected function adhTwoExists()
537 {
538 $mdata = $this->dataAdherentTwo();
539 $select = $this->zdb->select(\Galette\Entity\Adherent::TABLE, 'a');
540 $select->where(
541 array(
542 'a.fingerprint' => 'FAKER' . $this->seed,
543 'a.login_adh' => $mdata['login_adh']
544 )
545 );
546
547 $results = $this->zdb->execute($select);
548 if ($results->count() === 0) {
549 return false;
550 } else {
551 return $results;
552 }
553 }
554
555 /**
556 * Get member one
557 *
558 * @return \Galette\Entity\Adherent
559 */
560 protected function getMemberOne()
561 {
562 $rs = $this->adhOneExists();
563 if ($rs === false) {
564 $this->createMember($this->dataAdherentOne());
565 } else {
566 $this->loadAdherent($rs->current()->id_adh);
567 }
568 }
569
570 /**
571 * Get member two
572 *
573 * @return \Galette\Entity\Adherent
574 */
575 protected function getMemberTwo()
576 {
577 $rs = $this->adhTwoExists();
578 if ($rs === false) {
579 $this->createMember($this->dataAdherentTwo());
580 } else {
581 $this->loadAdherent($rs->current()->id_adh);
582 }
583 }
584
585 /**
586 * Create contribution from data
587 *
588 * @param array $data Data to use to create contribution
589 *
590 * @return \Galette\Entity\Contribution
591 */
592 public function createContrib(array $data)
593 {
594 $this->contrib = new \Galette\Entity\Contribution($this->zdb, $this->login);
595 $contrib = $this->contrib;
596 $check = $contrib->check($data, [], []);
597 if (is_array($check)) {
598 var_dump($check);
599 }
600 $this->boolean($check)->isTrue();
601
602 $store = $contrib->store();
603 $this->boolean($store)->isTrue();
604
605 return $contrib;
606 }
607
608 /**
609 * Create test contribution in database
610 *
611 * @return void
612 */
613 protected function createContribution()
614 {
615 $bdate = new \DateTime(); // 2020-11-07
616 $bdate->sub(new \DateInterval('P5M')); // 2020-06-07
617 $bdate->add(new \DateInterval('P3D')); // 2020-06-10
618
619 $edate = clone $bdate;
620 $edate->add(new \DateInterval('P1Y'));
621
622 $data = [
623 'id_adh' => $this->adh->id,
624 'id_type_cotis' => 1, //annual fee
625 'montant_cotis' => 92,
626 'type_paiement_cotis' => 3,
627 'info_cotis' => 'FAKER' . $this->seed,
628 'date_enreg' => $bdate->format('Y-m-d'),
629 'date_debut_cotis' => $bdate->format('Y-m-d'),
630 'date_fin_cotis' => $edate->format('Y-m-d'),
631 ];
632 $this->createContrib($data);
633 $this->checkContribExpected();
634 }
635
636 /**
637 * Check contributions expected
638 *
639 * @param Contribution $contrib Contribution instance, if any
640 * @param array $new_expecteds Changes on expected values
641 *
642 * @return void
643 */
644 protected function checkContribExpected($contrib = null, $new_expecteds = [])
645 {
646 if ($contrib === null) {
647 $contrib = $this->contrib;
648 }
649
650 $date_begin = $contrib->raw_begin_date;
651 $date_end = clone $date_begin;
652 $date_end->add(new \DateInterval('P1Y'));
653
654 $this->object($contrib->raw_date)->isInstanceOf('DateTime');
655 $this->object($contrib->raw_begin_date)->isInstanceOf('DateTime');
656 $this->object($contrib->raw_end_date)->isInstanceOf('DateTime');
657
658 $expecteds = [
659 'id_adh' => "{$this->adh->id}",
660 'id_type_cotis' => 1, //annual fee
661 'montant_cotis' => '92',
662 'type_paiement_cotis' => '3',
663 'info_cotis' => 'FAKER' . $this->seed,
664 'date_fin_cotis' => $date_end->format('Y-m-d'),
665 ];
666 $expecteds = array_merge($expecteds, $new_expecteds);
667
668 $this->string($contrib->raw_end_date->format('Y-m-d'))->isIdenticalTo($expecteds['date_fin_cotis']);
669
670 foreach ($expecteds as $key => $value) {
671 $property = $this->contrib->fields[$key]['propname'];
672 switch ($key) {
673 case \Galette\Entity\ContributionsTypes::PK:
674 $ct = $this->contrib->type;
675 if ($ct instanceof \Galette\Entity\ContributionsTypes) {
676 $this->integer((int)$ct->id)->isIdenticalTo($value);
677 } else {
678 $this->integer($ct)->isIdenticalTo($value);
679 }
680 break;
681 default:
682 $this->variable($contrib->$property)->isEqualTo($value, $property);
683 break;
684 }
685 }
686
687 //load member from db
688 $this->adh = new \Galette\Entity\Adherent($this->zdb, $this->adh->id);
689 //member is now up-to-date
690 $this->string($this->adh->getRowClass())->isIdenticalTo('active cotis-ok');
691 $this->string($this->adh->due_date)->isIdenticalTo($this->contrib->end_date);
692 $this->boolean($this->adh->isUp2Date())->isTrue();
693 $this->boolean($contrib->isFee())->isTrue();
694 $this->string($contrib->getTypeLabel())->isIdenticalTo('Membership');
695 $this->string($contrib->getRawType())->isIdenticalTo('membership');
696 $this->array($this->contrib->getRequired())->isIdenticalTo([
697 'id_type_cotis' => 1,
698 'id_adh' => 1,
699 'date_enreg' => 1,
700 'date_debut_cotis' => 1,
701 'date_fin_cotis' => 1,
702 'montant_cotis' => 1
703 ]);
704 }
705
706 /**
707 * Initialize default status in database
708 *
709 * @return void
710 */
711 protected function initStatus(): void
712 {
713 $status = new \Galette\Entity\Status($this->zdb);
714 if (count($status->getList()) === 0) {
715 //status are not yet instantiated.
716 $res = $status->installInit();
717 $this->boolean($res)->isTrue();
718 }
719 }
720
721 /**
722 * Initialize default contributions types in database
723 *
724 * @return void
725 */
726 protected function initContributionsTypes(): void
727 {
728 $ct = new \Galette\Entity\ContributionsTypes($this->zdb);
729 if (count($ct->getCompleteList()) === 0) {
730 //status are not yet instanciated.
731 $res = $ct->installInit();
732 $this->boolean($res)->isTrue();
733 }
734 }
735
736 /**
737 * Initialize default titles in database
738 *
739 * @return void
740 */
741 protected function initTitles(): void
742 {
743 $titles = new \Galette\Repository\Titles($this->zdb);
744 if (count($titles->getList($this->zdb)) === 0) {
745 $res = $titles->installInit($this->zdb);
746 $this->boolean($res)->isTrue();
747 }
748 }
749
750 /**
751 * Clean history
752 *
753 * @return void
754 */
755 protected function cleanHistory(): void
756 {
757 $this->zdb->db->query(
758 'TRUNCATE TABLE ' . PREFIX_DB . \Galette\Core\History::TABLE,
759 \Zend\Db\Adapter\Adapter::QUERY_MODE_EXECUTE
760 );
761 }
762
763 /**
764 * Log-in as super administrator
765 *
766 * @return void
767 */
768 protected function logSuperAdmin(): void
769 {
770 $this->login->logAdmin('superadmin', $this->preferences);
771 $this->boolean($this->login->isLogged())->isTrue();
772 $this->boolean($this->login->isSuperAdmin())->isTrue();
773 }
774 }