From 074110ca2dd3ba0d58f2fa93076933d06b46df77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 24 Apr 2020 16:06:06 +0200 Subject: First draft for tests --- .../CoreBundle/Controller/EntryController.php | 16 +++++--- .../Resources/translations/messages.en.yml | 1 + .../views/themes/material/Entry/entries.html.twig | 4 +- .../CoreBundle/Controller/EntryControllerTest.php | 46 ++++++++++++++++++++++ 4 files changed, 59 insertions(+), 8 deletions(-) diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index 6e56c237..56759adb 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -532,13 +532,17 @@ class EntryController extends Controller $repository = $this->get('wallabag_core.entry_repository'); $searchTerm = (isset($request->get('search_entry')['term']) ? $request->get('search_entry')['term'] : ''); $currentRoute = (null !== $request->query->get('currentRoute') ? $request->query->get('currentRoute') : ''); - $direction = (null !== $request->query->get('entry_sort')['sortOrder'] ? $request->query->get('entry_sort')['sortOrder'] : 'asc'); - - // defined as null by default because each repository method have the right field as default value too - // like `getBuilderForStarredByUser` will have `starredAt` sort by default + $direction = 'asc'; $sortBy = null; - if (\in_array($request->get('entry_sort')['sortType'], ['id', 'title', 'createdAt', 'updatedAt', 'starredAt', 'archivedAt'], true)) { - $sortBy = $request->get('entry_sort')['sortType']; + + if (null !== ($request->query->get('entry_sort'))) { + $direction = (null !== $request->query->get('entry_sort')['sortOrder'] ? $request->query->get('entry_sort')['sortOrder'] : 'asc'); + + // defined as null by default because each repository method have the right field as default value too + // like `getBuilderForStarredByUser` will have `starredAt` sort by default + if (\in_array($request->get('entry_sort')['sortType'], ['id', 'title', 'createdAt', 'updatedAt', 'starredAt', 'archivedAt'], true)) { + $sortBy = $request->get('entry_sort')['sortType']; + } } switch ($type) { diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml index 99425d5a..c7699ef0 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml @@ -267,6 +267,7 @@ entry: 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/views/themes/material/Entry/entries.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig index 505a739b..2c8224bb 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig @@ -211,7 +211,7 @@ {% if sortForm is not null %}
-
+

{{ 'entry.sort.title'|trans }}

@@ -232,7 +232,7 @@
- +
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 0aa562d8..15f05d48 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -1015,6 +1015,52 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertCount(2, $crawler->filter('li.entry')); } + public function testSortOnTitle() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/unread/list'); + $form = $crawler->filter('button[id=submit-sort]')->form(); + $data = [ + 'entry_sort[sortType]' => 'title', + '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 = [1, 2, 4, 5]; + + foreach ($results as $key => $result) { + $this->assertSame('test title entry' . $ids[$key], $result); + } + + rsort($ids); + + $crawler = $client->request('GET', '/unread/list'); + $form = $crawler->filter('button[id=submit-sort]')->form(); + $data = [ + 'entry_sort[sortType]' => 'title', + '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'); -- cgit v1.2.3