mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
add tests for closing/opening accompanying periods
refs #274 check : - closing the current period works - closing a period with date closing AFTER the opening fails - creating a new period works - create a period with closing after current (opened) period fails => fails see refs #410 - create a period with opening and closing after current (opened) period fails => fails see refs #410 - create a period with end date between another fails - create a period with end date after opening date fails - create a period between another period (date closing and date opening) fails - create a period with date opening inside another period fails
This commit is contained in:
parent
7ebaafe768
commit
69042c683f
@ -75,29 +75,23 @@ class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
->setGenre(Person::GENRE_MAN)
|
||||
;
|
||||
|
||||
//remove Accompanying periods
|
||||
$this->person->close($this->person->getCurrentHistory()
|
||||
->setDateClosing(new \DateTime('2015-01-05')));
|
||||
foreach($this->person->getHistories() as $accompanyingPeriod) {
|
||||
$this->person->removeHistoryFile($accompanyingPeriod);
|
||||
}
|
||||
static::$em->persist($this->person);
|
||||
static::$em->flush();
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
//static::$em->refresh($this->person);
|
||||
//static::$em->remove($this->person);
|
||||
static::$em->refresh($this->person);
|
||||
static::$em->remove($this->person);
|
||||
|
||||
//static::$em->flush();
|
||||
static::$em->flush();
|
||||
}
|
||||
|
||||
private function generatePeriods(array $periods)
|
||||
{
|
||||
foreach ($periods as $periodDef) {
|
||||
$period = new AccompanyingPeriod(new \DateTime($periodDef['openingDate']));
|
||||
var_dump((new \DateTime($periodDef['openingDate']))->format('d-m-Y'));
|
||||
|
||||
if (array_key_exists('closingDate', $periodDef)) {
|
||||
if (!array_key_exists('closingMotive', $periodDef)) {
|
||||
throw new \LogicalException('you must define a closing '
|
||||
@ -123,6 +117,14 @@ class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
->availableOptionValues());
|
||||
}
|
||||
|
||||
private function getRandomClosingMotive()
|
||||
{
|
||||
$motives = static::$em
|
||||
->getRepository('ChillPersonBundle:AccompanyingPeriod\ClosingMotive')
|
||||
->findAll();
|
||||
return end($motives);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the closing of a periods
|
||||
*
|
||||
@ -137,13 +139,6 @@ class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
*/
|
||||
public function testClosingCurrentPeriod()
|
||||
{
|
||||
|
||||
$this->markTestSkipped('not implemented fully');
|
||||
|
||||
$this->generatePeriods(array( [
|
||||
'openingDate' => '2015-01-05'
|
||||
]
|
||||
));
|
||||
|
||||
$crawler = $this->client->request('GET', '/en/person/'
|
||||
.$this->person->getId().'/history/close');
|
||||
@ -154,25 +149,63 @@ class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
->setValue($this->getLastValueOnClosingMotive($form));
|
||||
$form->get(self::CLOSING_INPUT)
|
||||
->setValue((new \DateTime('2015-02-01'))->format('d-m-Y'));
|
||||
var_dump((new \DateTime('2015-02-01'))->format('d-m-Y'));
|
||||
|
||||
$cr = $this->client->submit($form);
|
||||
var_dump($cr->text());
|
||||
|
||||
$this->assertTrue($this->client->getResponse()->isRedirect(
|
||||
'/en/person/'.$this->person->getId().'/history'),
|
||||
'the server redirects to /history page');
|
||||
$this->assertGreaterThan(0, $this->client->followRedirect()
|
||||
->filter('.success')->count(),
|
||||
"a 'success' message is shown");
|
||||
->filter('.success')->count(),
|
||||
"a 'success' element is shown");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the closing of a periods
|
||||
*
|
||||
* Given that a person as an accompanying period opened since 2015-01-05
|
||||
* and we fill the close form (at /en/person/[id]/history/close
|
||||
* with : dateClosing: 2014-01-01
|
||||
* with : the last closing motive in list
|
||||
* Then the response should redirect to history view
|
||||
* And the next page should have a `.error` element present in page
|
||||
*
|
||||
* @todo
|
||||
*/
|
||||
public function testClosingCurrentPeriodWithDateClosingBeforeOpeningFails()
|
||||
{
|
||||
|
||||
$crawler = $this->client->request('GET', '/en/person/'
|
||||
.$this->person->getId().'/history/close');
|
||||
|
||||
$form = $crawler->selectButton('Submit')->form();
|
||||
|
||||
$form->get(self::CLOSING_MOTIVE_INPUT)
|
||||
->setValue($this->getLastValueOnClosingMotive($form));
|
||||
$form->get(self::CLOSING_INPUT)
|
||||
->setValue((new \DateTime('2014-01-01'))->format('d-m-Y'));
|
||||
|
||||
$crawlerResponse = $this->client->submit($form);
|
||||
|
||||
$this->assertFalse($this->client->getResponse()->isRedirect(),
|
||||
'the server stays on the /close page');
|
||||
$this->assertGreaterThan(0, $crawlerResponse
|
||||
->filter('.error')->count(),
|
||||
"an '.error' element is shown");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the creation of a new period
|
||||
*
|
||||
* Given that a person as an accompanying period opened since 2015-01-05
|
||||
* and we create a new period
|
||||
* with : dateClosing: 2014-12-31
|
||||
* with : dateOpening: 2014-01-01
|
||||
* with : the last closing motive in list
|
||||
* Then the response should redirect to history view
|
||||
*/
|
||||
public function testAddNewPeriodBeforeActual()
|
||||
{
|
||||
$this->generatePeriods(array(
|
||||
[
|
||||
'openingDate' => '2015-01-25'
|
||||
]
|
||||
));
|
||||
|
||||
$crawler = $this->client->request('GET', '/en/person/'
|
||||
.$this->person->getId().'/history/create');
|
||||
@ -192,6 +225,239 @@ class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
'the server redirects to /history page');
|
||||
$this->assertGreaterThan(0, $this->client->followRedirect()
|
||||
->filter('.success')->count(),
|
||||
"a 'success' message is shown");
|
||||
"a 'success' element is shown");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a period with closing after current fails
|
||||
*
|
||||
* Given that a person as an accompanying period opened since 2015-01-05
|
||||
* and we create a new period
|
||||
* with : dateClosing: 2015-02-01 (after 2015-01-05)
|
||||
* with : dateOpening: 2014-12-31
|
||||
* with : the last closing motive in list
|
||||
* Then the response should not redirect to any page
|
||||
* and an error element is shown
|
||||
*
|
||||
* @todo
|
||||
*/
|
||||
public function testCreatePeriodWithClosingAfterCurrentFails()
|
||||
{
|
||||
|
||||
$this->markTestSkipped('this feature is not yet implemented');
|
||||
|
||||
$crawler = $this->client->request('GET', '/en/person/'
|
||||
.$this->person->getId().'/history/create');
|
||||
|
||||
$form = $crawler->selectButton('Submit')->form();;
|
||||
$form->get(self::CLOSING_MOTIVE_INPUT)
|
||||
->setValue($this->getLastValueOnClosingMotive($form));
|
||||
$form->get(self::CLOSING_INPUT)
|
||||
->setValue('01-02-2015');
|
||||
$form->get(self::OPENING_INPUT)
|
||||
->setValue('31-12-2014');
|
||||
|
||||
$crawler = $this->client->submit($form);
|
||||
|
||||
$this->assertFalse($this->client->getResponse()->isRedirect(),
|
||||
'the server stay on form page');
|
||||
$this->assertGreaterThan(0, $crawler->filter('.error')->count(),
|
||||
"an 'error' element is shown");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a period after a current opened period fails
|
||||
*
|
||||
* Given that a person as an accompanying period opened since 2015-01-05
|
||||
* and we create a new period
|
||||
* with : dateClosing: 2015-03-01
|
||||
* with : dateOpening: 2015-02-01
|
||||
* with : the last closing motive in list
|
||||
* Then the response should not redirect to any page
|
||||
* and an error element is shown
|
||||
*
|
||||
* @todo
|
||||
*/
|
||||
public function testCreatePeriodWithOpeningAndClosingAfterCurrentFails()
|
||||
{
|
||||
|
||||
$this->markTestSkipped('this feature is not yet implemented');
|
||||
|
||||
$crawler = $this->client->request('GET', '/en/person/'
|
||||
.$this->person->getId().'/history/create');
|
||||
|
||||
$form = $crawler->selectButton('Submit')->form();;
|
||||
$form->get(self::CLOSING_MOTIVE_INPUT)
|
||||
->setValue($this->getLastValueOnClosingMotive($form));
|
||||
$form->get(self::CLOSING_INPUT)
|
||||
->setValue('01-03-2015');
|
||||
$form->get(self::OPENING_INPUT)
|
||||
->setValue('01-02-2015');
|
||||
|
||||
$crawler = $this->client->submit($form);
|
||||
|
||||
$this->assertFalse($this->client->getResponse()->isRedirect(),
|
||||
'the server stay on form page');
|
||||
$this->assertGreaterThan(0, $crawler->filter('.error')->count(),
|
||||
"an 'error' element is shown");
|
||||
}
|
||||
|
||||
/**
|
||||
* create a period with date end between another period must fails
|
||||
*
|
||||
* Given that a person as an accompanying period opened since 2015-01-05
|
||||
* and that this person has another accompanying period between 2014-01-01 and 2014-12-31
|
||||
* and we create a new period
|
||||
* with : dateClosing: 2014-16-01
|
||||
* with : dateOpening: 2013-01-01
|
||||
* with : the last closing motive in list
|
||||
* Then the response should not redirect
|
||||
* and a error element is shown on the response page
|
||||
*/
|
||||
public function testCreatePeriodWithDateEndBetweenAnotherPeriodFails()
|
||||
{
|
||||
|
||||
$this->generatePeriods(array(
|
||||
[
|
||||
'openingDate' => '2014-01-01',
|
||||
'closingDate' => '2014-12-31',
|
||||
'closingMotive' => $this->getRandomClosingMotive()
|
||||
]
|
||||
));
|
||||
|
||||
$crawler = $this->client->request('GET', '/en/person/'
|
||||
.$this->person->getId().'/history/create');
|
||||
|
||||
$form = $crawler->selectButton('Submit')->form();;
|
||||
$form->get(self::CLOSING_MOTIVE_INPUT)
|
||||
->setValue($this->getLastValueOnClosingMotive($form));
|
||||
$form->get(self::CLOSING_INPUT)
|
||||
->setValue('31-12-2014');
|
||||
$form->get(self::OPENING_INPUT)
|
||||
->setValue('01-02-2015');
|
||||
|
||||
$crawlerResponse = $this->client->submit($form);
|
||||
|
||||
$this->assertFalse($this->client->getResponse()->isRedirect(),
|
||||
'the server stay on form page');
|
||||
$this->assertGreaterThan(0, $crawlerResponse->filter('.error')->count(),
|
||||
"an 'error' element is shown");
|
||||
}
|
||||
|
||||
/**
|
||||
* create a period with date closing after opening fails
|
||||
*
|
||||
* Given that a person as an accompanying period opened since 2015-01-05
|
||||
* and we create a new period
|
||||
* with : dateClosing: 2014-01-01 (before opening)
|
||||
* with : dateOpening: 2015-01-01
|
||||
* with : the last closing motive in list
|
||||
* Then the response should redirect to history view
|
||||
*/
|
||||
public function testCreatePeriodWithClosingBeforeOpeningFails()
|
||||
{
|
||||
$crawler = $this->client->request('GET', '/en/person/'
|
||||
.$this->person->getId().'/history/create');
|
||||
|
||||
$form = $crawler->selectButton('Submit')->form();;
|
||||
$form->get(self::CLOSING_MOTIVE_INPUT)
|
||||
->setValue($this->getLastValueOnClosingMotive($form));
|
||||
$form->get(self::CLOSING_INPUT)
|
||||
->setValue('01-01-2014');
|
||||
$form->get(self::OPENING_INPUT)
|
||||
->setValue('01-01-2015');
|
||||
|
||||
$crawler = $this->client->submit($form);
|
||||
|
||||
$this->assertFalse($this->client->getResponse()->isRedirect(),
|
||||
'the server stay on form page');
|
||||
$this->assertGreaterThan(0, $crawler->filter('.error')->count(),
|
||||
"an 'error' element is shown");
|
||||
}
|
||||
|
||||
/**
|
||||
* create a period with date closing and date opening inside another period
|
||||
* fails
|
||||
*
|
||||
* Given that a person as an accompanying period opened since 2015-01-05
|
||||
* and that this person has another accompanying period between 2014-01-01 and 2014-12-31
|
||||
* and we create a new period
|
||||
* with : dateClosing: 2014-02-01
|
||||
* with : dateOpening: 2014-03-01
|
||||
* with : the last closing motive in list
|
||||
* Then the response should not redirect
|
||||
* and a error element is shown on the response page
|
||||
*/
|
||||
public function testCreatePeriodAfterOpeningFails()
|
||||
{
|
||||
$this->generatePeriods(array(
|
||||
[
|
||||
'openingDate' => '2014-01-01',
|
||||
'closingDate' => '2014-12-31',
|
||||
'closingMotive' => $this->getRandomClosingMotive()
|
||||
]
|
||||
));
|
||||
|
||||
$crawler = $this->client->request('GET', '/en/person/'
|
||||
.$this->person->getId().'/history/create');
|
||||
|
||||
$form = $crawler->selectButton('Submit')->form();;
|
||||
$form->get(self::CLOSING_MOTIVE_INPUT)
|
||||
->setValue($this->getLastValueOnClosingMotive($form));
|
||||
$form->get(self::CLOSING_INPUT)
|
||||
->setValue('2014-02-01');
|
||||
$form->get(self::OPENING_INPUT)
|
||||
->setValue('01-03-2014');
|
||||
|
||||
$crawlerResponse = $this->client->submit($form);
|
||||
|
||||
$this->assertFalse($this->client->getResponse()->isRedirect(),
|
||||
'the server stay on form page');
|
||||
$this->assertGreaterThan(0, $crawlerResponse->filter('.error')->count(),
|
||||
"an 'error' element is shown");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a period with dateOpening between another period must fails
|
||||
*
|
||||
* Given that a person as an accompanying period opened since 2015-01-05
|
||||
* and that this person has another accompanying period between 2014-01-01 and 2014-12-31
|
||||
* and we create a new period
|
||||
* with : dateClosing: 2015-01-01
|
||||
* with : dateOpening: 2014-06-01
|
||||
* with : the last closing motive in list
|
||||
* Then the response should not redirect
|
||||
* and a error element is shown on the response page
|
||||
*/
|
||||
public function testCreatePeriodWithDateOpeningBetweenAnotherPeriodFails()
|
||||
{
|
||||
|
||||
$this->generatePeriods(array(
|
||||
[
|
||||
'openingDate' => '2014-01-01',
|
||||
'closingDate' => '2014-12-31',
|
||||
'closingMotive' => $this->getRandomClosingMotive()
|
||||
]
|
||||
));
|
||||
|
||||
$crawler = $this->client->request('GET', '/en/person/'
|
||||
.$this->person->getId().'/history/create');
|
||||
|
||||
$form = $crawler->selectButton('Submit')->form();;
|
||||
$form->get(self::CLOSING_MOTIVE_INPUT)
|
||||
->setValue($this->getLastValueOnClosingMotive($form));
|
||||
$form->get(self::CLOSING_INPUT)
|
||||
->setValue('2015-01-01');
|
||||
$form->get(self::OPENING_INPUT)
|
||||
->setValue('01-06-2014');
|
||||
|
||||
$crawlerResponse = $this->client->submit($form);
|
||||
|
||||
$this->assertFalse($this->client->getResponse()->isRedirect(),
|
||||
'the server stay on form page');
|
||||
$this->assertGreaterThan(0, $crawlerResponse->filter('.error')->count(),
|
||||
"an 'error' element is shown");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user