}
/**
- * Test contribution update
+ * Test donation update
*
* @return void
*/
- public function testUpdate()
+ public function testDonationUpdate()
{
$this->getMemberOne();
//create contribution for member
$this->assertSame(0.00, $contrib->amount);
}
+ /**
+ * Test contribution update
+ *
+ * @return void
+ */
+ public function testContributionUpdate()
+ {
+ $this->logSuperAdmin();
+
+ $this->getMemberOne();
+ //create contribution for member
+ $begin_date = new \DateTime(); // 2020-11-07
+ $begin_date->sub(new \DateInterval('P5M')); // 2020-06-07
+ $begin_date->add(new \DateInterval('P3D')); // 2020-06-10
+
+ $due_date = clone $begin_date;
+ $due_date->add(new \DateInterval('P1Y'));
+ $due_date->sub(new \DateInterval('P1D'));
+
+ //instanciate contribution as annual fee
+ $this->contrib = new \Galette\Entity\Contribution(
+ $this->zdb,
+ $this->login,
+ [
+ 'type' => 1 //annual fee
+ ]
+ );
+ $this->assertSame(
+ [
+ 'id_type_cotis' => 1,
+ 'id_adh' => 1,
+ 'date_enreg' => 1,
+ 'date_debut_cotis' => 1,
+ 'date_fin_cotis' => 1, //should be 1
+ 'montant_cotis' => 1 // should be 1
+ ],
+ $this->contrib->getRequired()
+ );
+
+ $data = [
+ 'id_adh' => $this->adh->id,
+ 'id_type_cotis' => 1, //annual fee
+ 'montant_cotis' => 0,
+ 'type_paiement_cotis' => 3,
+ 'info_cotis' => 'FAKER' . $this->seed,
+ 'date_enreg' => $begin_date->format('Y-m-d'),
+ 'date_debut_cotis' => $begin_date->format('Y-m-d'),
+ 'date_fin_cotis' => $due_date->format('Y-m-d'),
+ ];
+
+ $this->createContrib($data, $this->contrib);
+
+ $this->assertSame(0.0, $this->contrib->amount);
+ $contrib = new \Galette\Entity\Contribution($this->zdb, $this->login, $this->contrib->id);
+ $this->assertSame(0.0, $contrib->amount);
+
+ //change amount
+ $data['montant_cotis'] = 42;
+ $check = $contrib->check($data, [], []);
+ if (is_array($check)) {
+ var_dump($check);
+ }
+ $this->assertTrue($check);
+
+ $store = $contrib->store();
+ $this->assertTrue($store);
+
+ $contrib = new \Galette\Entity\Contribution($this->zdb, $this->login, $this->contrib->id);
+ $this->assertSame(42.0, $contrib->amount);
+
+ //change amount back to 0
+ $data['montant_cotis'] = 0;
+ $check = $contrib->check($data, [], []);
+ if (is_array($check)) {
+ var_dump($check);
+ }
+ $this->assertTrue($check);
+
+ $store = $contrib->store();
+ $this->assertTrue($store);
+
+ $contrib = new \Galette\Entity\Contribution($this->zdb, $this->login, $this->contrib->id);
+ $this->assertSame(0.0, $contrib->amount);
+ }
+
/**
* Test end date retrieving
* This is based on some Preferences parameters
/**
* Create contribution from data
*
- * @param array $data Data to use to create contribution
+ * @param array $data Data to use to create contribution
+ * @param ?\Galette\Entity\Contribution $contrib Contribution instance, if any
*
* @return \Galette\Entity\Contribution
*/
- public function createContrib(array $data)
+ public function createContrib(array $data, \Galette\Entity\Contribution $contrib = null)
{
- $this->contrib = new \Galette\Entity\Contribution($this->zdb, $this->login);
- $contrib = $this->contrib;
+ if ($contrib === null) {
+ $this->contrib = new \Galette\Entity\Contribution($this->zdb, $this->login);
+ $contrib = $this->contrib;
+ }
+
$check = $contrib->check($data, [], []);
if (is_array($check)) {
var_dump($check);