From 76459e5694084f3eea6d30f438ffc95fb35cbe67 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nicolas=20L=C5=93uillet?= Date: Sat, 25 Apr 2020 10:33:41 +0200 Subject: [PATCH] Added tests --- .../CoreBundle/Form/Type/EntrySortType.php | 2 +- .../Resources/translations/messages.da.yml | 12 +- .../Resources/translations/messages.de.yml | 12 +- .../Resources/translations/messages.en.yml | 2 + .../Resources/translations/messages.es.yml | 12 +- .../Resources/translations/messages.fa.yml | 12 +- .../Resources/translations/messages.fr.yml | 4 + .../Resources/translations/messages.it.yml | 12 +- .../Resources/translations/messages.ja.yml | 13 ++ .../Resources/translations/messages.oc.yml | 12 +- .../Resources/translations/messages.pl.yml | 12 +- .../Resources/translations/messages.pt.yml | 12 +- .../Resources/translations/messages.ro.yml | 12 +- .../Resources/translations/messages.ru.yml | 13 ++ .../Resources/translations/messages.th.yml | 13 ++ .../Resources/translations/messages.tr.yml | 12 +- .../Resources/translations/messages.zh.yml | 13 ++ .../Controller/EntryControllerTest.php | 197 +++++++++++++++++- 18 files changed, 335 insertions(+), 42 deletions(-) diff --git a/src/Wallabag/CoreBundle/Form/Type/EntrySortType.php b/src/Wallabag/CoreBundle/Form/Type/EntrySortType.php index ac251c5b..4ad54118 100644 --- a/src/Wallabag/CoreBundle/Form/Type/EntrySortType.php +++ b/src/Wallabag/CoreBundle/Form/Type/EntrySortType.php @@ -36,8 +36,8 @@ class EntrySortType extends AbstractType 'entry.sort.by.creation_date' => 'createdAt', 'entry.sort.by.starred_date' => 'starredAt', 'entry.sort.by.archive_date' => 'archivedAt', - 'entry.sort.by.title' => 'title', 'entry.sort.by.last_updated' => 'updatedAt', + 'entry.sort.by.title' => 'title', ], 'label' => 'entry.sort.status_label', ]) diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml index 0c35f2f9..20a3fa50 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml @@ -260,12 +260,16 @@ entry: sort: # title: 'Sort options' # status_label: 'Sort by' + # order_label: 'Order' # by: - # creation_date: 'Creation date' - # title: 'Title' - # last_updated: 'Last updated' - #ascending: 'Asencending' + # creation_date: 'Creation date' + # starred_date: 'Starred date' + # archive_date: 'Archived date' + # title: 'Title' + # last_updated: 'Last updated' + # ascending: 'Ascending' # descending: 'Descending' + # sort: 'Sort' view: left_menu: # back_to_top: 'Back to top' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml index 73ecebb9..d998cfc8 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml @@ -260,12 +260,16 @@ entry: sort: # title: 'Sort options' # status_label: 'Sort by' + # order_label: 'Order' # by: - # creation_date: 'Creation date' - # title: 'Title' - # last_updated: 'Last updated' - #ascending: 'Asencending' + # creation_date: 'Creation date' + # starred_date: 'Starred date' + # archive_date: 'Archived date' + # title: 'Title' + # last_updated: 'Last updated' + # ascending: 'Ascending' # descending: 'Descending' + # sort: 'Sort' view: left_menu: back_to_top: 'Nach oben' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml index c7699ef0..635937a5 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml @@ -263,6 +263,8 @@ entry: order_label: 'Order' by: creation_date: 'Creation date' + starred_date: 'Starred date' + archive_date: 'Archived date' title: 'Title' last_updated: 'Last updated' ascending: 'Ascending' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml index 1d834290..9945e24b 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml @@ -260,12 +260,16 @@ entry: sort: # title: 'Sort options' # status_label: 'Sort by' + # order_label: 'Order' # by: - # creation_date: 'Creation date' - # title: 'Title' - # last_updated: 'Last updated' - #ascending: 'Asencending' + # creation_date: 'Creation date' + # starred_date: 'Starred date' + # archive_date: 'Archived date' + # title: 'Title' + # last_updated: 'Last updated' + # ascending: 'Ascending' # descending: 'Descending' + # sort: 'Sort' view: left_menu: back_to_top: 'Regrese al principio' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml index 46e96c04..6cb3be43 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml @@ -260,12 +260,16 @@ entry: sort: # title: 'Sort options' # status_label: 'Sort by' + # order_label: 'Order' # by: - # creation_date: 'Creation date' - # title: 'Title' - # last_updated: 'Last updated' - #ascending: 'Asencending' + # creation_date: 'Creation date' + # starred_date: 'Starred date' + # archive_date: 'Archived date' + # title: 'Title' + # last_updated: 'Last updated' + # ascending: 'Ascending' # descending: 'Descending' + # sort: 'Sort' view: left_menu: back_to_top: 'بازگشت به بالای صفحه' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml index dc75f5c1..75df9260 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml @@ -260,12 +260,16 @@ entry: sort: title: 'Options de tri' status_label: 'Trier par' + order_label: 'Ordre' by: creation_date: 'Date de création' + starred_date: 'Date de mise en favori date' + archive_date: "Date d'archivage" title: 'Titre' last_updated: 'Dernière mise à jour' ascending: 'Ascendant' descending: 'Descendant' + sort: 'Trier' view: left_menu: back_to_top: "Revenir en haut" diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml index 804871b1..7e30fa8a 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml @@ -260,12 +260,16 @@ entry: sort: # title: 'Sort options' # status_label: 'Sort by' + # order_label: 'Order' # by: - # creation_date: 'Creation date' - # title: 'Title' - # last_updated: 'Last updated' - #ascending: 'Asencending' + # creation_date: 'Creation date' + # starred_date: 'Starred date' + # archive_date: 'Archived date' + # title: 'Title' + # last_updated: 'Last updated' + # ascending: 'Ascending' # descending: 'Descending' + # sort: 'Sort' view: left_menu: back_to_top: "Torna all'inizio" diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.ja.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.ja.yml index 9ae4d6bb..38e8e95c 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.ja.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.ja.yml @@ -236,6 +236,19 @@ entry: action: clear: '解除' filter: '検索' + sort: + # title: 'Sort options' + # status_label: 'Sort by' + # order_label: 'Order' + # by: + # creation_date: 'Creation date' + # starred_date: 'Starred date' + # archive_date: 'Archived date' + # title: 'Title' + # last_updated: 'Last updated' + # ascending: 'Ascending' + # descending: 'Descending' + # sort: 'Sort' view: left_menu: back_to_top: 'トップへ戻る' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml index 93b844d8..7bda5880 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml @@ -260,12 +260,16 @@ entry: sort: # title: 'Sort options' # status_label: 'Sort by' + # order_label: 'Order' # by: - # creation_date: 'Creation date' - # title: 'Title' - # last_updated: 'Last updated' - #ascending: 'Asencending' + # creation_date: 'Creation date' + # starred_date: 'Starred date' + # archive_date: 'Archived date' + # title: 'Title' + # last_updated: 'Last updated' + # ascending: 'Ascending' # descending: 'Descending' + # sort: 'Sort' view: left_menu: back_to_top: 'Tornar en naut' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml index 0f0d8378..77b93403 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml @@ -260,12 +260,16 @@ entry: sort: # title: 'Sort options' # status_label: 'Sort by' + # order_label: 'Order' # by: - # creation_date: 'Creation date' - # title: 'Title' - # last_updated: 'Last updated' - #ascending: 'Asencending' + # creation_date: 'Creation date' + # starred_date: 'Starred date' + # archive_date: 'Archived date' + # title: 'Title' + # last_updated: 'Last updated' + # ascending: 'Ascending' # descending: 'Descending' + # sort: 'Sort' view: left_menu: back_to_top: 'Wróć na górę' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml index 5a403c23..dd34d579 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml @@ -260,12 +260,16 @@ entry: sort: # title: 'Sort options' # status_label: 'Sort by' + # order_label: 'Order' # by: - # creation_date: 'Creation date' - # title: 'Title' - # last_updated: 'Last updated' - #ascending: 'Asencending' + # creation_date: 'Creation date' + # starred_date: 'Starred date' + # archive_date: 'Archived date' + # title: 'Title' + # last_updated: 'Last updated' + # ascending: 'Ascending' # descending: 'Descending' + # sort: 'Sort' view: left_menu: back_to_top: 'Voltar ao topo' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml index 55fcead7..0991c373 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml @@ -260,12 +260,16 @@ entry: sort: # title: 'Sort options' # status_label: 'Sort by' + # order_label: 'Order' # by: - # creation_date: 'Creation date' - # title: 'Title' - # last_updated: 'Last updated' - #ascending: 'Asencending' + # creation_date: 'Creation date' + # starred_date: 'Starred date' + # archive_date: 'Archived date' + # title: 'Title' + # last_updated: 'Last updated' + # ascending: 'Ascending' # descending: 'Descending' + # sort: 'Sort' view: left_menu: # back_to_top: 'Back to top' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.ru.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.ru.yml index f593a037..d151e351 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.ru.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.ru.yml @@ -256,6 +256,19 @@ entry: action: clear: 'Очистить' filter: 'Выбрать' + sort: + # title: 'Sort options' + # status_label: 'Sort by' + # order_label: 'Order' + # by: + # creation_date: 'Creation date' + # starred_date: 'Starred date' + # archive_date: 'Archived date' + # title: 'Title' + # last_updated: 'Last updated' + # ascending: 'Ascending' + # descending: 'Descending' + # sort: 'Sort' view: left_menu: back_to_top: 'Наверх' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.th.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.th.yml index fa013e55..30364443 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.th.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.th.yml @@ -256,6 +256,19 @@ entry: action: clear: 'ล้าง' filter: 'ตัวกรอง' + sort: + # title: 'Sort options' + # status_label: 'Sort by' + # order_label: 'Order' + # by: + # creation_date: 'Creation date' + # starred_date: 'Starred date' + # archive_date: 'Archived date' + # title: 'Title' + # last_updated: 'Last updated' + # ascending: 'Ascending' + # descending: 'Descending' + # sort: 'Sort' view: left_menu: back_to_top: 'กลับไปข้างบน' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml index 0f5655fa..84a48f5b 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml @@ -260,12 +260,16 @@ entry: sort: # title: 'Sort options' # status_label: 'Sort by' + # order_label: 'Order' # by: - # creation_date: 'Creation date' - # title: 'Title' - # last_updated: 'Last updated' - #ascending: 'Asencending' + # creation_date: 'Creation date' + # starred_date: 'Starred date' + # archive_date: 'Archived date' + # title: 'Title' + # last_updated: 'Last updated' + # ascending: 'Ascending' # descending: 'Descending' + # sort: 'Sort' view: left_menu: # back_to_top: 'Back to top' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.zh.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.zh.yml index e68b91b7..dad26cba 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.zh.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.zh.yml @@ -236,6 +236,19 @@ entry: action: clear: '清除' filter: '筛选' + sort: + # title: 'Sort options' + # status_label: 'Sort by' + # order_label: 'Order' + # by: + # creation_date: 'Creation date' + # starred_date: 'Starred date' + # archive_date: 'Archived date' + # title: 'Title' + # last_updated: 'Last updated' + # ascending: 'Ascending' + # descending: 'Descending' + # sort: 'Sort' view: left_menu: back_to_top: '返回顶部' diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 15f05d48..765c108e 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -1041,7 +1041,7 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertSame('test title entry' . $ids[$key], $result); } - rsort($ids); + $ids = array_reverse($ids); $crawler = $client->request('GET', '/unread/list'); $form = $crawler->filter('button[id=submit-sort]')->form(); @@ -1061,6 +1061,201 @@ class EntryControllerTest extends WallabagCoreTestCase } } + public function testSortOnCreationDate() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $entry1 = new Entry($this->getLoggedInUser()); + $entry1->setTitle('test title entry7'); + $entry1->setCreatedAt(new \DateTime('2013-04-03T13:37:00')); + $this->getEntityManager()->persist($entry1); + + $entry2 = new Entry($this->getLoggedInUser()); + $entry2->setTitle('test title entry8'); + $entry2->setCreatedAt(new \DateTime('2012-04-03T13:37:00')); + $this->getEntityManager()->persist($entry2); + + $entry3 = new Entry($this->getLoggedInUser()); + $entry3->setTitle('test title entry9'); + $entry3->setCreatedAt(new \DateTime('2014-04-03T13:37:00')); + $this->getEntityManager()->persist($entry3); + + $this->getEntityManager()->flush(); + + $crawler = $client->request('GET', '/unread/list'); + $form = $crawler->filter('button[id=submit-sort]')->form(); + $data = [ + 'entry_sort[sortType]' => 'createdAt', + 'entry_sort[sortOrder]' => 'asc', + ]; + $crawler = $client->submit($form, $data); + + $this->assertCount(7, $crawler->filter('li.entry')); + + $matches = []; + preg_match_all('/test title entry([0-9])/', $client->getResponse()->getContent(), $matches); + + $results = array_values(array_unique($matches[0])); + + $ids = [8, 7, 9, 1, 2, 4, 5]; + + foreach ($results as $key => $result) { + $this->assertSame('test title entry' . $ids[$key], $result); + } + + $ids = array_reverse($ids); + + $crawler = $client->request('GET', '/unread/list'); + $form = $crawler->filter('button[id=submit-sort]')->form(); + $data = [ + 'entry_sort[sortType]' => 'createdAt', + 'entry_sort[sortOrder]' => 'desc', + ]; + $crawler = $client->submit($form, $data); + + $matches = []; + preg_match_all('/test title entry([0-9])/', $client->getResponse()->getContent(), $matches); + + $results = array_values(array_unique($matches[0])); + + foreach ($results as $key => $result) { + $this->assertSame('test title entry' . $ids[$key], $result); + } + } + + public function testSortOnStarredDate() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $entry1 = new Entry($this->getLoggedInUser()); + $entry1->setTitle('test title entry7'); + $entry1->setStarred(true); + $entry1->setStarredAt(new \DateTime('2013-04-03T13:37:00')); + $this->getEntityManager()->persist($entry1); + + $entry2 = new Entry($this->getLoggedInUser()); + $entry2->setTitle('test title entry8'); + $entry2->setStarred(true); + $entry2->setStarredAt(new \DateTime('2012-04-03T13:37:00')); + $this->getEntityManager()->persist($entry2); + + $entry3 = new Entry($this->getLoggedInUser()); + $entry3->setTitle('test title entry9'); + $entry3->setStarred(true); + $entry3->setStarredAt(new \DateTime('2014-04-03T13:37:00')); + $this->getEntityManager()->persist($entry3); + + $this->getEntityManager()->flush(); + + $crawler = $client->request('GET', '/starred/list'); + $form = $crawler->filter('button[id=submit-sort]')->form(); + $data = [ + 'entry_sort[sortType]' => 'starredAt', + 'entry_sort[sortOrder]' => 'asc', + ]; + $crawler = $client->submit($form, $data); + + $this->assertCount(4, $crawler->filter('li.entry')); + + $matches = []; + preg_match_all('/test title entry([0-9])/', $client->getResponse()->getContent(), $matches); + + $results = array_values(array_unique($matches[0])); + + $ids = [5, 8, 7, 9]; + + foreach ($results as $key => $result) { + $this->assertSame('test title entry' . $ids[$key], $result); + } + + $ids = array_reverse($ids); + + $crawler = $client->request('GET', '/starred/list'); + $form = $crawler->filter('button[id=submit-sort]')->form(); + $data = [ + 'entry_sort[sortType]' => 'starredAt', + 'entry_sort[sortOrder]' => 'desc', + ]; + $crawler = $client->submit($form, $data); + + $matches = []; + preg_match_all('/test title entry([0-9])/', $client->getResponse()->getContent(), $matches); + + $results = array_values(array_unique($matches[0])); + + foreach ($results as $key => $result) { + $this->assertSame('test title entry' . $ids[$key], $result); + } + } + + public function testSortOnArchivedDate() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $entry1 = new Entry($this->getLoggedInUser()); + $entry1->setTitle('test title entry7'); + $entry1->setArchived(true); + $entry1->setArchivedAt(new \DateTime('2010-04-03T13:37:00')); + $this->getEntityManager()->persist($entry1); + + $entry2 = new Entry($this->getLoggedInUser()); + $entry2->setTitle('test title entry8'); + $entry2->setArchived(true); + $entry2->setArchivedAt(new \DateTime('2000-04-03T13:37:00')); + $this->getEntityManager()->persist($entry2); + + $entry3 = new Entry($this->getLoggedInUser()); + $entry3->setTitle('test title entry9'); + $entry3->setArchived(true); + $entry3->setArchivedAt(new \DateTime('2020-04-03T13:37:00')); + $this->getEntityManager()->persist($entry3); + + $this->getEntityManager()->flush(); + + $crawler = $client->request('GET', '/archive/list'); + $form = $crawler->filter('button[id=submit-sort]')->form(); + $data = [ + 'entry_sort[sortType]' => 'archivedAt', + 'entry_sort[sortOrder]' => 'asc', + ]; + $crawler = $client->submit($form, $data); + + $this->assertCount(4, $crawler->filter('li.entry')); + + $matches = []; + preg_match_all('/test title entry([0-9])/', $client->getResponse()->getContent(), $matches); + + $results = array_values(array_unique($matches[0])); + + $ids = [6, 8, 7, 9]; + + foreach ($results as $key => $result) { + $this->assertSame('test title entry' . $ids[$key], $result); + } + + $ids = array_reverse($ids); + + $crawler = $client->request('GET', '/archive/list'); + $form = $crawler->filter('button[id=submit-sort]')->form(); + $data = [ + 'entry_sort[sortType]' => 'archivedAt', + 'entry_sort[sortOrder]' => 'desc', + ]; + $crawler = $client->submit($form, $data); + + $matches = []; + preg_match_all('/test title entry([0-9])/', $client->getResponse()->getContent(), $matches); + + $results = array_values(array_unique($matches[0])); + + foreach ($results as $key => $result) { + $this->assertSame('test title entry' . $ids[$key], $result); + } + } + public function testShareEntryPublicly() { $this->logInAs('admin'); -- 2.41.0