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");
}
}