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