mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +00:00
fix tests
This commit is contained in:
parent
209aa24866
commit
8e6f2d4355
@ -167,7 +167,7 @@ class EventSearchTest extends WebTestCase
|
|||||||
'q' => '@events'
|
'q' => '@events'
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->assertGreaterThan(2, $crawler->filter('table.events tr')->count(),
|
$this->assertGreaterThanOrEqual(2, $crawler->filter('table.events tr')->count(),
|
||||||
'assert than more than 2 tr are present');
|
'assert than more than 2 tr are present');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,49 +205,171 @@ class EventSearchTest extends WebTestCase
|
|||||||
'assert that the word "printemps" is present');
|
'assert that the word "printemps" is present');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSearchByDate()
|
public function testSearchByDateDateFromOnly()
|
||||||
{
|
{
|
||||||
// search with date from
|
// search with date from
|
||||||
$crawler = $this->client->request('GET', '/fr/search', array(
|
$crawler = $this->client->request('GET', '/fr/search', array(
|
||||||
'q' => '@events date-from:2016-05-30'
|
'q' => '@events date-from:2016-05-30'
|
||||||
));
|
));
|
||||||
|
/* @var $dateFrom \DateTime the date from in DateTime */
|
||||||
|
$dateFrom = \DateTime::createFromFormat("Y-m-d", "2016-05-30");
|
||||||
|
|
||||||
$this->assertEquals(
|
$dates = $this->iterateOnRowsToFindDate($crawler->filter("tr"));
|
||||||
1,
|
|
||||||
$crawler->filter('tr:contains("Printemps")')->count(),
|
|
||||||
'assert that the word "printemps" is present');
|
|
||||||
$this->assertEquals(
|
|
||||||
1,
|
|
||||||
$crawler->filter('tr:contains("Hiver")')->count(),
|
|
||||||
'assert that the word "Hiver" is present');
|
|
||||||
|
|
||||||
|
foreach($dates as $date) {
|
||||||
|
$this->assertGreaterThanOrEqual($dateFrom, $date);
|
||||||
|
}
|
||||||
|
|
||||||
|
// click on link "Voir tous les résultats"
|
||||||
|
$crawlerAllResults = $this->client->click($crawler
|
||||||
|
->selectLink("Voir tous les résultats")->link());
|
||||||
|
$dates = $this->iterateOnRowsToFindDate($crawlerAllResults->filter("tr"));
|
||||||
|
|
||||||
|
foreach ($dates as $date) {
|
||||||
|
$this->assertGreaterThanOrEqual($dateFrom, $date);
|
||||||
|
}
|
||||||
|
|
||||||
|
//iterate on pagination
|
||||||
|
$crawlerAllResults->filter(".pagination a")->each(function($a, $i) use ($dateFrom) {
|
||||||
|
$page = $this->client->click($a->link());
|
||||||
|
$dates = $this->iterateOnRowsToFindDate($page->filter("tr"));
|
||||||
|
|
||||||
|
foreach($dates as $date) {
|
||||||
|
$this->assertGreaterThanOrEqual($dateFrom, $date);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSearchByDateDateBetween()
|
||||||
|
{
|
||||||
// serach with date from **and** date-to
|
// serach with date from **and** date-to
|
||||||
$crawler = $this->client->request('GET', '/fr/search', array(
|
$crawler = $this->client->request('GET', '/fr/search', array(
|
||||||
'q' => '@events date-from:2016-05-30 date-to:2016-06-20'
|
'q' => '@events date-from:2016-05-30 date-to:2016-06-20'
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->assertEquals(
|
/* @var $dateFrom \DateTime the date from in DateTime */
|
||||||
1,
|
$dateFrom = \DateTime::createFromFormat("Y-m-d", "2016-05-30");
|
||||||
$crawler->filter('tr:contains("Printemps")')->count(),
|
$dateTo = \DateTime::createFromFormat("Y-m-d", "2016-06-20");
|
||||||
'assert that the word "printemps" is present');
|
|
||||||
$this->assertEquals(
|
$dates = $this->iterateOnRowsToFindDate($crawler->filter("tr"));
|
||||||
0,
|
|
||||||
$crawler->filter('tr:contains("Hiver")')->count(),
|
foreach($dates as $date) {
|
||||||
'assert that the word "Hiver" is not present');
|
$this->assertGreaterThanOrEqual($dateFrom, $date);
|
||||||
|
$this->assertLessThanOrEqual($dateTo, $date);
|
||||||
|
}
|
||||||
|
|
||||||
|
// there should not have any other results, but if any other bundle
|
||||||
|
// add some other event, we go on next pages
|
||||||
|
|
||||||
|
if ($crawler->selectLink("Voir tous les résultats")->count() == 0) {
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
// click on link "Voir tous les résultats"
|
||||||
|
$crawlerAllResults = $this->client->click($crawler
|
||||||
|
->selectLink("Voir tous les résultats")->link());
|
||||||
|
$dates = $this->iterateOnRowsToFindDate($crawlerAllResults->filter("tr"));
|
||||||
|
|
||||||
|
foreach ($dates as $date) {
|
||||||
|
$this->assertGreaterThanOrEqual($dateFrom, $date);
|
||||||
|
$this->assertLessThanOrEqual($dateTo, $date);
|
||||||
|
}
|
||||||
|
|
||||||
|
//iterate on pagination
|
||||||
|
$crawlerAllResults->filter(".pagination a")->each(function($a, $i) use ($dateFrom) {
|
||||||
|
$page = $this->client->click($a->link());
|
||||||
|
$dates = $this->iterateOnRowsToFindDate($page->filter("tr"));
|
||||||
|
|
||||||
|
foreach($dates as $date) {
|
||||||
|
$this->assertGreaterThanOrEqual($dateFrom, $date);
|
||||||
|
$this->assertLessThanOrEqual($dateTo, $date);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSearchByDateDateTo()
|
||||||
|
{
|
||||||
|
|
||||||
// serach with date from **and** date-to
|
// serach with date from **and** date-to
|
||||||
$crawler = $this->client->request('GET', '/fr/search', array(
|
$crawler = $this->client->request('GET', '/fr/search', array(
|
||||||
'q' => '@events date:2016-05-30'
|
'q' => '@events date:2016-05-30'
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->assertEquals(
|
/* @var $dateFrom \DateTime the date from in DateTime */
|
||||||
1,
|
$dateTo = \DateTime::createFromFormat("Y-m-d", "2016-05-30");
|
||||||
$crawler->filter('tr:contains("Printemps")')->count(),
|
|
||||||
'assert that the word "printemps" is present');
|
$dates = $this->iterateOnRowsToFindDate($crawler->filter("tr"));
|
||||||
$this->assertEquals(
|
|
||||||
0,
|
foreach($dates as $date) {
|
||||||
$crawler->filter('tr:contains("Hiver")')->count(),
|
$this->assertLessThanOrEqual($dateTo, $date);
|
||||||
'assert that the word "Hiver" is not present');
|
}
|
||||||
|
|
||||||
|
if ($crawler->selectLink("Voir tous les résultats")->count() == 0) {
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
// click on link "Voir tous les résultats"
|
||||||
|
$crawlerAllResults = $this->client->click($crawler
|
||||||
|
->selectLink("Voir tous les résultats")->link());
|
||||||
|
$dates = $this->iterateOnRowsToFindDate($crawlerAllResults->filter("tr"));
|
||||||
|
|
||||||
|
foreach ($dates as $date) {
|
||||||
|
$this->assertLessThanOrEqual($dateTo, $date);
|
||||||
|
}
|
||||||
|
|
||||||
|
//iterate on pagination
|
||||||
|
$crawlerAllResults->filter(".pagination a")->each(function($a, $i) use ($dateFrom) {
|
||||||
|
$page = $this->client->click($a->link());
|
||||||
|
$dates = $this->iterateOnRowsToFindDate($page->filter("tr"));
|
||||||
|
|
||||||
|
foreach($dates as $date) {
|
||||||
|
$this->assertLessThanOrEqual($dateTo, $date);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* this function iterate on row from results of events and return the content
|
||||||
|
* of the second column (which should contains the date) in DateTime objects
|
||||||
|
*
|
||||||
|
* @param \Symfony\Component\DomCrawler\Crawler $trs
|
||||||
|
* @return \DateTime[]
|
||||||
|
*/
|
||||||
|
private function iterateOnRowsToFindDate(\Symfony\Component\DomCrawler\Crawler $trs)
|
||||||
|
{
|
||||||
|
$months = array(
|
||||||
|
"janvier" => 1,
|
||||||
|
"février" => 2,
|
||||||
|
"mars" => 3,
|
||||||
|
"avril" => 4,
|
||||||
|
"mai" => 5,
|
||||||
|
"juin" => 6,
|
||||||
|
"juillet" => 7,
|
||||||
|
"août" => 8,
|
||||||
|
"septembre" => 9,
|
||||||
|
"octobre" => 10,
|
||||||
|
"novembre" => 11,
|
||||||
|
"décembre" => 12
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
$results = $trs->each(function($tr, $i) use ($months) {
|
||||||
|
// we skip the first row
|
||||||
|
if ($i > 0) {
|
||||||
|
// get the second node, which should contains a date
|
||||||
|
$tdDate = $tr->filter("td")->eq(1);
|
||||||
|
// transform the date, which should be in french, into a DateTime object
|
||||||
|
$parts = explode(" ", $tdDate->text());
|
||||||
|
return \DateTime::createFromFormat("Y-m-d", $parts[2].
|
||||||
|
"-".$months[$parts[1]]."-".$parts[0]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// remove the first row
|
||||||
|
unset($results[0]);
|
||||||
|
|
||||||
|
return $results;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user