diff options
author | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2020-04-24 16:06:06 +0200 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2020-04-28 10:14:46 +0200 |
commit | 074110ca2dd3ba0d58f2fa93076933d06b46df77 (patch) | |
tree | 42b46f8058f78def2dff488725c9c1c3bed0d63f | |
parent | 9b5552290445b404e6de0595d7d27a2de824230a (diff) | |
download | wallabag-074110ca2dd3ba0d58f2fa93076933d06b46df77.tar.gz wallabag-074110ca2dd3ba0d58f2fa93076933d06b46df77.tar.zst wallabag-074110ca2dd3ba0d58f2fa93076933d06b46df77.zip |
First draft for tests
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 | |||
532 | $repository = $this->get('wallabag_core.entry_repository'); | 532 | $repository = $this->get('wallabag_core.entry_repository'); |
533 | $searchTerm = (isset($request->get('search_entry')['term']) ? $request->get('search_entry')['term'] : ''); | 533 | $searchTerm = (isset($request->get('search_entry')['term']) ? $request->get('search_entry')['term'] : ''); |
534 | $currentRoute = (null !== $request->query->get('currentRoute') ? $request->query->get('currentRoute') : ''); | 534 | $currentRoute = (null !== $request->query->get('currentRoute') ? $request->query->get('currentRoute') : ''); |
535 | $direction = (null !== $request->query->get('entry_sort')['sortOrder'] ? $request->query->get('entry_sort')['sortOrder'] : 'asc'); | 535 | $direction = 'asc'; |
536 | |||
537 | // defined as null by default because each repository method have the right field as default value too | ||
538 | // like `getBuilderForStarredByUser` will have `starredAt` sort by default | ||
539 | $sortBy = null; | 536 | $sortBy = null; |
540 | if (\in_array($request->get('entry_sort')['sortType'], ['id', 'title', 'createdAt', 'updatedAt', 'starredAt', 'archivedAt'], true)) { | 537 | |
541 | $sortBy = $request->get('entry_sort')['sortType']; | 538 | if (null !== ($request->query->get('entry_sort'))) { |
539 | $direction = (null !== $request->query->get('entry_sort')['sortOrder'] ? $request->query->get('entry_sort')['sortOrder'] : 'asc'); | ||
540 | |||
541 | // defined as null by default because each repository method have the right field as default value too | ||
542 | // like `getBuilderForStarredByUser` will have `starredAt` sort by default | ||
543 | if (\in_array($request->get('entry_sort')['sortType'], ['id', 'title', 'createdAt', 'updatedAt', 'starredAt', 'archivedAt'], true)) { | ||
544 | $sortBy = $request->get('entry_sort')['sortType']; | ||
545 | } | ||
542 | } | 546 | } |
543 | 547 | ||
544 | switch ($type) { | 548 | 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: | |||
267 | last_updated: 'Last updated' | 267 | last_updated: 'Last updated' |
268 | ascending: 'Ascending' | 268 | ascending: 'Ascending' |
269 | descending: 'Descending' | 269 | descending: 'Descending' |
270 | sort: 'Sort' | ||
270 | view: | 271 | view: |
271 | left_menu: | 272 | left_menu: |
272 | back_to_top: 'Back to top' | 273 | 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 @@ | |||
211 | <!-- Sort --> | 211 | <!-- Sort --> |
212 | {% if sortForm is not null %} | 212 | {% if sortForm is not null %} |
213 | <div id="sort" class="side-nav right-aligned"> | 213 | <div id="sort" class="side-nav right-aligned"> |
214 | <form action="{{ previousRoute }}"> | 214 | <form> |
215 | <h4 class="center">{{ 'entry.sort.title'|trans }}</h4> | 215 | <h4 class="center">{{ 'entry.sort.title'|trans }}</h4> |
216 | 216 | ||
217 | <div class="row"> | 217 | <div class="row"> |
@@ -232,7 +232,7 @@ | |||
232 | </div> | 232 | </div> |
233 | 233 | ||
234 | <div class="col s12"> | 234 | <div class="col s12"> |
235 | <button class="btn waves-effect waves-light" type="submit" id="submit-filter" value="filter">{{ 'entry.filters.action.filter'|trans }}</button> | 235 | <button class="btn waves-effect waves-light" type="submit" id="submit-sort" value="sort">{{ 'entry.sort.action.sort'|trans }}</button> |
236 | </div> | 236 | </div> |
237 | </div> | 237 | </div> |
238 | </form> | 238 | </form> |
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 | |||
1015 | $this->assertCount(2, $crawler->filter('li.entry')); | 1015 | $this->assertCount(2, $crawler->filter('li.entry')); |
1016 | } | 1016 | } |
1017 | 1017 | ||
1018 | public function testSortOnTitle() | ||
1019 | { | ||
1020 | $this->logInAs('admin'); | ||
1021 | $client = $this->getClient(); | ||
1022 | |||
1023 | $crawler = $client->request('GET', '/unread/list'); | ||
1024 | $form = $crawler->filter('button[id=submit-sort]')->form(); | ||
1025 | $data = [ | ||
1026 | 'entry_sort[sortType]' => 'title', | ||
1027 | 'entry_sort[sortOrder]' => 'asc', | ||
1028 | ]; | ||
1029 | $crawler = $client->submit($form, $data); | ||
1030 | |||
1031 | $this->assertCount(4, $crawler->filter('li.entry')); | ||
1032 | |||
1033 | $matches = []; | ||
1034 | preg_match_all('/test title entry([0-9])/', $client->getResponse()->getContent(), $matches); | ||
1035 | |||
1036 | $results = array_values(array_unique($matches[0])); | ||
1037 | |||
1038 | $ids = [1, 2, 4, 5]; | ||
1039 | |||
1040 | foreach ($results as $key => $result) { | ||
1041 | $this->assertSame('test title entry' . $ids[$key], $result); | ||
1042 | } | ||
1043 | |||
1044 | rsort($ids); | ||
1045 | |||
1046 | $crawler = $client->request('GET', '/unread/list'); | ||
1047 | $form = $crawler->filter('button[id=submit-sort]')->form(); | ||
1048 | $data = [ | ||
1049 | 'entry_sort[sortType]' => 'title', | ||
1050 | 'entry_sort[sortOrder]' => 'desc', | ||
1051 | ]; | ||
1052 | $crawler = $client->submit($form, $data); | ||
1053 | |||
1054 | $matches = []; | ||
1055 | preg_match_all('/test title entry([0-9])/', $client->getResponse()->getContent(), $matches); | ||
1056 | |||
1057 | $results = array_values(array_unique($matches[0])); | ||
1058 | |||
1059 | foreach ($results as $key => $result) { | ||
1060 | $this->assertSame('test title entry' . $ids[$key], $result); | ||
1061 | } | ||
1062 | } | ||
1063 | |||
1018 | public function testShareEntryPublicly() | 1064 | public function testShareEntryPublicly() |
1019 | { | 1065 | { |
1020 | $this->logInAs('admin'); | 1066 | $this->logInAs('admin'); |