fix bugs in accompanying periods

ref #11
This commit is contained in:
2016-05-17 10:02:45 +02:00
parent 8b98e8a4b6
commit ce7c149c35
12 changed files with 355 additions and 77 deletions

View File

@@ -26,6 +26,7 @@ namespace Chill\PersonBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\Person;
use Doctrine\Common\Collections\Criteria;
/**
* Test the creation or deletion of accompanying periods
@@ -461,4 +462,65 @@ class AccompanyingPeriodControllerTest extends WebTestCase
$this->assertGreaterThan(0, $crawlerResponse->filter('.error')->count(),
"an 'error' element is shown");
}
/**
* @group reopening
*/
public function testReOpeningPeriod()
{
// test that re-opening a period which is opened does not work
$this->client->request('GET',
sprintf(
'/fr/person/%d/accompanying-period/%d/re-open',
$this->person->getId(),
$this->person->getOpenedAccompanyingPeriod()->getId()
)
);
$this->assertEquals(400, $this->client->getResponse()->getStatusCode(),
"Test an error is returned on a period which cannot be reopened");
// close the current period
$period = $this->person->getOpenedAccompanyingPeriod();
$period->setClosingDate(new \DateTime('2015-02-05'));
$this->person->close($period);
$this->generatePeriods(array(
[
'openingDate' => '2014-01-01',
'closingDate' => '2014-12-31',
'closingMotive' => $this->getRandomClosingMotive()
]
));
$periods = $this->person->getAccompanyingPeriodsOrdered();
/* @var $criteria Criteria */
$criteria = Criteria::create();
//$criteria->where(Criteria::expr()->eq('openingDate', \DateTime::createFromFormat()))
$firstPeriod = reset($periods);
$lastPeriod = end($periods);
// test that it is not possible to open the first period in the list
$this->client->request('GET',
sprintf('/fr/person/%d/accompanying-period/%d/re-open', $this->person->getId(), reset($periods)->getId())
);
$this->assertEquals(400, $this->client->getResponse()->getStatusCode(),
"Test an error is returned on the first period in the list");
// test that re-opening the last closed period works
$crawler = $this->client->request('GET',
sprintf('/fr/person/%d/accompanying-period/%d/re-open', $this->person->getId(), end($periods)->getId())
);
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$links = $crawler->selectLink('Confirmer');
$this->assertEquals(1, $links->count(), "test the link 'confirmer' is present");
$this->client->click($links->link());
$this->assertTrue($this->client->getResponse()->isRedirect(),
"Test the response is a redirection => the period is re-opened");
}
}

View File

@@ -23,79 +23,76 @@
namespace Chill\PersonBundle\Tests\Entity;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\Person;
class AccompanyingPeriodTest extends \PHPUnit_Framework_TestCase
{
public function testClosingIsAfterOpeningConsistency()
{
$datetime1 = new \DateTime('now');
$datetime2 = new \DateTime('tomorrow');
$period = new AccompanyingPeriod($datetime1);
$period->setClosingDate($datetime2);
$r = $period->isClosingAfterOpening();
$this->assertTrue($r);
}
public function testClosingIsBeforeOpeningConsistency() {
public function testClosingIsBeforeOpeningConsistency()
{
$datetime1 = new \DateTime('tomorrow');
$datetime2 = new \DateTime('now');
$period = new AccompanyingPeriod($datetime1);
$period->setClosingDate($datetime2);
$this->assertFalse($period->isClosingAfterOpening());
}
public function testClosingEqualOpening() {
public function testClosingEqualOpening()
{
$datetime = new \DateTime('now');
$period = new AccompanyingPeriod($datetime);
$period->setClosingDate($datetime);
$this->assertTrue($period->isClosingAfterOpening());
}
public function testIsOpen() {
public function testIsOpen()
{
$period = new AccompanyingPeriod(new \DateTime());
$this->assertTrue($period->isOpen());
}
public function testIsClosed() {
public function testIsClosed()
{
$period = new AccompanyingPeriod(new \DateTime());
$period->setClosingDate(new \DateTime('tomorrow'));
$this->assertFalse($period->isOpen());
}
/**
* This test seems only to test ordering datetime... Maybe delete ?
*/
public function testOrder() {
$d = new \DateTime(); $d->setDate(2013, 2, 1);
$g = new \DateTime(); $g->setDate(2013, 4, 1);
$f = new \DateTime(); $f->setDate(2013, 1, 1);
$e = new \DateTime(); $e->setDate(2013,3,1);
public function testCanBeReOpened()
{
$person = new Person(\DateTime::createFromFormat('Y-m-d', '2010-01-01'));
$person->close($person->getAccompanyingPeriods()[0]
->setClosingDate(\DateTime::createFromFormat('Y-m-d', '2010-12-31')));
$a = array($d, $g, $f, $e);
$firstAccompanygingPeriod = $person->getAccompanyingPeriodsOrdered()[0];
usort($a, function($a, $b) {
if ($a === $b) {
return 0;
}
if ($a < $b) {
return -1;
} else {
return 1;
}
});
$this->assertTrue($firstAccompanygingPeriod->canBeReOpened());
$date = $a[0]->format('Y-m-d');
$lastAccompanyingPeriod = (new AccompanyingPeriod(\DateTime::createFromFormat('Y-m-d', '2011-01-01')))
->setClosingDate(\DateTime::createFromFormat('Y-m-d', '2011-12-31'))
;
$person->addAccompanyingPeriod($lastAccompanyingPeriod);
$this->assertEquals($date, '2013-01-01');
$this->assertFalse($firstAccompanygingPeriod->canBeReOpened());
}
}
}

View File

@@ -50,10 +50,10 @@ class TimelineAccompanyingPeriodTest extends \Chill\PersonBundle\Tests\Controlle
"the timeline page loads sucessfully");
$this->assertGreaterThan(0, $crawler->filter('.timeline div')->count(),
"the timeline page contains multiple div inside a .timeline element");
$this->assertContains("Une période d'accompagnement a été ouverte",
$this->assertContains("Ouverture d'une période d'accompagnement",
$crawler->filter('.timeline')->text(),
"the text 'une période d'accompagnement a été ouverte' is present");
$this->assertContains("Une période d'accompagnement a été fermée",
$this->assertContains("Fermeture de la période d'accompagnement",
$crawler->Filter('.timeline')->text(),
"the text 'Une période d'accompagnement a été fermée' is present");
}