From b814cf51e4024b6c4c95dcffa00d308570644a9e Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Tue, 12 May 2020 00:12:49 +0200 Subject: [PATCH] News: Preselect "Is Meeting" when adding from Meeting overview --- resources/views/pages/news/edit.twig | 2 +- resources/views/pages/news/overview.twig | 5 +-- src/Controllers/Admin/NewsController.php | 3 +- .../Controllers/Admin/NewsControllerTest.php | 36 +++++++++++++++++++ 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/resources/views/pages/news/edit.twig b/resources/views/pages/news/edit.twig index 52b2aaae..920bec0c 100644 --- a/resources/views/pages/news/edit.twig +++ b/resources/views/pages/news/edit.twig @@ -41,7 +41,7 @@ ) }}
- {{ f.checkbox('is_meeting', __('news.edit.is_meeting'), news ? news.is_meeting : false) }} + {{ f.checkbox('is_meeting', __('news.edit.is_meeting'), is_meeting) }}
diff --git a/resources/views/pages/news/overview.twig b/resources/views/pages/news/overview.twig index d14d853d..e30cc192 100644 --- a/resources/views/pages/news/overview.twig +++ b/resources/views/pages/news/overview.twig @@ -1,14 +1,15 @@ {% extends 'layouts/app.twig' %} {% import 'macros/base.twig' as m %} -{% block title %}{{ not only_meetings|default(false) ? __('news.title') : __('news.title.meetings') }}{% endblock %} +{% set only_meetings = only_meetings|default(false) %} +{% block title %}{{ not only_meetings ? __('news.title') : __('news.title.meetings') }}{% endblock %} {% block content %}

{{ block('title') }} {%- if has_permission_to('admin_news') and is_overview|default(false) -%} - {{ m.button(__('news.add'), url('admin/news')) }} + {{ m.button(__('news.add'), url('admin/news', only_meetings ? {'meeting': 1} : {})) }} {%- endif %}

diff --git a/src/Controllers/Admin/NewsController.php b/src/Controllers/Admin/NewsController.php index 05f1ea3c..ec1b7fd2 100644 --- a/src/Controllers/Admin/NewsController.php +++ b/src/Controllers/Admin/NewsController.php @@ -64,6 +64,7 @@ class NewsController extends BaseController { $id = $request->getAttribute('id'); $news = $this->news->find($id); + $isMeeting = $request->get('meeting', false); if ( $news @@ -75,7 +76,7 @@ class NewsController extends BaseController return $this->response->withView( 'pages/news/edit.twig', - ['news' => $news] + $this->getNotifications() + ['news' => $news, 'is_meeting' => $news ? $news->is_meeting : $isMeeting] + $this->getNotifications(), ); } diff --git a/tests/Unit/Controllers/Admin/NewsControllerTest.php b/tests/Unit/Controllers/Admin/NewsControllerTest.php index 00018f8b..ab3ef357 100644 --- a/tests/Unit/Controllers/Admin/NewsControllerTest.php +++ b/tests/Unit/Controllers/Admin/NewsControllerTest.php @@ -106,6 +106,42 @@ class NewsControllerTest extends TestCase $controller->edit($this->request); } + /** + * @covers \Engelsystem\Controllers\Admin\NewsController::edit + */ + public function testEditIsMeeting() + { + $isMeeting = false; + $this->response->expects($this->exactly(3)) + ->method('withView') + ->willReturnCallback( + function ($view, $data) use (&$isMeeting) { + $this->assertEquals($isMeeting, $data['is_meeting']); + $isMeeting = !$isMeeting; + + return $this->response; + } + ); + $this->auth->expects($this->once()) + ->method('can') + ->with('admin_news_html') + ->willReturn(true); + + /** @var NewsController $controller */ + $controller = $this->app->make(NewsController::class); + + // Is no meeting + $controller->edit($this->request); + + // Is meeting + $this->request->query->set('meeting', 1); + $controller->edit($this->request); + + // Should stay no meeting + $this->request->attributes->set('id', 1); + $controller->edit($this->request); + } + /** * @covers \Engelsystem\Controllers\Admin\NewsController::save */