]> git.agnieray.net Git - galette.git/blob - tests/Galette/Entity/tests/units/Contribution.php
0e5a1a85c72681d2e08d0f84ca5602a94edb9469
[galette.git] / tests / Galette / Entity / tests / units / Contribution.php
1 <?php
2
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5 /**
6 * Contribution tests
7 *
8 * PHP version 5
9 *
10 * Copyright © 2017-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 Entity
28 * @package GaletteTests
29 *
30 * @author Johan Cwiklinski <johan@x-tnd.be>
31 * @copyright 2017-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.tuxfamily.org
34 * @since 2017-06-11
35 */
36
37 namespace Galette\Entity\test\units;
38
39 use Galette\GaletteTestCase;
40
41 /**
42 * Contribution tests class
43 *
44 * @category Entity
45 * @name Contribution
46 * @package GaletteTests
47 * @author Johan Cwiklinski <johan@x-tnd.be>
48 * @copyright 2017-2023 The Galette Team
49 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
50 * @link http://galette.tuxfamily.org
51 * @since 2017-06-11
52 */
53 class Contribution extends GaletteTestCase
54 {
55 protected int $seed = 95842354;
56
57 /**
58 * Cleanup after each test method
59 *
60 * @return void
61 */
62 public function tearDown(): void
63 {
64 parent::tearDown();
65
66 $this->zdb = new \Galette\Core\Db();
67 $delete = $this->zdb->delete(\Galette\Entity\Contribution::TABLE);
68 $delete->where(['info_cotis' => 'FAKER' . $this->seed]);
69 $this->zdb->execute($delete);
70
71 $delete = $this->zdb->delete(\Galette\Entity\Adherent::TABLE);
72 $delete->where(['fingerprint' => 'FAKER' . $this->seed]);
73 $delete->where('parent_id IS NOT NULL');
74 $this->zdb->execute($delete);
75
76 $delete = $this->zdb->delete(\Galette\Entity\Adherent::TABLE);
77 $delete->where(['fingerprint' => 'FAKER' . $this->seed]);
78 $this->zdb->execute($delete);
79 }
80
81 /**
82 * Set up tests
83 *
84 * @return void
85 */
86 public function setUp(): void
87 {
88 parent::setUp();
89 $this->initContributionsTypes();
90
91 $this->contrib = new \Galette\Entity\Contribution($this->zdb, $this->login);
92
93 $this->adh = new \Galette\Entity\Adherent($this->zdb);
94 $this->adh->setDependencies(
95 $this->preferences,
96 $this->members_fields,
97 $this->history
98 );
99 }
100
101 /**
102 * Test empty contribution
103 *
104 * @return void
105 */
106 public function testEmpty()
107 {
108 $contrib = $this->contrib;
109 $this->assertNull($contrib->id);
110 $this->assertNull($contrib->isFee());
111 $this->assertNull($contrib->is_cotis);
112 $this->assertNull($contrib->date);
113 $this->assertNull($contrib->begin_date);
114 $this->assertNull($contrib->end_date);
115 $this->assertNull($contrib->raw_date);
116 $this->assertNull($contrib->raw_begin_date);
117 $this->assertNull($contrib->raw_end_date);
118 $this->assertEmpty($contrib->duration);
119 $this->assertSame((int)$this->preferences->pref_default_paymenttype, $contrib->payment_type);
120 $this->assertSame('Check', $contrib->spayment_type);
121 $this->assertNull($contrib->model);
122 $this->assertNull($contrib->member);
123 $this->assertNull($contrib->type);
124 $this->assertNull($contrib->amount);
125 $this->assertNull($contrib->orig_amount);
126 $this->assertNull($contrib->info);
127 $this->assertNull($contrib->transaction);
128 $this->assertCount(11, $contrib->fields);
129 $this->assertTrue(isset($contrib->fields[\Galette\Entity\Contribution::PK]));
130 $this->assertTrue(isset($contrib->fields[\Galette\Entity\Adherent::PK]));
131 $this->assertTrue(isset($contrib->fields[\Galette\Entity\ContributionsTypes::PK]));
132 $this->assertTrue(isset($contrib->fields['montant_cotis']));
133 $this->assertTrue(isset($contrib->fields['type_paiement_cotis']));
134 $this->assertTrue(isset($contrib->fields['info_cotis']));
135 $this->assertTrue(isset($contrib->fields['date_debut_cotis']));
136
137 $this->assertSame('cotis-give', $contrib->getRowClass());
138 $this->assertNull($contrib::getDueDate($this->zdb, 1));
139 $this->assertFalse($contrib->isTransactionPart());
140 $this->assertFalse($contrib->isTransactionPartOf(1));
141 $this->assertSame('donation', $contrib->getRawType());
142 $this->assertSame('Donation', $contrib->getTypeLabel());
143 $this->assertSame('Check', $contrib->getPaymentType());
144 $this->assertNull($contrib->unknown_property);
145 }
146
147 /**
148 * Test getter and setter special cases
149 *
150 * @return void
151 */
152 public function testGetterSetter()
153 {
154 $contrib = $this->contrib;
155
156 //set a bad date
157 $contrib->begin_date = 'not a date';
158 $this->assertNull($contrib->raw_begin_date);
159 $this->assertNull($contrib->begin_date);
160
161 $contrib->begin_date = '2017-06-17';
162 $this->assertInstanceOf('DateTime', $contrib->raw_begin_date);
163 $this->assertSame('2017-06-17', $contrib->begin_date);
164
165 $contrib->amount = 'not an amount';
166 $this->assertNull($contrib->amount);
167 $contrib->amount = 0;
168 $this->assertNull($contrib->amount);
169 $contrib->amount = 42;
170 $this->assertSame(42, $contrib->amount);
171 $contrib->amount = '42';
172 $this->assertSame('42', $contrib->amount);
173
174 $contrib->type = 'not a type';
175 $this->assertNull($contrib->type);
176 $contrib->type = 156;
177 $this->assertInstanceOf('\Galette\Entity\ContributionsTypes', $contrib->type);
178 $this->assertFalse($contrib->type->id);
179 $contrib->type = 1;
180 $this->assertInstanceOf('\Galette\Entity\ContributionsTypes', $contrib->type);
181 $this->assertEquals(1, $contrib->type->id);
182
183 $contrib->transaction = 'not a transaction id';
184 $this->assertNull($contrib->transaction);
185 $contrib->transaction = 46;
186 $this->assertInstanceOf('\Galette\Entity\Transaction', $contrib->transaction);
187 $this->assertNull($contrib->transaction->id);
188
189 $contrib->member = 'not a member';
190 $this->assertNull($contrib->member);
191 $contrib->member = 118218;
192 $this->assertSame(118218, $contrib->member);
193
194 $contrib->not_a_property = 'abcde';
195 $this->assertFalse(property_exists($contrib, 'not_a_property'));
196
197 $contrib->payment_type = \Galette\Entity\PaymentType::CASH;
198 $this->assertSame('Cash', $contrib->getPaymentType());
199 $this->assertSame('Cash', $contrib->spayment_type);
200
201 $contrib->payment_type = \Galette\Entity\PaymentType::CHECK;
202 $this->assertSame('Check', $contrib->getPaymentType());
203 $this->assertSame('Check', $contrib->spayment_type);
204
205 $contrib->payment_type = \Galette\Entity\PaymentType::OTHER;
206 $this->assertSame('Other', $contrib->getPaymentType());
207 $this->assertSame('Other', $contrib->spayment_type);
208
209 $contrib->payment_type = \Galette\Entity\PaymentType::CREDITCARD;
210 $this->assertSame('Credit card', $contrib->getPaymentType());
211 $this->assertSame('Credit card', $contrib->spayment_type);
212
213 $contrib->payment_type = \Galette\Entity\PaymentType::TRANSFER;
214 $this->assertSame('Transfer', $contrib->getPaymentType());
215 $this->assertSame('Transfer', $contrib->spayment_type);
216
217 $contrib->payment_type = \Galette\Entity\PaymentType::PAYPAL;
218 $this->assertSame('Paypal', $contrib->getPaymentType());
219 $this->assertSame('Paypal', $contrib->spayment_type);
220 }
221
222 /**
223 * Test contribution creation
224 *
225 * @return void
226 */
227 public function testCreation()
228 {
229 $this->getMemberOne();
230 //create contribution for member
231 $this->createContribution();
232 }
233
234 /**
235 * Test donation update
236 *
237 * @return void
238 */
239 public function testDonationUpdate()
240 {
241 $this->getMemberOne();
242 //create contribution for member
243 $begin_date = new \DateTime(); // 2020-11-07
244 $begin_date->sub(new \DateInterval('P5M')); // 2020-06-07
245 $begin_date->add(new \DateInterval('P3D')); // 2020-06-10
246
247 $due_date = clone $begin_date;
248 $due_date->add(new \DateInterval('P1Y'));
249 $due_date->sub(new \DateInterval('P1D'));
250
251 $data = [
252 'id_adh' => $this->adh->id,
253 'id_type_cotis' => 4, //donation
254 'montant_cotis' => 12,
255 'type_paiement_cotis' => 3,
256 'info_cotis' => 'FAKER' . $this->seed,
257 'date_enreg' => $begin_date->format('Y-m-d'),
258 'date_debut_cotis' => $begin_date->format('Y-m-d'),
259 'date_fin_cotis' => $due_date->format('Y-m-d'),
260 ];
261 $this->createContrib($data);
262 $this->assertSame(
263 [
264 'id_type_cotis' => 1,
265 'id_adh' => 1,
266 'date_enreg' => 1,
267 'date_debut_cotis' => 1,
268 'date_fin_cotis' => 0,
269 'montant_cotis' => 0
270 ],
271 $this->contrib->getRequired()
272 );
273
274 $this->logSuperAdmin();
275 $data = [
276 'id_adh' => $this->adh->id,
277 'id_type_cotis' => 4, //donation
278 'montant_cotis' => 1280,
279 'type_paiement_cotis' => 4,
280 'info_cotis' => 'FAKER' . $this->seed,
281 'date_enreg' => $begin_date->format('Y-m-d'),
282 'date_debut_cotis' => $begin_date->format('Y-m-d'),
283 'date_fin_cotis' => $due_date->format('Y-m-d'),
284 ];
285 $this->createContrib($data);
286
287 $contrib = new \Galette\Entity\Contribution($this->zdb, $this->login, $this->contrib->id);
288 $this->assertSame(1280.00, $contrib->amount);
289
290 //empty amount
291 $data = [
292 'id_adh' => $this->adh->id,
293 'id_type_cotis' => 4, //donation
294 'montant_cotis' => '',
295 'type_paiement_cotis' => 4,
296 'info_cotis' => 'FAKER' . $this->seed,
297 'date_enreg' => $begin_date->format('Y-m-d'),
298 'date_debut_cotis' => $begin_date->format('Y-m-d'),
299 'date_fin_cotis' => $due_date->format('Y-m-d'),
300 ];
301 $this->createContrib($data);
302
303 $contrib = new \Galette\Entity\Contribution($this->zdb, $this->login, $this->contrib->id);
304 $this->assertSame(0.00, $contrib->amount);
305 }
306
307 /**
308 * Test contribution update
309 *
310 * @return void
311 */
312 public function testContributionUpdate()
313 {
314 $this->logSuperAdmin();
315
316 $this->getMemberOne();
317 //create contribution for member
318 $begin_date = new \DateTime(); // 2020-11-07
319 $begin_date->sub(new \DateInterval('P5M')); // 2020-06-07
320 $begin_date->add(new \DateInterval('P3D')); // 2020-06-10
321
322 $due_date = clone $begin_date;
323 $due_date->add(new \DateInterval('P1Y'));
324 $due_date->sub(new \DateInterval('P1D'));
325
326 //instanciate contribution as annual fee
327 $this->contrib = new \Galette\Entity\Contribution(
328 $this->zdb,
329 $this->login,
330 [
331 'type' => 1 //annual fee
332 ]
333 );
334 $this->assertSame(
335 [
336 'id_type_cotis' => 1,
337 'id_adh' => 1,
338 'date_enreg' => 1,
339 'date_debut_cotis' => 1,
340 'date_fin_cotis' => 1, //should be 1
341 'montant_cotis' => 1 // should be 1
342 ],
343 $this->contrib->getRequired()
344 );
345
346 $data = [
347 'id_adh' => $this->adh->id,
348 'id_type_cotis' => 1, //annual fee
349 'montant_cotis' => 0,
350 'type_paiement_cotis' => 3,
351 'info_cotis' => 'FAKER' . $this->seed,
352 'date_enreg' => $begin_date->format('Y-m-d'),
353 'date_debut_cotis' => $begin_date->format('Y-m-d'),
354 'date_fin_cotis' => $due_date->format('Y-m-d'),
355 ];
356
357 $this->createContrib($data, $this->contrib);
358
359 $this->assertSame(0.0, $this->contrib->amount);
360 $contrib = new \Galette\Entity\Contribution($this->zdb, $this->login, $this->contrib->id);
361 $this->assertSame(0.0, $contrib->amount);
362
363 //change amount
364 $data['montant_cotis'] = 42;
365 $check = $contrib->check($data, [], []);
366 if (is_array($check)) {
367 var_dump($check);
368 }
369 $this->assertTrue($check);
370
371 $store = $contrib->store();
372 $this->assertTrue($store);
373
374 $contrib = new \Galette\Entity\Contribution($this->zdb, $this->login, $this->contrib->id);
375 $this->assertSame(42.0, $contrib->amount);
376
377 //change amount back to 0
378 $data['montant_cotis'] = 0;
379 $check = $contrib->check($data, [], []);
380 if (is_array($check)) {
381 var_dump($check);
382 }
383 $this->assertTrue($check);
384
385 $store = $contrib->store();
386 $this->assertTrue($store);
387
388 $contrib = new \Galette\Entity\Contribution($this->zdb, $this->login, $this->contrib->id);
389 $this->assertSame(0.0, $contrib->amount);
390 }
391
392 /**
393 * Test end date retrieving
394 * This is based on some Preferences parameters
395 *
396 * @return void
397 */
398 public function testRetrieveEndDate()
399 {
400 global $preferences;
401 $orig_pref_beg_membership = $this->preferences->pref_beg_membership;
402 $orig_pref_membership_ext = $this->preferences->pref_membership_ext;
403 $orig_pref_membership_offermonths = $this->preferences->pref_membership_offermonths;
404
405 $contrib = new \Galette\Entity\Contribution(
406 $this->zdb,
407 $this->login,
408 ['type' => 1] //annual fee
409 );
410
411 // First, check for 12 months renewal
412 $due_date = new \DateTime();
413 $due_date->add(new \DateInterval('P1Y'));
414 $due_date->sub(new \DateInterval('P1D'));
415 $this->assertSame($due_date->format('Y-m-d'), $contrib->end_date);
416
417 //unset pref_beg_membership and pref_membership_ext
418 $preferences->pref_beg_membership = '';
419 $preferences->pref_membership_ext = '';
420
421 $this->expectException('RuntimeException');
422 $this->expectExceptionMessage('Unable to define end date; none of pref_beg_membership nor pref_membership_ext are defined!');
423 $contrib = new \Galette\Entity\Contribution(
424 $this->zdb,
425 $this->login,
426 ['type' => 1] //annual fee
427 );
428
429 // Second, test with beginning of membership date
430 $preferences->pref_beg_membership = '29/05';
431 $due_date = new \DateTime();
432 $due_date->setDate(date('Y'), 5, 28);
433 if ($due_date <= new \DateTime()) {
434 $due_date->add(new \DateInterval('P1Y'));
435 }
436
437 $contrib = new \Galette\Entity\Contribution(
438 $this->zdb,
439 $this->login,
440 ['type' => 1] // annual fee
441 );
442 $this->assertSame($due_date->format('Y-m-d'), $contrib->end_date);
443
444 // Third, test with beginning of membership date and 2 last months offered
445 $begin_date = new \DateTime();
446 $begin_date->add(new \DateInterval('P1M'));
447 $preferences->pref_beg_membership = $begin_date->format('01/m');
448 $preferences->pref_membership_offermonths = 2;
449 $due_date = new \DateTime($begin_date->format('Y-m-01'));
450 $due_date->add(new \DateInterval('P1Y'));
451 $due_date->sub(new \DateInterval('P1D'));
452
453 $contrib = new \Galette\Entity\Contribution(
454 $this->zdb,
455 $this->login,
456 ['type' => 1] // annual fee
457 );
458 $this->assertSame($due_date->format('Y-m-d'), $contrib->end_date);
459
460 //reset
461 $preferences->pref_beg_membership = $orig_pref_beg_membership;
462 $preferences->pref_membership_ext = $orig_pref_membership_ext;
463 $preferences->pref_membership_offermonths = $orig_pref_membership_offermonths;
464 }
465
466 /**
467 * Test checkOverlap method
468 *
469 * @return void
470 */
471 public function testCheckOverlap()
472 {
473 $adh = new \Galette\Entity\Adherent($this->zdb);
474 $adh->setDependencies(
475 $this->preferences,
476 $this->members_fields,
477 $this->history
478 );
479
480 $check = $adh->check(
481 [
482 'nom_adh' => 'Overlapped',
483 'date_crea_adh' => date(_T("Y-m-d")),
484 \Galette\Entity\Status::PK => \Galette\Entity\Status::DEFAULT_STATUS,
485 'fingerprint' => 'FAKER' . $this->seed
486 ],
487 [],
488 []
489 );
490 if (is_array($check)) {
491 var_dump($check);
492 }
493 $this->assertTrue($check);
494
495 $store = $adh->store();
496 $this->assertTrue($store);
497
498 //create first contribution for member
499 $contrib = new \Galette\Entity\Contribution($this->zdb, $this->login);
500
501 $now = new \DateTime();
502 $due_date = clone $now;
503 $due_date->add(new \DateInterval('P1Y'));
504 $due_date->sub(new \DateInterval('P1D'));
505 $data = [
506 \Galette\Entity\Adherent::PK => $adh->id,
507 \Galette\Entity\ContributionsTypes::PK => 1, //annual fee
508 'montant_cotis' => 20,
509 'type_paiement_cotis' => \Galette\Entity\PaymentType::CHECK,
510 'date_enreg' => $now->format(_T("Y-m-d")),
511 'date_debut_cotis' => $now->format(_T("Y-m-d")),
512 'date_fin_cotis' => $due_date->format(_T("Y-m-d")),
513 'info_cotis' => 'FAKER' . $this->seed
514 ];
515
516 $check = $contrib->check($data, [], []);
517 if (is_array($check)) {
518 var_dump($check);
519 }
520 $this->assertTrue($check);
521 $this->assertTrue($contrib->checkOverlap());
522
523 $store = $contrib->store();
524 $this->assertTrue($store);
525
526 //load member from db
527 $adh = new \Galette\Entity\Adherent($this->zdb, $adh->id);
528
529 $contrib = new \Galette\Entity\Contribution($this->zdb, $this->login);
530 $begin_date = clone $due_date;
531 $begin_date->add(new \DateInterval('P1D'));
532 $begin_date->sub(new \DateInterval('P3M'));
533 $due_date = clone $begin_date;
534 $due_date->add(new \DateInterval('P1Y'));
535 $due_date->sub(new \DateInterval('P1D'));
536 $data = [
537 \Galette\Entity\Adherent::PK => $adh->id,
538 \Galette\Entity\ContributionsTypes::PK => 1, //annual fee
539 'montant_cotis' => 20,
540 'type_paiement_cotis' => \Galette\Entity\PaymentType::CHECK,
541 'date_enreg' => $now->format(_T("Y-m-d")),
542 'date_debut_cotis' => $begin_date->format(_T("Y-m-d")),
543 'date_fin_cotis' => $due_date->format(_T("Y-m-d")),
544 'info_cotis' => 'FAKER' . $this->seed
545 ];
546
547 $check = $contrib->check($data, [], []);
548 $this->assertSame(
549 [
550 '- Membership period overlaps period starting at ' . $now->format('Y-m-d')
551 ],
552 $check
553 );
554
555 $this->expectException('RuntimeException');
556 $this->expectExceptionMessage('Existing errors prevents storing contribution');
557 $store = $contrib->store();
558 }
559
560 /**
561 * Test fields labels
562 *
563 * @return void
564 */
565 public function testGetFieldLabel()
566 {
567 $this->assertSame(
568 'Amount',
569 $this->contrib->getFieldLabel('montant_cotis')
570 );
571
572 $this->assertSame(
573 'Date of contribution',
574 $this->contrib->getFieldLabel('date_debut_cotis')
575 );
576
577 $this->contrib->type = 1;
578 $this->assertSame(
579 'Start date of membership',
580 $this->contrib->getFieldLabel('date_debut_cotis')
581 );
582
583 $this->assertSame(
584 'Comments',
585 $this->contrib->getFieldLabel('info_cotis')
586 );
587 }
588
589 /**
590 * Test contribution loading
591 *
592 * @return void
593 */
594 public function testLoad()
595 {
596 $this->login = $this->getMockBuilder(\Galette\Core\Login::class)
597 ->setConstructorArgs(array($this->zdb, $this->i18n))
598 ->onlyMethods(array('isLogged', 'isStaff', 'isAdmin'))
599 ->getMock();
600 $this->login->method('isLogged')->willReturn(true);
601 $this->login->method('isStaff')->willReturn(true);
602 $this->login->method('isAdmin')->willReturn(true);
603
604 $this->getMemberOne();
605
606 //create contribution for member
607 $this->createContribution();
608
609 $id = $this->contrib->id;
610 $contrib = new \Galette\Entity\Contribution($this->zdb, $this->login);
611
612 $this->assertTrue($contrib->load((int)$id));
613 $this->checkContribExpected($contrib);
614
615 $this->assertFalse($contrib->load(1355522012));
616 }
617
618 /**
619 * Test contribution removal
620 *
621 * @return void
622 */
623 public function testRemove()
624 {
625 $this->getMemberOne();
626 $this->createContribution();
627
628 $this->assertTrue($this->contrib->remove());
629 $this->assertFalse($this->contrib->remove());
630 }
631
632 /**
633 * Test can* methods
634 *
635 * @return void
636 */
637 public function testCan()
638 {
639 $this->getMemberOne();
640 //create contribution for member
641 $this->createContribution();
642 $contrib = $this->contrib;
643
644 $this->assertFalse($contrib->canShow($this->login));
645
646 //Superadmin can fully change contributions
647 $this->logSuperAdmin();
648
649 $this->assertTrue($contrib->canShow($this->login));
650
651 //logout
652 $this->login->logOut();
653 $this->assertFalse($this->login->isLogged());
654
655 //Member can fully change its own contributions
656 $mdata = $this->dataAdherentOne();
657 $this->assertTrue($this->login->login($mdata['login_adh'], $mdata['mdp_adh']));
658 $this->assertTrue($this->login->isLogged());
659 $this->assertFalse($this->login->isAdmin());
660 $this->assertFalse($this->login->isStaff());
661
662 $this->assertTrue($contrib->canShow($this->login));
663
664 //logout
665 $this->login->logOut();
666 $this->assertFalse($this->login->isLogged());
667
668 //Another member has no access
669 $this->getMemberTwo();
670 $mdata = $this->dataAdherentTwo();
671 $this->assertTrue($this->login->login($mdata['login_adh'], $mdata['mdp_adh']));
672 $this->assertTrue($this->login->isLogged());
673 $this->assertFalse($this->login->isAdmin());
674 $this->assertFalse($this->login->isStaff());
675
676 $this->assertFalse($contrib->canShow($this->login));
677
678 //parents can chow change children contributions
679 $this->getMemberOne();
680 $member = $this->adh;
681 $mdata = $this->dataAdherentOne();
682 global $login;
683 $login = $this->login;
684 $this->logSuperAdmin();
685
686 $child_data = [
687 'nom_adh' => 'Doe',
688 'prenom_adh' => 'Johny',
689 'parent_id' => $member->id,
690 'attach' => true,
691 'login_adh' => 'child.johny.doe',
692 'fingerprint' => 'FAKER' . $this->seed
693 ];
694 $child = $this->createMember($child_data);
695 $cid = $child->id;
696
697 //contribution for child
698 $begin_date = new \DateTime(); // 2020-11-07
699 $begin_date->sub(new \DateInterval('P5M')); // 2020-06-07
700 $begin_date->add(new \DateInterval('P3D')); // 2020-06-10
701
702 $due_date = clone $begin_date;
703 $due_date->add(new \DateInterval('P1Y'));
704 $due_date->sub(new \DateInterval('P1D'));
705
706 $data = [
707 'id_adh' => $cid,
708 'id_type_cotis' => 1,
709 'montant_cotis' => 25,
710 'type_paiement_cotis' => 3,
711 'info_cotis' => 'FAKER' . $this->seed,
712 'date_enreg' => $begin_date->format('Y-m-d'),
713 'date_debut_cotis' => $begin_date->format('Y-m-d'),
714 'date_fin_cotis' => $due_date->format('Y-m-d'),
715 ];
716 $ccontrib = $this->createContrib($data);
717
718 $this->login->logOut();
719
720 //load child from db
721 $child = new \Galette\Entity\Adherent($this->zdb);
722 $child->enableDep('parent');
723 $this->assertTrue($child->load($cid));
724
725 $this->assertSame($child_data['nom_adh'], $child->name);
726 $this->assertInstanceOf('\Galette\Entity\Adherent', $child->parent);
727 $this->assertSame($member->id, $child->parent->id);
728 $this->assertTrue($this->login->login($mdata['login_adh'], $mdata['mdp_adh']));
729
730 $mdata = $this->dataAdherentOne();
731 $this->assertTrue($this->login->login($mdata['login_adh'], $mdata['mdp_adh']));
732 $this->assertTrue($this->login->isLogged());
733 $this->assertFalse($this->login->isAdmin());
734 $this->assertFalse($this->login->isStaff());
735
736 $this->assertTrue($ccontrib->canShow($this->login));
737
738 //logout
739 $this->login->logOut();
740 $this->assertFalse($this->login->isLogged());
741 }
742 }