Tests: Add CourseHomeControllerTest.php

pull/3959/head
Julio 3 years ago
parent 183ab2bef3
commit 3505aafc39
  1. 5
      src/CoreBundle/Controller/CourseHomeController.php
  2. 15
      src/CoreBundle/Resources/views/Course/welcome.html.twig
  3. 48
      tests/CoreBundle/Controller/CourseHomeControllerTest.php

@ -49,6 +49,7 @@ class CourseHomeController extends ToolBaseController
public function indexJsonAction(Request $request, CToolRepository $toolRepository, CShortcutRepository $shortcutRepository, ToolChain $toolChain): Response public function indexJsonAction(Request $request, CToolRepository $toolRepository, CShortcutRepository $shortcutRepository, ToolChain $toolChain): Response
{ {
$course = $this->getCourse(); $course = $this->getCourse();
if (null === $course) { if (null === $course) {
throw $this->createAccessDeniedException(); throw $this->createAccessDeniedException();
} }
@ -248,6 +249,10 @@ class CourseHomeController extends ToolBaseController
$tool = $toolChain->getToolFromName($tool->getTool()->getName()); $tool = $toolChain->getToolFromName($tool->getTool()->getName());
$link = $tool->getLink(); $link = $tool->getLink();
if (null === $this->getCourse()) {
throw new NotFoundHttpException($this->trans('Course not found'));
}
if (strpos($link, 'nodeId')) { if (strpos($link, 'nodeId')) {
$nodeId = (string) $this->getCourse()->getResourceNode()->getId(); $nodeId = (string) $this->getCourse()->getResourceNode()->getId();
$link = str_replace(':nodeId', $nodeId, $link); $link = str_replace(':nodeId', $nodeId, $link);

@ -4,16 +4,15 @@
{% autoescape false %} {% autoescape false %}
<div class="start-course"> <div class="start-course">
<div class="image-course"> <div class="image-course">
<img src="{{ course.course_image_large }}" class="img-fluid"/> <img src="{{ course }}" class="img-fluid"/>
</div> </div>
<div class="description-course"> <div class="description-course">
{% if course.categoryName %}
<h5>{{ course.categoryName }}</h5> <h2><a href="">{{ course.title }}</a></h2>
{% endif %}
<h2><a href="{{ course_url }}">{{ course_title }}</a></h2> <a role="button" href="{{ course.title }}" class="btn btn-primary btn-lg">
{% if just_created == 1%} {{ "Go to the course created"|trans }}</a>
<a role="button" href="{{ course_url }}" class="btn btn-primary btn-lg">{{ "Go to the course created"|trans }}</a>
{% endif %}
</div> </div>
<div class="start-info"> <div class="start-info">
<h3>{{ 'Things to do'|trans }}</h3> <h3>{{ 'Things to do'|trans }}</h3>

@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\Tests\CoreBundle\Controller;
use Chamilo\Tests\AbstractApiTest;
use Chamilo\Tests\ChamiloTestTrait;
class CourseHomeControllerTest extends AbstractApiTest
{
use ChamiloTestTrait;
public function testIndexJsonAction(): void
{
$course = $this->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'
);
}
}
Loading…
Cancel
Save