Merge branch 'master' of github.com:chamilo/chamilo-lms

pull/4004/head
Yannick Warnier 3 years ago
commit 394578957f
  1. 2
      public/main/lp/learnpathList.class.php
  2. 20
      src/CoreBundle/Entity/AbstractResource.php
  3. 17
      tests/CoreBundle/Controller/CourseControllerTest.php

@ -119,7 +119,7 @@ class LearnpathList
$lp->getId(), $lp->getId(),
$session_id $session_id
);*/ );*/
$visibility = $lp->isVisible($course, $session); $visibility = $lp->isVisible($course);
// If option is not true then don't show invisible LP to user // If option is not true then don't show invisible LP to user
if (false === $ignoreLpVisibility) { if (false === $ignoreLpVisibility) {

@ -410,6 +410,12 @@ abstract class AbstractResource
public function isVisible(Course $course, Session $session = null): bool public function isVisible(Course $course, Session $session = null): bool
{ {
$link = $this->getFirstResourceLinkFromCourseSession($course, $session); $link = $this->getFirstResourceLinkFromCourseSession($course, $session);
if (null === $link) {
if ((new ReflectionClass($this))->hasProperty('loadCourseResourcesInSession')) {
$link = $this->getFirstResourceLinkFromCourseSession($course);
}
}
if (null === $link) { if (null === $link) {
return false; return false;
} }
@ -435,19 +441,7 @@ abstract class AbstractResource
$found = false; $found = false;
$link = null; $link = null;
foreach ($links as $link) { foreach ($links as $link) {
if (null === $session) { if ($link->getCourse() === $course && $link->getSession() === $session) {
$found = $link->getCourse() === $course;
break;
}
if ((new ReflectionClass($this))->hasProperty('loadCourseResourcesInSession')) {
$found = $link->getSession() === $session || null === $link->getSession();
break;
}
if ($link->getSession() === $session) {
$found = true; $found = true;
break; break;

@ -7,6 +7,7 @@ declare(strict_types=1);
namespace Chamilo\Tests\CoreBundle\Controller; namespace Chamilo\Tests\CoreBundle\Controller;
use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Repository\Node\CourseRepository;
use Chamilo\CourseBundle\Entity\CCourseDescription; use Chamilo\CourseBundle\Entity\CCourseDescription;
use Chamilo\CourseBundle\Settings\SettingsCourseManager; use Chamilo\CourseBundle\Settings\SettingsCourseManager;
use Chamilo\Tests\ChamiloTestTrait; use Chamilo\Tests\ChamiloTestTrait;
@ -48,14 +49,20 @@ class CourseControllerTest extends WebTestCase
'/course/'.$course->getId().'/home.json' '/course/'.$course->getId().'/home.json'
); );
$this->assertResponseIsSuccessful(); $this->assertResponseIsSuccessful();
}
// Course is REGISTERED. public function testIndexJsonWithAccessRegistered()
$course = $this->getCourse($course->getId()); {
$client = static::createClient();
$em = $this->getEntityManager(); $courseRepo = self::getContainer()->get(CourseRepository::class);
$course = $this->createCourse('course with acess for registered users');
$course->setVisibility(Course::REGISTERED); $course->setVisibility(Course::REGISTERED);
$em->persist($course); $courseRepo->update($course);
$em->flush();
$userTest1 = $this->createUser('test1');
$client->loginUser($userTest1);
$client->request( $client->request(
'GET', 'GET',

Loading…
Cancel
Save