Fix createdAt date range filter

- hiddenName has been disabled in order to fix the missing date range
  values when using the material theme
- data format has been changed to 'Y-m-d' in order to comply with the
  browser date input default format
- tests: date() and strtotime have been replaced with DateTime-related
  objects

Signed-off-by: Kevin Decherf <kevin@kdecherf.com>
This commit is contained in:
Kevin Decherf 2020-03-21 21:11:01 +01:00
parent ef81e3c89b
commit 8ee7b1603d
6 changed files with 28 additions and 16 deletions

View file

@ -57,9 +57,9 @@ $(document).ready(() => {
$('.datepicker').pickadate({ $('.datepicker').pickadate({
selectMonths: true, selectMonths: true,
selectYears: 15, selectYears: 15,
formatSubmit: 'dd/mm/yyyy', formatSubmit: 'yyyy-mm-dd',
hiddenName: true, hiddenName: false,
format: 'dd/mm/yyyy', format: 'yyyy-mm-dd',
container: 'body', container: 'body',
}); });

View file

@ -552,7 +552,7 @@ class Entry
* *
* @return Entry * @return Entry
*/ */
public function setCreatedAt(\DateTime $createdAt) public function setCreatedAt(\DateTimeInterface $createdAt)
{ {
$this->createdAt = $createdAt; $this->createdAt = $createdAt;

View file

@ -75,16 +75,16 @@ class EntryFilterType extends AbstractType
->add('createdAt', DateRangeFilterType::class, [ ->add('createdAt', DateRangeFilterType::class, [
'left_date_options' => [ 'left_date_options' => [
'attr' => [ 'attr' => [
'placeholder' => 'dd/mm/yyyy', 'placeholder' => 'yyyy-mm-dd',
], ],
'format' => 'dd/MM/yyyy', 'format' => 'yyyy-MM-dd',
'widget' => 'single_text', 'widget' => 'single_text',
], ],
'right_date_options' => [ 'right_date_options' => [
'attr' => [ 'attr' => [
'placeholder' => 'dd/mm/yyyy', 'placeholder' => 'yyyy-mm-dd',
], ],
'format' => 'dd/MM/yyyy', 'format' => 'yyyy-MM-dd',
'widget' => 'single_text', 'widget' => 'single_text',
], ],
'label' => 'entry.filters.created_at.label', 'label' => 'entry.filters.created_at.label',

View file

@ -822,13 +822,25 @@ class EntryControllerTest extends WallabagCoreTestCase
$this->logInAs('admin'); $this->logInAs('admin');
$client = $this->getClient(); $client = $this->getClient();
$em = $this->getEntityManager();
$today = new \DateTimeImmutable();
$tomorrow = $today->add(new \DateInterval('P1D'));
$yesterday = $today->sub(new \DateInterval('P1D'));
$entry = new Entry($this->getLoggedInUser());
$entry->setUrl('http://0.0.0.0/testFilterOnCreationDate');
$entry->setCreatedAt($yesterday);
$em->persist($entry);
$em->flush();
$crawler = $client->request('GET', '/unread/list'); $crawler = $client->request('GET', '/unread/list');
$form = $crawler->filter('button[id=submit-filter]')->form(); $form = $crawler->filter('button[id=submit-filter]')->form();
$data = [ $data = [
'entry_filter[createdAt][left_date]' => date('d/m/Y'), 'entry_filter[createdAt][left_date]' => $today->format('Y-m-d'),
'entry_filter[createdAt][right_date]' => date('d/m/Y', strtotime('+1 day')), 'entry_filter[createdAt][right_date]' => $tomorrow->format('Y-m-d'),
]; ];
$crawler = $client->submit($form, $data); $crawler = $client->submit($form, $data);
@ -836,8 +848,8 @@ class EntryControllerTest extends WallabagCoreTestCase
$this->assertCount(5, $crawler->filter('li.entry')); $this->assertCount(5, $crawler->filter('li.entry'));
$data = [ $data = [
'entry_filter[createdAt][left_date]' => date('d/m/Y'), 'entry_filter[createdAt][left_date]' => $today->format('Y-m-d'),
'entry_filter[createdAt][right_date]' => date('d/m/Y'), 'entry_filter[createdAt][right_date]' => $today->format('Y-m-d'),
]; ];
$crawler = $client->submit($form, $data); $crawler = $client->submit($form, $data);
@ -845,8 +857,8 @@ class EntryControllerTest extends WallabagCoreTestCase
$this->assertCount(5, $crawler->filter('li.entry')); $this->assertCount(5, $crawler->filter('li.entry'));
$data = [ $data = [
'entry_filter[createdAt][left_date]' => '01/01/1970', 'entry_filter[createdAt][left_date]' => '1970-01-01',
'entry_filter[createdAt][right_date]' => '01/01/1970', 'entry_filter[createdAt][right_date]' => '1970-01-01',
]; ];
$crawler = $client->submit($form, $data); $crawler = $client->submit($form, $data);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long