4 * Copyright © 2003-2024 The Galette Team
6 * This file is part of Galette (https://galette.eu).
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.
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.
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/>.
22 namespace Galette\Entity\test\units
;
24 use Galette\GaletteTestCase
;
27 * Contribution tests class
29 * @author Johan Cwiklinski <johan@x-tnd.be>
31 class Contribution
extends GaletteTestCase
33 protected int $seed = 95842354;
36 * Cleanup after each test method
40 public function tearDown(): void
44 $this->zdb
= new \Galette\Core\
Db();
45 $delete = $this->zdb
->delete(\Galette\Entity\Contribution
::TABLE
);
46 $delete->where(['info_cotis' => 'FAKER' . $this->seed
]);
47 $this->zdb
->execute($delete);
49 $delete = $this->zdb
->delete(\Galette\Entity\Adherent
::TABLE
);
50 $delete->where(['fingerprint' => 'FAKER' . $this->seed
]);
51 $delete->where('parent_id IS NOT NULL');
52 $this->zdb
->execute($delete);
54 $delete = $this->zdb
->delete(\Galette\Entity\Adherent
::TABLE
);
55 $delete->where(['fingerprint' => 'FAKER' . $this->seed
]);
56 $this->zdb
->execute($delete);
64 public function setUp(): void
67 $this->initContributionsTypes();
69 $this->contrib
= new \Galette\Entity\
Contribution($this->zdb
, $this->login
);
71 $this->adh
= new \Galette\Entity\
Adherent($this->zdb
);
72 $this->adh
->setDependencies(
74 $this->members_fields
,
80 * Test empty contribution
84 public function testEmpty()
86 $contrib = $this->contrib
;
87 $this->assertNull($contrib->id
);
88 $this->assertNull($contrib->date
);
89 $this->assertNull($contrib->begin_date
);
90 $this->assertNull($contrib->end_date
);
91 $this->assertNull($contrib->raw_date
);
92 $this->assertNull($contrib->raw_begin_date
);
93 $this->assertNull($contrib->raw_end_date
);
94 $this->assertEmpty($contrib->duration
);
95 $this->assertSame((int)$this->preferences
->pref_default_paymenttype
, $contrib->payment_type
);
96 $this->assertSame('Check', $contrib->getPaymentType());
97 $this->assertNull($contrib->model
);
98 $this->assertNull($contrib->member
);
99 $this->assertNull($contrib->type
);
100 $this->assertNull($contrib->amount
);
101 $this->assertNull($contrib->orig_amount
);
102 $this->assertNull($contrib->info
);
103 $this->assertNull($contrib->transaction
);
104 $this->assertCount(11, $contrib->fields
);
105 $this->assertTrue(isset($contrib->fields
[\Galette\Entity\Contribution
::PK
]));
106 $this->assertTrue(isset($contrib->fields
[\Galette\Entity\Adherent
::PK
]));
107 $this->assertTrue(isset($contrib->fields
[\Galette\Entity\ContributionsTypes
::PK
]));
108 $this->assertTrue(isset($contrib->fields
['montant_cotis']));
109 $this->assertTrue(isset($contrib->fields
['type_paiement_cotis']));
110 $this->assertTrue(isset($contrib->fields
['info_cotis']));
111 $this->assertTrue(isset($contrib->fields
['date_debut_cotis']));
113 $this->assertSame('cotis-give', $contrib->getRowClass());
114 $this->assertNull($contrib::getDueDate($this->zdb
, 1));
115 $this->assertFalse($contrib->isTransactionPart());
116 $this->assertFalse($contrib->isTransactionPartOf(1));
117 $this->assertSame('Check', $contrib->getPaymentType());
118 $this->assertNull($contrib->unknown_property
);
122 * Test getter and setter special cases
126 public function testGetterSetter()
128 $contrib = $this->contrib
;
131 $contrib->begin_date
= 'not a date';
132 $this->assertNull($contrib->raw_begin_date
);
133 $this->assertNull($contrib->begin_date
);
135 $contrib->begin_date
= '2017-06-17';
136 $this->assertInstanceOf('DateTime', $contrib->raw_begin_date
);
137 $this->assertSame('2017-06-17', $contrib->begin_date
);
139 $contrib->amount
= 'not an amount';
140 $this->assertNull($contrib->amount
);
141 $contrib->amount
= 0;
142 $this->assertNull($contrib->amount
);
143 $contrib->amount
= 42;
144 $this->assertSame(42.0, $contrib->amount
);
145 $contrib->amount
= '42';
146 $this->assertSame(42.0, $contrib->amount
);
148 $contrib->type
= 156;
149 $this->assertInstanceOf('\Galette\Entity\ContributionsTypes', $contrib->type
);
150 $this->assertFalse($contrib->type
->id
);
152 $this->assertInstanceOf('\Galette\Entity\ContributionsTypes', $contrib->type
);
153 $this->assertEquals(1, $contrib->type
->id
);
155 $contrib->transaction
= 'not a transaction id';
156 $this->assertNull($contrib->transaction
);
157 $contrib->transaction
= 46;
158 $this->assertInstanceOf('\Galette\Entity\Transaction', $contrib->transaction
);
159 $this->assertNull($contrib->transaction
->id
);
161 $contrib->member
= 'not a member';
162 $this->assertNull($contrib->member
);
163 $contrib->member
= 118218;
164 $this->assertSame(118218, $contrib->member
);
166 $contrib->not_a_property
= 'abcde';
167 $this->assertFalse(property_exists($contrib, 'not_a_property'));
169 $contrib->payment_type
= \Galette\Entity\PaymentType
::CASH
;
170 $this->assertSame('Cash', $contrib->getPaymentType());
172 $contrib->payment_type
= \Galette\Entity\PaymentType
::CHECK
;
173 $this->assertSame('Check', $contrib->getPaymentType());
175 $contrib->payment_type
= \Galette\Entity\PaymentType
::OTHER
;
176 $this->assertSame('Other', $contrib->getPaymentType());
178 $contrib->payment_type
= \Galette\Entity\PaymentType
::CREDITCARD
;
179 $this->assertSame('Credit card', $contrib->getPaymentType());
181 $contrib->payment_type
= \Galette\Entity\PaymentType
::TRANSFER
;
182 $this->assertSame('Transfer', $contrib->getPaymentType());
184 $contrib->payment_type
= \Galette\Entity\PaymentType
::PAYPAL
;
185 $this->assertSame('Paypal', $contrib->getPaymentType());
189 * Test contribution creation
193 public function testCreation()
195 $this->getMemberOne();
196 //create contribution for member
197 $this->createContribution();
201 * Test donation update
205 public function testDonationUpdate()
207 $this->getMemberOne();
208 //create contribution for member
209 $begin_date = new \
DateTime(); // 2020-11-07
210 $begin_date->sub(new \
DateInterval('P5M')); // 2020-06-07
211 $begin_date->add(new \
DateInterval('P3D')); // 2020-06-10
213 $due_date = clone $begin_date;
214 $due_date->add(new \
DateInterval('P1Y'));
215 $due_date->sub(new \
DateInterval('P1D'));
218 'id_adh' => $this->adh
->id
,
219 'id_type_cotis' => 4, //donation
220 'montant_cotis' => 12,
221 'type_paiement_cotis' => 3,
222 'info_cotis' => 'FAKER' . $this->seed
,
223 'date_enreg' => $begin_date->format('Y-m-d'),
224 'date_debut_cotis' => $begin_date->format('Y-m-d'),
225 'date_fin_cotis' => $due_date->format('Y-m-d'),
227 $this->createContrib($data);
230 'id_type_cotis' => 1,
233 'date_debut_cotis' => 1,
234 'date_fin_cotis' => 0,
237 $this->contrib
->getRequired()
240 $this->logSuperAdmin();
242 'id_adh' => $this->adh
->id
,
243 'id_type_cotis' => 4, //donation
244 'montant_cotis' => 1280,
245 'type_paiement_cotis' => 4,
246 'info_cotis' => 'FAKER' . $this->seed
,
247 'date_enreg' => $begin_date->format('Y-m-d'),
248 'date_debut_cotis' => $begin_date->format('Y-m-d'),
249 'date_fin_cotis' => $due_date->format('Y-m-d'),
251 $this->createContrib($data);
253 $contrib = new \Galette\Entity\
Contribution($this->zdb
, $this->login
, $this->contrib
->id
);
254 $this->assertSame(1280.00, $contrib->amount
);
258 'id_adh' => $this->adh
->id
,
259 'id_type_cotis' => 4, //donation
260 'montant_cotis' => 0,
261 'type_paiement_cotis' => 4,
262 'info_cotis' => 'FAKER' . $this->seed
,
263 'date_enreg' => $begin_date->format('Y-m-d'),
264 'date_debut_cotis' => $begin_date->format('Y-m-d'),
265 'date_fin_cotis' => $due_date->format('Y-m-d'),
267 $this->createContrib($data);
269 $contrib = new \Galette\Entity\
Contribution($this->zdb
, $this->login
, $this->contrib
->id
);
270 $this->assertSame(0.00, $contrib->amount
);
274 * Test contribution update
278 public function testContributionUpdate()
280 $this->logSuperAdmin();
282 $this->getMemberOne();
283 //create contribution for member
284 $begin_date = new \
DateTime(); // 2020-11-07
285 $begin_date->sub(new \
DateInterval('P5M')); // 2020-06-07
286 $begin_date->add(new \
DateInterval('P3D')); // 2020-06-10
288 $due_date = clone $begin_date;
289 $due_date->add(new \
DateInterval('P1Y'));
290 $due_date->sub(new \
DateInterval('P1D'));
292 //instanciate contribution as annual fee
293 $this->contrib
= new \Galette\Entity\
Contribution(
297 'type' => 1 //annual fee
302 'id_type_cotis' => 1,
305 'date_debut_cotis' => 1,
306 'date_fin_cotis' => 1, //should be 1
307 'montant_cotis' => 1 // should be 1
309 $this->contrib
->getRequired()
313 'id_adh' => $this->adh
->id
,
314 'id_type_cotis' => 1, //annual fee
315 'montant_cotis' => 0,
316 'type_paiement_cotis' => 3,
317 'info_cotis' => 'FAKER' . $this->seed
,
318 'date_enreg' => $begin_date->format('Y-m-d'),
319 'date_debut_cotis' => $begin_date->format('Y-m-d'),
320 'date_fin_cotis' => $due_date->format('Y-m-d'),
323 $this->createContrib($data, $this->contrib
);
325 $this->assertSame(0.0, $this->contrib
->amount
);
326 $contrib = new \Galette\Entity\
Contribution($this->zdb
, $this->login
, $this->contrib
->id
);
327 $this->assertSame(0.0, $contrib->amount
);
330 $data['montant_cotis'] = 42;
331 $check = $contrib->check($data, [], []);
332 if (is_array($check)) {
335 $this->assertTrue($check);
337 $store = $contrib->store();
338 $this->assertTrue($store);
340 $contrib = new \Galette\Entity\
Contribution($this->zdb
, $this->login
, $this->contrib
->id
);
341 $this->assertSame(42.0, $contrib->amount
);
343 //change amount back to 0
344 $data['montant_cotis'] = 0;
345 $check = $contrib->check($data, [], []);
346 if (is_array($check)) {
349 $this->assertTrue($check);
351 $store = $contrib->store();
352 $this->assertTrue($store);
354 $contrib = new \Galette\Entity\
Contribution($this->zdb
, $this->login
, $this->contrib
->id
);
355 $this->assertSame(0.0, $contrib->amount
);
359 * Test end date retrieving
360 * This is based on some Preferences parameters
364 public function testRetrieveEndDate()
367 $orig_pref_beg_membership = $this->preferences
->pref_beg_membership
;
368 $orig_pref_membership_ext = $this->preferences
->pref_membership_ext
;
369 $orig_pref_membership_offermonths = $this->preferences
->pref_membership_offermonths
;
371 $contrib = new \Galette\Entity\
Contribution(
374 ['type' => 1] //annual fee
377 // First, check for 12 months renewal
378 $due_date = new \
DateTime();
379 $due_date->add(new \
DateInterval('P1Y'));
380 $due_date->sub(new \
DateInterval('P1D'));
381 $this->assertSame($due_date->format('Y-m-d'), $contrib->end_date
);
383 //unset pref_beg_membership and pref_membership_ext
384 $preferences->pref_beg_membership
= '';
385 $preferences->pref_membership_ext
= '';
387 $this->expectException('RuntimeException');
388 $this->expectExceptionMessage('Unable to define end date; none of pref_beg_membership nor pref_membership_ext are defined!');
389 $contrib = new \Galette\Entity\
Contribution(
392 ['type' => 1] //annual fee
395 // Second, test with beginning of membership date
396 $preferences->pref_beg_membership
= '29/05';
397 $due_date = new \
DateTime();
398 $due_date->setDate(date('Y'), 5, 28);
399 if ($due_date <= new \
DateTime()) {
400 $due_date->add(new \
DateInterval('P1Y'));
403 $contrib = new \Galette\Entity\
Contribution(
406 ['type' => 1] // annual fee
408 $this->assertSame($due_date->format('Y-m-d'), $contrib->end_date
);
410 // Third, test with beginning of membership date and 2 last months offered
411 $begin_date = new \
DateTime();
412 $begin_date->add(new \
DateInterval('P1M'));
413 $preferences->pref_beg_membership
= $begin_date->format('01/m');
414 $preferences->pref_membership_offermonths
= 2;
415 $due_date = new \
DateTime($begin_date->format('Y-m-01'));
416 $due_date->add(new \
DateInterval('P1Y'));
417 $due_date->sub(new \
DateInterval('P1D'));
419 $contrib = new \Galette\Entity\
Contribution(
422 ['type' => 1] // annual fee
424 $this->assertSame($due_date->format('Y-m-d'), $contrib->end_date
);
427 $preferences->pref_beg_membership
= $orig_pref_beg_membership;
428 $preferences->pref_membership_ext
= $orig_pref_membership_ext;
429 $preferences->pref_membership_offermonths
= $orig_pref_membership_offermonths;
433 * Test checkOverlap method
437 public function testCheckOverlap()
439 $adh = new \Galette\Entity\
Adherent($this->zdb
);
440 $adh->setDependencies(
442 $this->members_fields
,
446 $check = $adh->check(
448 'nom_adh' => 'Overlapped',
449 'date_crea_adh' => date(_T("Y-m-d")),
450 \Galette\Entity\Status
::PK
=> \Galette\Entity\Status
::DEFAULT_STATUS
,
451 'fingerprint' => 'FAKER' . $this->seed
456 if (is_array($check)) {
459 $this->assertTrue($check);
461 $store = $adh->store();
462 $this->assertTrue($store);
464 //create first contribution for member
465 $contrib = new \Galette\Entity\
Contribution($this->zdb
, $this->login
);
467 $now = new \
DateTime();
468 $due_date = clone $now;
469 $due_date->add(new \
DateInterval('P1Y'));
470 $due_date->sub(new \
DateInterval('P1D'));
472 \Galette\Entity\Adherent
::PK
=> $adh->id
,
473 \Galette\Entity\ContributionsTypes
::PK
=> 1, //annual fee
474 'montant_cotis' => 20,
475 'type_paiement_cotis' => \Galette\Entity\PaymentType
::CHECK
,
476 'date_enreg' => $now->format(_T("Y-m-d")),
477 'date_debut_cotis' => $now->format(_T("Y-m-d")),
478 'date_fin_cotis' => $due_date->format(_T("Y-m-d")),
479 'info_cotis' => 'FAKER' . $this->seed
482 $check = $contrib->check($data, [], []);
483 if (is_array($check)) {
486 $this->assertTrue($check);
487 $this->assertTrue($contrib->checkOverlap());
489 $store = $contrib->store();
490 $this->assertTrue($store);
492 //load member from db
493 $adh = new \Galette\Entity\
Adherent($this->zdb
, $adh->id
);
495 $contrib = new \Galette\Entity\
Contribution($this->zdb
, $this->login
);
496 $begin_date = clone $due_date;
497 $begin_date->add(new \
DateInterval('P1D'));
498 $begin_date->sub(new \
DateInterval('P3M'));
499 $due_date = clone $begin_date;
500 $due_date->add(new \
DateInterval('P1Y'));
501 $due_date->sub(new \
DateInterval('P1D'));
503 \Galette\Entity\Adherent
::PK
=> $adh->id
,
504 \Galette\Entity\ContributionsTypes
::PK
=> 1, //annual fee
505 'montant_cotis' => 20,
506 'type_paiement_cotis' => \Galette\Entity\PaymentType
::CHECK
,
507 'date_enreg' => $now->format(_T("Y-m-d")),
508 'date_debut_cotis' => $begin_date->format(_T("Y-m-d")),
509 'date_fin_cotis' => $due_date->format(_T("Y-m-d")),
510 'info_cotis' => 'FAKER' . $this->seed
513 $check = $contrib->check($data, [], []);
516 '- Membership period overlaps period starting at ' . $now->format('Y-m-d')
521 $this->expectException('RuntimeException');
522 $this->expectExceptionMessage('Existing errors prevents storing contribution');
523 $store = $contrib->store();
531 public function testGetFieldLabel()
535 $this->contrib
->getFieldLabel('montant_cotis')
539 'Date of contribution',
540 $this->contrib
->getFieldLabel('date_debut_cotis')
543 $this->contrib
->type
= 1;
545 'Start date of membership',
546 $this->contrib
->getFieldLabel('date_debut_cotis')
551 $this->contrib
->getFieldLabel('info_cotis')
556 * Test contribution loading
560 public function testLoad()
562 $this->login
= $this->getMockBuilder(\Galette\Core\Login
::class)
563 ->setConstructorArgs(array($this->zdb
, $this->i18n
))
564 ->onlyMethods(array('isLogged', 'isStaff', 'isAdmin'))
566 $this->login
->method('isLogged')->willReturn(true);
567 $this->login
->method('isStaff')->willReturn(true);
568 $this->login
->method('isAdmin')->willReturn(true);
570 $this->getMemberOne();
572 //create contribution for member
573 $this->createContribution();
575 $id = $this->contrib
->id
;
576 $contrib = new \Galette\Entity\
Contribution($this->zdb
, $this->login
);
578 $this->assertTrue($contrib->load((int)$id));
579 $this->checkContribExpected($contrib);
581 $this->assertFalse($contrib->load(1355522012));
585 * Test contribution removal
589 public function testRemove()
591 $this->getMemberOne();
592 $this->createContribution();
594 $this->assertTrue($this->contrib
->remove());
595 $this->assertFalse($this->contrib
->remove());
603 public function testCan()
605 $this->getMemberOne();
606 //create contribution for member
607 $this->createContribution();
608 $contrib = $this->contrib
;
610 $this->assertFalse($contrib->canShow($this->login
));
612 //Superadmin can fully change contributions
613 $this->logSuperAdmin();
615 $this->assertTrue($contrib->canShow($this->login
));
618 $this->login
->logOut();
619 $this->assertFalse($this->login
->isLogged());
621 //Member can fully change its own contributions
622 $mdata = $this->dataAdherentOne();
623 $this->assertTrue($this->login
->login($mdata['login_adh'], $mdata['mdp_adh']));
624 $this->assertTrue($this->login
->isLogged());
625 $this->assertFalse($this->login
->isAdmin());
626 $this->assertFalse($this->login
->isStaff());
628 $this->assertTrue($contrib->canShow($this->login
));
631 $this->login
->logOut();
632 $this->assertFalse($this->login
->isLogged());
634 //Another member has no access
635 $this->getMemberTwo();
636 $mdata = $this->dataAdherentTwo();
637 $this->assertTrue($this->login
->login($mdata['login_adh'], $mdata['mdp_adh']));
638 $this->assertTrue($this->login
->isLogged());
639 $this->assertFalse($this->login
->isAdmin());
640 $this->assertFalse($this->login
->isStaff());
642 $this->assertFalse($contrib->canShow($this->login
));
644 //parents can chow change children contributions
645 $this->getMemberOne();
646 $member = $this->adh
;
647 $mdata = $this->dataAdherentOne();
649 $login = $this->login
;
650 $this->logSuperAdmin();
654 'prenom_adh' => 'Johny',
655 'parent_id' => $member->id
,
657 'login_adh' => 'child.johny.doe',
658 'fingerprint' => 'FAKER' . $this->seed
660 $child = $this->createMember($child_data);
663 //contribution for child
664 $begin_date = new \
DateTime(); // 2020-11-07
665 $begin_date->sub(new \
DateInterval('P5M')); // 2020-06-07
666 $begin_date->add(new \
DateInterval('P3D')); // 2020-06-10
668 $due_date = clone $begin_date;
669 $due_date->add(new \
DateInterval('P1Y'));
670 $due_date->sub(new \
DateInterval('P1D'));
674 'id_type_cotis' => 1,
675 'montant_cotis' => 25,
676 'type_paiement_cotis' => 3,
677 'info_cotis' => 'FAKER' . $this->seed
,
678 'date_enreg' => $begin_date->format('Y-m-d'),
679 'date_debut_cotis' => $begin_date->format('Y-m-d'),
680 'date_fin_cotis' => $due_date->format('Y-m-d'),
682 $ccontrib = $this->createContrib($data);
684 $this->login
->logOut();
687 $child = new \Galette\Entity\
Adherent($this->zdb
);
688 $child->enableDep('parent');
689 $this->assertTrue($child->load($cid));
691 $this->assertSame($child_data['nom_adh'], $child->name
);
692 $this->assertInstanceOf('\Galette\Entity\Adherent', $child->parent
);
693 $this->assertSame($member->id
, $child->parent
->id
);
694 $this->assertTrue($this->login
->login($mdata['login_adh'], $mdata['mdp_adh']));
696 $mdata = $this->dataAdherentOne();
697 $this->assertTrue($this->login
->login($mdata['login_adh'], $mdata['mdp_adh']));
698 $this->assertTrue($this->login
->isLogged());
699 $this->assertFalse($this->login
->isAdmin());
700 $this->assertFalse($this->login
->isStaff());
702 $this->assertTrue($ccontrib->canShow($this->login
));
705 $this->login
->logOut();
706 $this->assertFalse($this->login
->isLogged());
710 * Test next year contribution
714 public function testNextYear()
716 $this->logSuperAdmin();
717 $this->getMemberOne();
719 //create contribution for member
720 $begin_date = new \
DateTime(); // 2023-12-30
721 $ny_begin_date = clone $begin_date; // 2023-12-30
722 $end_date = clone $begin_date;
723 $begin_date->sub(new \
DateInterval('P1Y')); // 2022-12-30
724 $end_date->sub(new \
DateInterval('P1D')); // 2023-12-29
727 'id_adh' => $this->adh
->id
,
728 'id_type_cotis' => 1, //contribution
729 'montant_cotis' => 100,
730 'type_paiement_cotis' => 3,
731 'info_cotis' => 'FAKER' . $this->seed
,
732 'date_enreg' => $begin_date->format('Y-m-d'),
733 'date_debut_cotis' => $begin_date->format('Y-m-d'),
734 'duree_mois_cotis' => 12
736 $this->createContrib($data);
738 $contrib = new \Galette\Entity\
Contribution($this->zdb
, $this->login
, $this->contrib
->id
);
739 $this->assertSame(100.00, $contrib->amount
);
740 $this->assertSame($end_date->format('Y-m-d'), $contrib->end_date
);
742 $contrib = new \Galette\Entity\
Contribution($this->zdb
, $this->login
, ['type' => 1, 'adh' => $this->adh
->id
]);
743 $this->assertSame($ny_begin_date->format('Y-m-d'), $contrib->begin_date
);
747 * Test next year contribution from a 0.9.x
751 public function testNextYearFrom096()
753 $this->logSuperAdmin();
754 $this->getMemberOne();
756 //create contribution for member
757 $begin_date = new \
DateTime(); // 2023-12-30
758 $ny_begin_date = clone $begin_date; // 2023-12-30
759 $end_date = clone $begin_date;
760 $due_date = clone $begin_date;
762 $begin_date->sub(new \
DateInterval('P1Y')); // 2022-12-30
764 $contrib = new \Galette\Entity\
Contribution($this->zdb
, $this->login
);
765 $insert = $this->zdb
->insert(\Galette\Entity\Contribution
::TABLE
);
768 'id_adh' => $this->adh
->id
,
769 'id_type_cotis' => 1, //contribution
770 'montant_cotis' => 100,
771 'type_paiement_cotis' => 3,
772 'info_cotis' => 'FAKER' . $this->seed
,
773 'date_enreg' => $begin_date->format('Y-m-d'),
774 'date_debut_cotis' => $begin_date->format('Y-m-d'),
775 'date_fin_cotis' => $due_date->format('Y-m-d')
778 $add = $this->zdb
->execute($insert);
779 $this->assertSame(1, $add->count());
780 $contribution_id = (int)($add->getGeneratedValue() ??
$this->zdb
->getLastGeneratedValue($contrib));
782 $update = $this->zdb
->update(\Galette\Entity\Adherent
::TABLE
);
784 array('date_echeance' => $due_date->format('Y-m-d'))
786 [\Galette\Entity\Adherent
::PK
=> $this->adh
->id
]
788 $this->zdb
->execute($update);
790 $contrib = new \Galette\Entity\
Contribution($this->zdb
, $this->login
, $contribution_id);
791 $this->assertSame(100.00, $contrib->amount
);
792 $this->assertSame($end_date->format('Y-m-d'), $contrib->end_date
);
794 $contrib = new \Galette\Entity\
Contribution($this->zdb
, $this->login
, ['type' => 1, 'adh' => $this->adh
->id
, 'payment_type' => 1]);
795 $this->assertSame($ny_begin_date->format('Y-m-d'), $contrib->begin_date
);
797 $check = $contrib->check(['type_paiement_cotis' => 1, 'montant_cotis' => 1, 'info_cotis' => 'FAKER' . $this->seed
], [], []);
798 if (is_array($check)) {
801 $this->assertTrue($check);
803 $store = $contrib->store();
804 $this->assertTrue($store);