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