$reminders = new \Galette\Repository\Reminders();
$this->array($reminders->getList($this->zdb))->isIdenticalTo([]);
- //create members
+ //create member
$this->createAdherent();
$id = current($this->ids);
- //create contributions
- $this->createContribution();
+ //create contribution, just about to be impending
+ $now = new \DateTime();
+ $date_begin = clone $now;
+ $date_begin->sub(new \DateInterval('P1Y'));
+ $date_begin->add(new \DateInterval('P1M'));
+ $date_end = clone $date_begin;
+ $date_end->add(new \DateInterval('P1Y'));
+
+ $this->createContrib([
+ 'id_adh' => $id,
+ 'id_type_cotis' => 3,
+ 'montant_cotis' => '111',
+ 'type_paiement_cotis' => '6',
+ 'info_cotis' => 'FAKER' . $this->seed,
+ 'date_fin_cotis' => $date_end->format('Y-m-d'),
+ 'date_enreg' => $now->format('Y-m-d'),
+ 'date_debut_cotis' => $now->format('Y-m-d')
+ ]);
$cid = current($this->contribs_ids);
$adh = $this->adh;
$this->boolean($adh->load($id))->isTrue();
- //member is late
- $this->boolean($adh->isUp2Date())->isFalse();
- $rlist = $reminders->getList($this->zdb);
- $this->array($rlist)->hasSize(1);
- $reminder = current($rlist);
+ //member is up to date, no reminder to send
+ $this->boolean($this->adh->isUp2Date())->isTrue();
+ $this->array($reminders->getList($this->zdb))->isIdenticalTo([]);
- $this->integer($reminder->member_id)->isIdenticalTo($id);
- $this->integer($reminder->type)->isIdenticalTo(\Galette\Entity\Reminder::LATE);
- $this->variable($reminder->date)->isNull();
- $this->variable($reminder->getMessage())->isNull();
- $this->boolean($reminder->isSuccess())->isFalse();
- $this->boolean($reminder->hasMail())->isTrue();
+ //create contribution, just impending
+ $date_begin = clone $now;
+ $date_begin->sub(new \DateInterval('P1Y'));
+ $date_begin->add(new \DateInterval('P1M'));
+ $date_begin->sub(new \DateInterval('P1D'));
+ $date_end = clone $date_begin;
+ $date_end->add(new \DateInterval('P1Y'));
- $this->array($ireminders->getList($this->zdb))->isIdenticalTo([]);
- $this->array($lreminders->getList($this->zdb))->isEqualTo($rlist);
+ $this->createContrib([
+ 'id_adh' => $id,
+ 'id_type_cotis' => 3,
+ 'montant_cotis' => '111',
+ 'type_paiement_cotis' => '6',
+ 'info_cotis' => 'FAKER' . $this->seed,
+ 'date_fin_cotis' => $date_end->format('Y-m-d'),
+ 'date_enreg' => $now->format('Y-m-d'),
+ 'date_debut_cotis' => $now->format('Y-m-d')
+ ]);
+ $cid = current($this->contribs_ids);
- //create already sent impending reminder 2 months ago
- $now = new \DateTime();
+ $adh = $this->adh;
+ $this->boolean($adh->load($id))->isTrue();
+
+ //member is up to date, there is one impending reminder to send
+ $this->boolean($this->adh->isUp2Date())->isTrue();
+ $this->array($reminders->getList($this->zdb))->hasSize(1);
+ $this->array($lreminders->getList($this->zdb))->hasSize(0);
+ $this->array($ireminders->getList($this->zdb))->hasSize(1);
+
+ //create contribution, just impending less than 7 days
+ $date_begin = clone $now;
+ $date_begin->sub(new \DateInterval('P1Y'));
+ $date_begin->add(new \DateInterval('P4D'));
+ $date_end = clone $date_begin;
+ $date_end->add(new \DateInterval('P1Y'));
+
+ $this->createContrib([
+ 'id_adh' => $id,
+ 'id_type_cotis' => 3,
+ 'montant_cotis' => '111',
+ 'type_paiement_cotis' => '6',
+ 'info_cotis' => 'FAKER' . $this->seed,
+ 'date_fin_cotis' => $date_end->format('Y-m-d'),
+ 'date_enreg' => $now->format('Y-m-d'),
+ 'date_debut_cotis' => $now->format('Y-m-d')
+ ]);
+ $cid = current($this->contribs_ids);
+
+ $adh = $this->adh;
+ $this->boolean($adh->load($id))->isTrue();
+
+ //member is up to date, there is one impending reminder to send
+ $this->boolean($this->adh->isUp2Date())->isTrue();
+ $this->array($reminders->getList($this->zdb))->hasSize(1);
+ $this->array($lreminders->getList($this->zdb))->hasSize(0);
+ $this->array($ireminders->getList($this->zdb))->hasSize(1);
+
+ //add a sent first impending reminder
+ $send = clone $now;
+ $send->sub(new \DateInterval('P1M'));
+ $data = array(
+ 'reminder_type' => \Galette\Entity\Reminder::IMPENDING,
+ 'reminder_dest' => $id,
+ 'reminder_date' => $send->format('Y-m-d'),
+ 'reminder_success' => true,
+ 'reminder_nomail' => ($this->zdb->isPostgres() ? 'false' : 0)
+ );
+
+ $insert = $this->zdb->insert(\Galette\Entity\Reminder::TABLE);
+ $insert->values($data);
+
+ $add = $this->zdb->execute($insert);
+ $this->integer($add->count())->isGreaterThan(0);
+
+ //there is still one reminder to send
+ $this->boolean($this->adh->isUp2Date())->isTrue();
+ $this->array($reminders->getList($this->zdb))->hasSize(1);
+ $this->array($lreminders->getList($this->zdb))->hasSize(0);
+ $this->array($ireminders->getList($this->zdb))->hasSize(1);
+
+ //add a sent second impending reminder, yesterday
$send = clone $now;
- $send->sub(new \DateInterval('P2M'));
+ $send->sub(new \DateInterval('P1D'));
$data = array(
'reminder_type' => \Galette\Entity\Reminder::IMPENDING,
'reminder_dest' => $id,
$add = $this->zdb->execute($insert);
$this->integer($add->count())->isGreaterThan(0);
- $rlist = $reminders->getList($this->zdb);
- $this->array($rlist)->hasSize(1);
- $reminder = current($rlist);
+ //nothing to send!
+ $this->boolean($this->adh->isUp2Date())->isTrue();
+ $this->array($reminders->getList($this->zdb))->hasSize(0);
+ $this->array($lreminders->getList($this->zdb))->hasSize(0);
+ $this->array($ireminders->getList($this->zdb))->hasSize(0);
+
+ //create contribution, expiration day
+ $now = new \DateTime();
+ $date_begin = clone $now;
+ $date_begin->sub(new \DateInterval('P1Y'));
+ $date_end = clone $date_begin;
+ $date_end->add(new \DateInterval('P1Y'));
+
+ $this->createContrib([
+ 'id_adh' => $id,
+ 'id_type_cotis' => 3,
+ 'montant_cotis' => '111',
+ 'type_paiement_cotis' => '6',
+ 'info_cotis' => 'FAKER' . $this->seed,
+ 'date_fin_cotis' => $date_end->format('Y-m-d'),
+ 'date_enreg' => $now->format('Y-m-d'),
+ 'date_debut_cotis' => $now->format('Y-m-d')
+ ]);
+ $cid = current($this->contribs_ids);
+
+ $adh = $this->adh;
+ $this->boolean($adh->load($id))->isTrue();
+
+ //member is up to date, no reminder to send
+ $this->boolean($this->adh->isUp2Date())->isTrue();
+ $this->array($reminders->getList($this->zdb))->isIdenticalTo([]);
+
+ //create contribution, just late
+ $now = new \DateTime();
+ $date_begin = clone $now;
+ $date_begin->sub(new \DateInterval('P1Y'));
+ $date_begin->sub(new \DateInterval('P1D'));
+ $date_end = clone $date_begin;
+ $date_end->add(new \DateInterval('P1Y'));
+
+ $this->createContrib([
+ 'id_adh' => $id,
+ 'id_type_cotis' => 3,
+ 'montant_cotis' => '111',
+ 'type_paiement_cotis' => '6',
+ 'info_cotis' => 'FAKER' . $this->seed,
+ 'date_fin_cotis' => $date_end->format('Y-m-d'),
+ 'date_enreg' => $now->format('Y-m-d'),
+ 'date_debut_cotis' => $now->format('Y-m-d')
+ ]);
+ $cid = current($this->contribs_ids);
+
+ $adh = $this->adh;
+ $this->boolean($adh->load($id))->isTrue();
+
+ //member is not up to date, but less than one month, no reminder to send
+ $this->boolean($this->adh->isUp2Date())->isFalse();
+ $this->array($reminders->getList($this->zdb))->hasSize(0);
+ $this->array($lreminders->getList($this->zdb))->hasSize(0);
+ $this->array($ireminders->getList($this->zdb))->hasSize(0);
+
+ //create contribution, late by 30 days
+ $now = new \DateTime();
+ $date_begin = clone $now;
+ $date_begin->sub(new \DateInterval('P1Y'));
+ $date_begin->sub(new \DateInterval('P30D'));
+ $date_end = clone $date_begin;
+ $date_end->add(new \DateInterval('P1Y'));
- $this->integer($reminder->member_id)->isIdenticalTo($id);
- $this->integer($reminder->type)->isIdenticalTo(\Galette\Entity\Reminder::LATE);
- $this->variable($reminder->date)->isNull();
- $this->variable($reminder->getMessage())->isNull();
- $this->boolean($reminder->isSuccess())->isFalse();
- $this->boolean($reminder->hasMail())->isTrue();
+ $this->createContrib([
+ 'id_adh' => $id,
+ 'id_type_cotis' => 3,
+ 'montant_cotis' => '111',
+ 'type_paiement_cotis' => '6',
+ 'info_cotis' => 'FAKER' . $this->seed,
+ 'date_fin_cotis' => $date_end->format('Y-m-d'),
+ 'date_enreg' => $now->format('Y-m-d'),
+ 'date_debut_cotis' => $now->format('Y-m-d')
+ ]);
+ $cid = current($this->contribs_ids);
- //create already sent laste reminder 2 days ago
+ $adh = $this->adh;
+ $this->boolean($adh->load($id))->isTrue();
+
+ //member is not up to date, but less than one month, no reminder to send
+ $this->boolean($this->adh->isUp2Date())->isFalse();
+ $this->array($reminders->getList($this->zdb))->hasSize(0);
+ $this->array($lreminders->getList($this->zdb))->hasSize(0);
+ $this->array($ireminders->getList($this->zdb))->hasSize(0);
+
+ //create contribution, late by 31 days
+ $now = new \DateTime();
+ $date_begin = clone $now;
+ $date_begin->sub(new \DateInterval('P1Y'));
+ $date_begin->sub(new \DateInterval('P31D'));
+ $date_end = clone $date_begin;
+ $date_end->add(new \DateInterval('P1Y'));
+
+ $this->createContrib([
+ 'id_adh' => $id,
+ 'id_type_cotis' => 3,
+ 'montant_cotis' => '111',
+ 'type_paiement_cotis' => '6',
+ 'info_cotis' => 'FAKER' . $this->seed,
+ 'date_fin_cotis' => $date_end->format('Y-m-d'),
+ 'date_enreg' => $now->format('Y-m-d'),
+ 'date_debut_cotis' => $now->format('Y-m-d')
+ ]);
+ $cid = current($this->contribs_ids);
+
+ $adh = $this->adh;
+ $this->boolean($adh->load($id))->isTrue();
+
+ //member is not up to date for one month, one late reminder to send
+ $this->boolean($this->adh->isUp2Date())->isFalse();
+ $this->array($reminders->getList($this->zdb))->hasSize(1);
+ $this->array($lreminders->getList($this->zdb))->hasSize(1);
+ $this->array($ireminders->getList($this->zdb))->hasSize(0);
+
+ //create contribution, late by 40 days
+ $now = new \DateTime();
+ $date_begin = clone $now;
+ $date_begin->sub(new \DateInterval('P1Y'));
+ $date_begin->sub(new \DateInterval('P40D'));
+ $date_end = clone $date_begin;
+ $date_end->add(new \DateInterval('P1Y'));
+
+ $this->createContrib([
+ 'id_adh' => $id,
+ 'id_type_cotis' => 3,
+ 'montant_cotis' => '111',
+ 'type_paiement_cotis' => '6',
+ 'info_cotis' => 'FAKER' . $this->seed,
+ 'date_fin_cotis' => $date_end->format('Y-m-d'),
+ 'date_enreg' => $now->format('Y-m-d'),
+ 'date_debut_cotis' => $now->format('Y-m-d')
+ ]);
+ $cid = current($this->contribs_ids);
+
+ $adh = $this->adh;
+ $this->boolean($adh->load($id))->isTrue();
+
+ //member is not up to date for one month, one late reminder to send
+ $this->boolean($this->adh->isUp2Date())->isFalse();
+ $this->array($reminders->getList($this->zdb))->hasSize(1);
+ $this->array($lreminders->getList($this->zdb))->hasSize(1);
+ $this->array($ireminders->getList($this->zdb))->hasSize(0);
+
+ //add a sent late reminder, at it should have been
$send = clone $now;
- $send->sub(new \DateInterval('P2D'));
+ $send->sub(new \DateInterval('P5D'));
$data = array(
'reminder_type' => \Galette\Entity\Reminder::LATE,
'reminder_dest' => $id,
$add = $this->zdb->execute($insert);
$this->integer($add->count())->isGreaterThan(0);
- $rlist = $reminders->getList($this->zdb);
- $this->array($rlist)->isIdenticalTo([]);
+ //nothing to send!
+ $this->boolean($this->adh->isUp2Date())->isFalse();
+ $this->array($reminders->getList($this->zdb))->hasSize(0);
+ $this->array($lreminders->getList($this->zdb))->hasSize(0);
+ $this->array($ireminders->getList($this->zdb))->hasSize(0);
+
+ //create contribution, late by 2 months
+ $now = new \DateTime();
+ $date_begin = clone $now;
+ $date_begin->sub(new \DateInterval('P1Y'));
+ $date_begin->sub(new \DateInterval('P2M'));
+ $date_end = clone $date_begin;
+ $date_end->add(new \DateInterval('P1Y'));
+
+ $this->createContrib([
+ 'id_adh' => $id,
+ 'id_type_cotis' => 3,
+ 'montant_cotis' => '111',
+ 'type_paiement_cotis' => '6',
+ 'info_cotis' => 'FAKER' . $this->seed,
+ 'date_fin_cotis' => $date_end->format('Y-m-d'),
+ 'date_enreg' => $now->format('Y-m-d'),
+ 'date_debut_cotis' => $now->format('Y-m-d')
+ ]);
+ $cid = current($this->contribs_ids);
+
+ $adh = $this->adh;
+ $this->boolean($adh->load($id))->isTrue();
+
+ //member is not up to date for one month, one late reminder to send
+ $this->boolean($this->adh->isUp2Date())->isFalse();
+ $this->array($reminders->getList($this->zdb))->hasSize(1);
+ $this->array($lreminders->getList($this->zdb))->hasSize(1);
+ $this->array($ireminders->getList($this->zdb))->hasSize(0);
}
/**
$this->string($adh->getRowClass())->isIdenticalTo('active cotis-never');
}
- /**
- * Create test contribution in database
- *
- * @return void
- */
- private function createContribution()
- {
- $fakedata = new \Galette\Util\FakeData($this->zdb, $this->i18n);
- $fakedata
- ->setSeed($this->seed)
- ->setDependencies(
- $this->preferences,
- $this->members_fields,
- $this->history,
- $this->login
- );
-
- $data = $fakedata->fakeContrib($this->adh->id);
- $this->createContrib($data);
- $this->checkContribExpected();
- }
-
/**
* Create contribution from data
*
$this->boolean($check)->isTrue();
$store = $contrib->store();
- $this->boolean($store)->isTrue();
+ $this->boolean($store)->isTrue($store);
$this->contribs_ids[] = (int)$contrib->id;
}
-
- /**
- * Check contributions expecteds
- *
- * @param Contribution $contrib Contribution instance, if any
- * @param array $new_expecteds Changes on expected values
- *
- * @return void
- */
- private function checkContribExpected($contrib = null, $new_expecteds = [])
- {
- if ($contrib === null) {
- $contrib = $this->contrib;
- }
-
- $date_begin = $contrib->raw_begin_date;
- $date_end = clone $date_begin;
- $date_end->add(new \DateInterval('P1Y'));
-
- $this->object($contrib->raw_date)->isInstanceOf('DateTime');
- $this->object($contrib->raw_begin_date)->isInstanceOf('DateTime');
- $this->object($contrib->raw_end_date)->isInstanceOf('DateTime');
-
- $expecteds = [
- 'id_adh' => "{$this->adh->id}",
- 'id_type_cotis' => 3,
- 'montant_cotis' => '111',
- 'type_paiement_cotis' => '6',
- 'info_cotis' => 'FAKER' . $this->seed,
- 'date_fin_cotis' => $date_end->format('Y-m-d')
- ];
- $expecteds = array_merge($expecteds, $new_expecteds);
-
- $this->string($contrib->raw_end_date->format('Y-m-d'))->isIdenticalTo($expecteds['date_fin_cotis']);
-
- foreach ($expecteds as $key => $value) {
- $property = $this->contrib->fields[$key]['propname'];
- switch ($key) {
- case \Galette\Entity\ContributionsTypes::PK:
- $ct = $this->contrib->type;
- if ($ct instanceof \Galette\Entity\ContributionsTypes) {
- $this->integer((int)$ct->id)->isIdenticalTo($value);
- } else {
- $this->integer($ct)->isIdenticalTo($value);
- }
- break;
- default:
- $this->variable($contrib->$property)->isEqualTo($value, $property);
- break;
- }
- }
-
- //load member from db
- $this->adh = new \Galette\Entity\Adherent($this->zdb, $this->adh->id);
- //member is now up-to-date
- $this->string($this->adh->getRowClass())->isIdenticalTo('active cotis-late');
- $this->string($this->adh->due_date)->isIdenticalTo($this->contrib->end_date);
- $this->boolean($this->adh->isUp2Date())->isFalse();
- }
}