Merge pull request #4299 from wallabag/fix/4133

Fix createdAt filter on material
This commit is contained in:
Jérémy Benoist 2020-03-28 16:38:12 +01:00 committed by GitHub
commit 26467fa6b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 71 additions and 73 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,21 +75,20 @@ 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',
] ])
)
->add('domainName', TextFilterType::class, [ ->add('domainName', TextFilterType::class, [
'apply_filter' => function (QueryInterface $filterQuery, $field, $values) { 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) {
$value = $values['value']; $value = $values['value'];

View file

@ -39,7 +39,7 @@
<ul class="{% if listMode == 1 %}collection{% else %}row data{% endif %}"> <ul class="{% if listMode == 1 %}collection{% else %}row data{% endif %}">
{% for entry in entries %} {% for entry in entries %}
<li id="entry-{{ entry.id|e }}" class="col {% if listMode == 0 %}l3 m6{% else %}collection-item{% endif %} s12"> <li id="entry-{{ entry.id|e }}" class="entry col {% if listMode == 0 %}l3 m6{% else %}collection-item{% endif %} s12">
{% if listMode == 1 %} {% if listMode == 1 %}
{% include "@WallabagCore/themes/material/Entry/_card_list.html.twig" with {'entry': entry} only %} {% include "@WallabagCore/themes/material/Entry/_card_list.html.twig" with {'entry': entry} only %}
{% elseif not entry.previewPicture is null and entry.mimetype starts with 'image/' %} {% elseif not entry.previewPicture is null and entry.mimetype starts with 'image/' %}

View file

@ -90,19 +90,18 @@ class EntryControllerTest extends WallabagCoreTestCase
public function testPostNewViaBookmarklet() public function testPostNewViaBookmarklet()
{ {
$this->logInAs('admin'); $this->logInAs('admin');
$this->useTheme('baggy');
$client = $this->getClient(); $client = $this->getClient();
$crawler = $client->request('GET', '/'); $crawler = $client->request('GET', '/');
$this->assertCount(4, $crawler->filter('div[class=entry]')); $this->assertCount(4, $crawler->filter('li.entry'));
// Good URL // Good URL
$client->request('GET', '/bookmarklet', ['url' => $this->url]); $client->request('GET', '/bookmarklet', ['url' => $this->url]);
$this->assertSame(302, $client->getResponse()->getStatusCode()); $this->assertSame(302, $client->getResponse()->getStatusCode());
$client->followRedirect(); $client->followRedirect();
$crawler = $client->request('GET', '/'); $crawler = $client->request('GET', '/');
$this->assertCount(5, $crawler->filter('div[class=entry]')); $this->assertCount(5, $crawler->filter('li.entry'));
$em = $client->getContainer() $em = $client->getContainer()
->get('doctrine.orm.entity_manager'); ->get('doctrine.orm.entity_manager');
@ -694,7 +693,6 @@ class EntryControllerTest extends WallabagCoreTestCase
public function testFilterOnReadingTime() public function testFilterOnReadingTime()
{ {
$this->logInAs('admin'); $this->logInAs('admin');
$this->useTheme('baggy');
$client = $this->getClient(); $client = $this->getClient();
$entry = new Entry($this->getLoggedInUser()); $entry = new Entry($this->getLoggedInUser());
$entry->setUrl($this->url); $entry->setUrl($this->url);
@ -713,7 +711,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$crawler = $client->submit($form, $data); $crawler = $client->submit($form, $data);
$this->assertCount(1, $crawler->filter('div[class=entry]')); $this->assertCount(1, $crawler->filter('li.entry'));
} }
public function testFilterOnReadingTimeWithNegativeValue() public function testFilterOnReadingTimeWithNegativeValue()
@ -733,17 +731,16 @@ class EntryControllerTest extends WallabagCoreTestCase
$crawler = $client->submit($form, $data); $crawler = $client->submit($form, $data);
// forcing negative value results in no entry displayed // forcing negative value results in no entry displayed
$this->assertCount(0, $crawler->filter('div[class=entry]')); $this->assertCount(0, $crawler->filter('li.entry'));
} }
public function testFilterOnReadingTimeOnlyUpper() public function testFilterOnReadingTimeOnlyUpper()
{ {
$this->logInAs('admin'); $this->logInAs('admin');
$this->useTheme('baggy');
$client = $this->getClient(); $client = $this->getClient();
$crawler = $client->request('GET', '/all/list'); $crawler = $client->request('GET', '/all/list');
$this->assertCount(5, $crawler->filter('div[class=entry]')); $this->assertCount(5, $crawler->filter('li.entry'));
$entry = new Entry($this->getLoggedInUser()); $entry = new Entry($this->getLoggedInUser());
$entry->setUrl($this->url); $entry->setUrl($this->url);
@ -752,7 +749,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$this->getEntityManager()->flush(); $this->getEntityManager()->flush();
$crawler = $client->request('GET', '/all/list'); $crawler = $client->request('GET', '/all/list');
$this->assertCount(6, $crawler->filter('div[class=entry]')); $this->assertCount(6, $crawler->filter('li.entry'));
$form = $crawler->filter('button[id=submit-filter]')->form(); $form = $crawler->filter('button[id=submit-filter]')->form();
@ -762,13 +759,12 @@ class EntryControllerTest extends WallabagCoreTestCase
$crawler = $client->submit($form, $data); $crawler = $client->submit($form, $data);
$this->assertCount(5, $crawler->filter('div[class=entry]')); $this->assertCount(5, $crawler->filter('li.entry'));
} }
public function testFilterOnReadingTimeOnlyLower() public function testFilterOnReadingTimeOnlyLower()
{ {
$this->logInAs('admin'); $this->logInAs('admin');
$this->useTheme('baggy');
$client = $this->getClient(); $client = $this->getClient();
$crawler = $client->request('GET', '/unread/list'); $crawler = $client->request('GET', '/unread/list');
@ -781,7 +777,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$crawler = $client->submit($form, $data); $crawler = $client->submit($form, $data);
$this->assertCount(0, $crawler->filter('div[class=entry]')); $this->assertCount(0, $crawler->filter('li.entry'));
$entry = new Entry($this->getLoggedInUser()); $entry = new Entry($this->getLoggedInUser());
$entry->setUrl($this->url); $entry->setUrl($this->url);
@ -790,13 +786,12 @@ class EntryControllerTest extends WallabagCoreTestCase
$this->getEntityManager()->flush(); $this->getEntityManager()->flush();
$crawler = $client->submit($form, $data); $crawler = $client->submit($form, $data);
$this->assertCount(1, $crawler->filter('div[class=entry]')); $this->assertCount(1, $crawler->filter('li.entry'));
} }
public function testFilterOnUnreadStatus() public function testFilterOnUnreadStatus()
{ {
$this->logInAs('admin'); $this->logInAs('admin');
$this->useTheme('baggy');
$client = $this->getClient(); $client = $this->getClient();
$crawler = $client->request('GET', '/all/list'); $crawler = $client->request('GET', '/all/list');
@ -809,7 +804,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$crawler = $client->submit($form, $data); $crawler = $client->submit($form, $data);
$this->assertCount(4, $crawler->filter('div[class=entry]')); $this->assertCount(4, $crawler->filter('li.entry'));
$entry = new Entry($this->getLoggedInUser()); $entry = new Entry($this->getLoggedInUser());
$entry->setUrl($this->url); $entry->setUrl($this->url);
@ -819,45 +814,56 @@ class EntryControllerTest extends WallabagCoreTestCase
$crawler = $client->submit($form, $data); $crawler = $client->submit($form, $data);
$this->assertCount(5, $crawler->filter('div[class=entry]')); $this->assertCount(5, $crawler->filter('li.entry'));
} }
public function testFilterOnCreationDate() public function testFilterOnCreationDate()
{ {
$this->logInAs('admin'); $this->logInAs('admin');
$this->useTheme('baggy');
$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);
$this->assertCount(5, $crawler->filter('div[class=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);
$this->assertCount(5, $crawler->filter('div[class=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);
$this->assertCount(0, $crawler->filter('div[class=entry]')); $this->assertCount(0, $crawler->filter('li.entry'));
} }
public function testPaginationWithFilter() public function testPaginationWithFilter()
@ -892,7 +898,6 @@ class EntryControllerTest extends WallabagCoreTestCase
public function testFilterOnDomainName() public function testFilterOnDomainName()
{ {
$this->logInAs('admin'); $this->logInAs('admin');
$this->useTheme('baggy');
$client = $this->getClient(); $client = $this->getClient();
$crawler = $client->request('GET', '/unread/list'); $crawler = $client->request('GET', '/unread/list');
@ -902,7 +907,7 @@ class EntryControllerTest extends WallabagCoreTestCase
]; ];
$crawler = $client->submit($form, $data); $crawler = $client->submit($form, $data);
$this->assertCount(5, $crawler->filter('div[class=entry]')); $this->assertCount(5, $crawler->filter('li.entry'));
$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();
@ -911,7 +916,7 @@ class EntryControllerTest extends WallabagCoreTestCase
]; ];
$crawler = $client->submit($form, $data); $crawler = $client->submit($form, $data);
$this->assertCount(5, $crawler->filter('div[class=entry]')); $this->assertCount(5, $crawler->filter('li.entry'));
$form = $crawler->filter('button[id=submit-filter]')->form(); $form = $crawler->filter('button[id=submit-filter]')->form();
$data = [ $data = [
@ -919,13 +924,12 @@ class EntryControllerTest extends WallabagCoreTestCase
]; ];
$crawler = $client->submit($form, $data); $crawler = $client->submit($form, $data);
$this->assertCount(0, $crawler->filter('div[class=entry]')); $this->assertCount(0, $crawler->filter('li.entry'));
} }
public function testFilterOnStatus() public function testFilterOnStatus()
{ {
$this->logInAs('admin'); $this->logInAs('admin');
$this->useTheme('baggy');
$client = $this->getClient(); $client = $this->getClient();
$crawler = $client->request('GET', '/unread/list'); $crawler = $client->request('GET', '/unread/list');
@ -934,20 +938,19 @@ class EntryControllerTest extends WallabagCoreTestCase
$form['entry_filter[isStarred]']->untick(); $form['entry_filter[isStarred]']->untick();
$crawler = $client->submit($form); $crawler = $client->submit($form);
$this->assertCount(1, $crawler->filter('div[class=entry]')); $this->assertCount(1, $crawler->filter('li.entry'));
$form = $crawler->filter('button[id=submit-filter]')->form(); $form = $crawler->filter('button[id=submit-filter]')->form();
$form['entry_filter[isArchived]']->untick(); $form['entry_filter[isArchived]']->untick();
$form['entry_filter[isStarred]']->tick(); $form['entry_filter[isStarred]']->tick();
$crawler = $client->submit($form); $crawler = $client->submit($form);
$this->assertCount(1, $crawler->filter('div[class=entry]')); $this->assertCount(1, $crawler->filter('li.entry'));
} }
public function testFilterOnIsPublic() public function testFilterOnIsPublic()
{ {
$this->logInAs('admin'); $this->logInAs('admin');
$this->useTheme('baggy');
$client = $this->getClient(); $client = $this->getClient();
$crawler = $client->request('GET', '/unread/list'); $crawler = $client->request('GET', '/unread/list');
@ -955,13 +958,12 @@ class EntryControllerTest extends WallabagCoreTestCase
$form['entry_filter[isPublic]']->tick(); $form['entry_filter[isPublic]']->tick();
$crawler = $client->submit($form); $crawler = $client->submit($form);
$this->assertCount(0, $crawler->filter('div[class=entry]')); $this->assertCount(0, $crawler->filter('li.entry'));
} }
public function testPreviewPictureFilter() public function testPreviewPictureFilter()
{ {
$this->logInAs('admin'); $this->logInAs('admin');
$this->useTheme('baggy');
$client = $this->getClient(); $client = $this->getClient();
$crawler = $client->request('GET', '/unread/list'); $crawler = $client->request('GET', '/unread/list');
@ -969,13 +971,12 @@ class EntryControllerTest extends WallabagCoreTestCase
$form['entry_filter[previewPicture]']->tick(); $form['entry_filter[previewPicture]']->tick();
$crawler = $client->submit($form); $crawler = $client->submit($form);
$this->assertCount(1, $crawler->filter('div[class=entry]')); $this->assertCount(1, $crawler->filter('li.entry'));
} }
public function testFilterOnLanguage() public function testFilterOnLanguage()
{ {
$this->logInAs('admin'); $this->logInAs('admin');
$this->useTheme('baggy');
$client = $this->getClient(); $client = $this->getClient();
$entry = new Entry($this->getLoggedInUser()); $entry = new Entry($this->getLoggedInUser());
@ -991,7 +992,7 @@ class EntryControllerTest extends WallabagCoreTestCase
]; ];
$crawler = $client->submit($form, $data); $crawler = $client->submit($form, $data);
$this->assertCount(3, $crawler->filter('div[class=entry]')); $this->assertCount(3, $crawler->filter('li.entry'));
$form = $crawler->filter('button[id=submit-filter]')->form(); $form = $crawler->filter('button[id=submit-filter]')->form();
$data = [ $data = [
@ -999,7 +1000,7 @@ class EntryControllerTest extends WallabagCoreTestCase
]; ];
$crawler = $client->submit($form, $data); $crawler = $client->submit($form, $data);
$this->assertCount(2, $crawler->filter('div[class=entry]')); $this->assertCount(2, $crawler->filter('li.entry'));
} }
public function testShareEntryPublicly() public function testShareEntryPublicly()
@ -1181,7 +1182,6 @@ class EntryControllerTest extends WallabagCoreTestCase
public function testFilterOnHttpStatus() public function testFilterOnHttpStatus()
{ {
$this->logInAs('admin'); $this->logInAs('admin');
$this->useTheme('baggy');
$client = $this->getClient(); $client = $this->getClient();
$entry = new Entry($this->getLoggedInUser()); $entry = new Entry($this->getLoggedInUser());
@ -1200,7 +1200,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$crawler = $client->submit($form, $data); $crawler = $client->submit($form, $data);
$this->assertCount(1, $crawler->filter('div[class=entry]')); $this->assertCount(1, $crawler->filter('li.entry'));
$entry = new Entry($this->getLoggedInUser()); $entry = new Entry($this->getLoggedInUser());
$entry->setUrl($this->url); $entry->setUrl($this->url);
@ -1223,7 +1223,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$crawler = $client->submit($form, $data); $crawler = $client->submit($form, $data);
$this->assertCount(2, $crawler->filter('div[class=entry]')); $this->assertCount(2, $crawler->filter('li.entry'));
$crawler = $client->request('GET', '/all/list'); $crawler = $client->request('GET', '/all/list');
$form = $crawler->filter('button[id=submit-filter]')->form(); $form = $crawler->filter('button[id=submit-filter]')->form();
@ -1234,13 +1234,12 @@ class EntryControllerTest extends WallabagCoreTestCase
$crawler = $client->submit($form, $data); $crawler = $client->submit($form, $data);
$this->assertCount(8, $crawler->filter('div[class=entry]')); $this->assertCount(8, $crawler->filter('li.entry'));
} }
public function testSearch() public function testSearch()
{ {
$this->logInAs('admin'); $this->logInAs('admin');
$this->useTheme('baggy');
$client = $this->getClient(); $client = $this->getClient();
$entry = new Entry($this->getLoggedInUser()); $entry = new Entry($this->getLoggedInUser());
@ -1259,7 +1258,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$crawler = $client->submit($form, $data); $crawler = $client->submit($form, $data);
$this->assertCount(4, $crawler->filter('div[class=entry]')); $this->assertCount(4, $crawler->filter('li.entry'));
// Search on starred list // Search on starred list
$crawler = $client->request('GET', '/starred/list'); $crawler = $client->request('GET', '/starred/list');
@ -1278,7 +1277,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$crawler = $client->submit($form, $data); $crawler = $client->submit($form, $data);
$this->assertCount(1, $crawler->filter('div[class=entry]')); $this->assertCount(1, $crawler->filter('li.entry'));
$crawler = $client->request('GET', '/archive/list'); $crawler = $client->request('GET', '/archive/list');
@ -1297,7 +1296,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$crawler = $client->submit($form, $data); $crawler = $client->submit($form, $data);
$this->assertCount(1, $crawler->filter('div[class=entry]')); $this->assertCount(1, $crawler->filter('li.entry'));
$client->request('GET', '/delete/' . $entry->getId()); $client->request('GET', '/delete/' . $entry->getId());
// test on list of all articles // test on list of all articles
@ -1310,7 +1309,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$crawler = $client->submit($form, $data); $crawler = $client->submit($form, $data);
$this->assertCount(0, $crawler->filter('div[class=entry]')); $this->assertCount(0, $crawler->filter('li.entry'));
// test url search on list of all articles // test url search on list of all articles
$entry = new Entry($this->getLoggedInUser()); $entry = new Entry($this->getLoggedInUser());
@ -1329,7 +1328,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$crawler = $client->submit($form, $data); $crawler = $client->submit($form, $data);
$this->assertCount(1, $crawler->filter('div[class=entry]')); $this->assertCount(1, $crawler->filter('li.entry'));
// same as previous test but for case-sensitivity // same as previous test but for case-sensitivity
$crawler = $client->request('GET', '/all/list'); $crawler = $client->request('GET', '/all/list');
@ -1341,7 +1340,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$crawler = $client->submit($form, $data); $crawler = $client->submit($form, $data);
$this->assertCount(1, $crawler->filter('div[class=entry]')); $this->assertCount(1, $crawler->filter('li.entry'));
} }
public function dataForLanguage() public function dataForLanguage()

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long