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