From 3505aafc3902af4c50bdb20e11832a215d38f7eb Mon Sep 17 00:00:00 2001 From: Julio Date: Fri, 3 Sep 2021 14:08:24 +0200 Subject: [PATCH] Tests: Add CourseHomeControllerTest.php --- .../Controller/CourseHomeController.php | 5 ++ .../Resources/views/Course/welcome.html.twig | 15 +++--- .../Controller/CourseHomeControllerTest.php | 48 +++++++++++++++++++ 3 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 tests/CoreBundle/Controller/CourseHomeControllerTest.php diff --git a/src/CoreBundle/Controller/CourseHomeController.php b/src/CoreBundle/Controller/CourseHomeController.php index f42d2cf96f..59596e8a58 100644 --- a/src/CoreBundle/Controller/CourseHomeController.php +++ b/src/CoreBundle/Controller/CourseHomeController.php @@ -49,6 +49,7 @@ class CourseHomeController extends ToolBaseController public function indexJsonAction(Request $request, CToolRepository $toolRepository, CShortcutRepository $shortcutRepository, ToolChain $toolChain): Response { $course = $this->getCourse(); + if (null === $course) { throw $this->createAccessDeniedException(); } @@ -248,6 +249,10 @@ class CourseHomeController extends ToolBaseController $tool = $toolChain->getToolFromName($tool->getTool()->getName()); $link = $tool->getLink(); + if (null === $this->getCourse()) { + throw new NotFoundHttpException($this->trans('Course not found')); + } + if (strpos($link, 'nodeId')) { $nodeId = (string) $this->getCourse()->getResourceNode()->getId(); $link = str_replace(':nodeId', $nodeId, $link); diff --git a/src/CoreBundle/Resources/views/Course/welcome.html.twig b/src/CoreBundle/Resources/views/Course/welcome.html.twig index 126fb6a3ee..571be676c4 100644 --- a/src/CoreBundle/Resources/views/Course/welcome.html.twig +++ b/src/CoreBundle/Resources/views/Course/welcome.html.twig @@ -4,16 +4,15 @@ {% autoescape false %}
- +
- {% if course.categoryName %} -
{{ course.categoryName }}
- {% endif %} -

{{ course_title }}

- {% if just_created == 1%} - {{ "Go to the course created"|trans }} - {% endif %} + +

{{ course.title }}

+ + + {{ "Go to the course created"|trans }} +

{{ 'Things to do'|trans }}

diff --git a/tests/CoreBundle/Controller/CourseHomeControllerTest.php b/tests/CoreBundle/Controller/CourseHomeControllerTest.php new file mode 100644 index 0000000000..63fa282ab0 --- /dev/null +++ b/tests/CoreBundle/Controller/CourseHomeControllerTest.php @@ -0,0 +1,48 @@ +createCourse('course 1'); + $this->getClientWithGuiCredentials('admin', 'admin')->request( + 'GET', + '/course/'.$course->getId().'/home.json' + ); + + $this->assertResponseIsSuccessful(); + $this->assertJsonContains( + [ + 'course' => [ + 'code' => $course->getCode(), + ], + ] + ); + } + + public function testRedirectTool(): void + { + $course = $this->createCourse('new'); + $this->getClientWithGuiCredentials('admin', 'admin')->request( + 'GET', + '/course/'.$course->getId().'/tool/document' + ); + + $this->assertResponseStatusCodeSame(302); + $this->assertResponseHasHeader('location'); + $this->assertResponseRedirects( + '/resources/document/'.$course->getResourceNode()->getId().'/?cid='.$course->getId().'&sid=0&gid=0' + ); + } +}