pull/4042/head
Julio 4 years ago
parent 9e98392062
commit fd60f2f548
  1. 16
      src/CoreBundle/Entity/ResourceNode.php
  2. 18
      tests/ChamiloTestTrait.php
  3. 4
      tests/CoreBundle/Repository/Node/CourseRepositoryTest.php
  4. 1
      tests/CoreBundle/Repository/Node/UsergroupRepositoryTest.php
  5. 133
      tests/CoreBundle/Repository/ResourceNodeRepositoryTest.php
  6. 6
      tests/CoreBundle/Repository/SessionRepositoryTest.php
  7. 11
      tests/CoreBundle/Repository/SysAnnouncementRepositoryTest.php
  8. 6
      tests/CoreBundle/Repository/TagRepositoryTest.php
  9. 2
      tests/CoreBundle/Repository/TrackExerciseRepositoryTest.php
  10. 3
      tests/CoreBundle/Tool/ToolChainTest.php
  11. 3
      tests/CourseBundle/Repository/CCalendarEventAttachmentRepositoryTest.php
  12. 6
      tests/CourseBundle/Repository/CCourseDescriptionRepositoryTest.php
  13. 6
      tests/CourseBundle/Repository/CDocumentRepositoryTest.php
  14. 10
      tests/CourseBundle/Repository/CGroupRepositoryTest.php
  15. 28
      tests/CourseBundle/Repository/CStudentPublicationRepositoryTest.php
  16. 4
      tests/CourseBundle/Repository/CSurveyRepositoryTest.php
  17. 2
      tests/CourseBundle/Repository/CThematicAdvanceRepositoryTest.php
  18. 2
      tests/CourseBundle/Repository/CThematicPlanRepositoryTest.php

@ -18,7 +18,6 @@ use Chamilo\CourseBundle\Entity\CShortcut;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use InvalidArgumentException;
@ -465,21 +464,6 @@ class ResourceNode
return $this;
}
/**
* @return Collection|ResourceLink[]
*/
public function hasSession(Session $session = null)
{
$links = $this->getResourceLinks();
$criteria = Criteria::create();
$criteria->andWhere(
Criteria::expr()->eq('session', $session)
);
return $links->matching($criteria);
}
public function hasResourceFile(): bool
{
return null !== $this->resourceFile;

@ -6,6 +6,7 @@ use Chamilo\CoreBundle\Entity\AccessUrl;
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CoreBundle\Entity\User;
use Chamilo\CoreBundle\Entity\Usergroup;
use Chamilo\CoreBundle\Repository\Node\AccessUrlRepository;
use Chamilo\CoreBundle\Repository\Node\CourseRepository;
use Chamilo\CoreBundle\Repository\Node\UserRepository;
@ -97,6 +98,23 @@ trait ChamiloTestTrait
return $group;
}
public function createUserGroup(string $title): ?Usergroup
{
$em = $this->getEntityManager();
$creator = $this->createUser('usergroup_creator');
$group = (new Usergroup())
->setName($title)
->setDescription('desc')
->setCreator($creator)
->addAccessUrl($this->getAccessUrl())
;
$em->persist($group);
$em->flush();
return $group;
}
/**
* Finds a user registered in the test DB, added by the DataFixtures classes.
*/

@ -84,8 +84,8 @@ class CourseRepositoryTest extends AbstractApiTest
;
$courseRepo->create($course);
/** @var Course $course */
$course = $courseRepo->find($course->getId());
$course = $this->getCourse($course->getId());
$this->assertSame('test julio', $course->getName());
$this->assertSame('test julio (TESTJULIO)', $course->getTitleAndCode());
$this->assertSame('TESTJULIO', $course->getCode());

@ -125,6 +125,7 @@ class UsergroupRepositoryTest extends KernelTestCase
$em->persist($group);
$em->flush();
$this->assertNotNull($userGroupRelCourse->getId());
$this->assertSame(1, $group->getCourses()->count());
$this->assertSame(1, $group->getQuestions()->count());
$this->assertSame(1, $group->getSessions()->count());

@ -6,12 +6,16 @@ declare(strict_types=1);
namespace Chamilo\Tests\CoreBundle\Repository;
use Chamilo\CoreBundle\Entity\ResourceComment;
use Chamilo\CoreBundle\Entity\ResourceFile;
use Chamilo\CoreBundle\Entity\ResourceLink;
use Chamilo\CoreBundle\Entity\ResourceNode;
use Chamilo\CoreBundle\Entity\ResourceType;
use Chamilo\CoreBundle\Repository\ResourceNodeRepository;
use Chamilo\Tests\AbstractApiTest;
use Chamilo\Tests\ChamiloTestTrait;
use DateTime;
use Symfony\Component\Routing\RouterInterface;
class ResourceNodeRepositoryTest extends AbstractApiTest
{
@ -19,8 +23,6 @@ class ResourceNodeRepositoryTest extends AbstractApiTest
public function testCreate(): void
{
self::bootKernel();
$em = $this->getEntityManager();
$repo = self::getContainer()->get(ResourceNodeRepository::class);
@ -30,8 +32,54 @@ class ResourceNodeRepositoryTest extends AbstractApiTest
$defaultCount = $repo->count([]);
$type = $repoType->findOneBy(['name' => 'illustrations']);
$resourceNode = (new ResourceNode())
->setContent('test')
->setTitle('test')
->setSlug('test')
->setResourceType($type)
->setCreator($user)
->setPublic(true)
->setParent($user->getResourceNode())
;
$this->assertHasNoEntityViolations($resourceNode);
$em->persist($resourceNode);
$em->flush();
$node = (new ResourceNode())
$this->assertNotNull((string) $resourceNode);
$this->assertSame(2, $resourceNode->getLevel());
$path = $user->getResourceNode()->getSlug().'-'.$user->getResourceNode()->getId().'/'.$resourceNode->getSlug().'-'.$resourceNode->getId().'/';
$this->assertSame($path, $resourceNode->getPathForDisplay());
$array = [
$user->getResourceNode()->getId() => $user->getResourceNode()->getSlug(),
$resourceNode->getId() => $resourceNode->getSlug(),
];
$this->assertSame($array, $resourceNode->getPathForDisplayToArray());
$path = $user->getResourceNode()->getSlug().'/'.$resourceNode->getSlug();
$this->assertSame($path, $resourceNode->getPathForDisplayRemoveBase(''));
$this->assertSame('test', $resourceNode->getSlug());
$this->assertFalse($resourceNode->isResourceFileAnImage());
$this->assertFalse($resourceNode->isResourceFileAVideo());
$this->assertNotEmpty(1, $resourceNode->getIcon());
$router = $this->getContainer()->get(RouterInterface::class);
$this->assertSame('<i class="fa fa-folder fa-3x"></i>', $resourceNode->getThumbnail($router));
$this->assertSame($defaultCount + 1, $repo->count([]));
}
public function testCreateWithComment(): void
{
$em = $this->getEntityManager();
$repo = self::getContainer()->get(ResourceNodeRepository::class);
$repoType = $em->getRepository(ResourceType::class);
$user = $this->createUser('julio');
$type = $repoType->findOneBy(['name' => 'illustrations']);
$resourceNode = (new ResourceNode())
->setContent('test')
->setTitle('test')
->setSlug('test')
@ -39,12 +87,84 @@ class ResourceNodeRepositoryTest extends AbstractApiTest
->setCreator($user)
->setParent($user->getResourceNode())
;
$this->assertHasNoEntityViolations($node);
$em->persist($node);
$em->persist($resourceNode);
$comment = (new ResourceComment())
->setContent('content')
->setAuthor($user)
->setParent(null)
->setCreatedAt(new DateTime())
->setResourceNode($resourceNode)
->setUpdatedAt(new DateTime())
;
$em->persist($comment);
$resourceNode->addComment($comment);
$em->flush();
$this->assertSame($defaultCount + 1, $repo->count([]));
$this->assertNotNull($comment->getResourceNode());
$this->assertSame(1, $resourceNode->getComments()->count());
}
public function testCreateWithResourceLink(): void
{
$em = $this->getEntityManager();
$repo = self::getContainer()->get(ResourceNodeRepository::class);
$repoType = $em->getRepository(ResourceType::class);
$user = $this->createUser('julio');
$student = $this->createUser('student');
$course = $this->createCourse('course');
$session = $this->createSession('session');
$group = $this->createGroup('group', $course);
$userGroup = $this->createUserGroup('group');
$type = $repoType->findOneBy(['name' => 'illustrations']);
$resourceNode = (new ResourceNode())
->setContent('test')
->setTitle('test')
->setSlug('test')
->setResourceType($type)
->setCreator($user)
->setParent($user->getResourceNode())
;
$em->persist($resourceNode);
$link = (new ResourceLink())
->setVisibility(ResourceLink::VISIBILITY_PUBLISHED)
->setResourceNode($resourceNode)
->setUser($student)
->setCourse($course)
->setSession($session)
->setGroup($group)
->setUserGroup($userGroup)
->setCreatedAt(new DateTime())
->setUpdatedAt(new DateTime())
->setStartVisibilityAt(new DateTime())
->setEndVisibilityAt(new DateTime())
;
$em->persist($link);
$em->flush();
$em->clear();
/** @var ResourceNode $resourceNode */
$resourceNode = $repo->find($resourceNode->getId());
$this->assertSame(1, $resourceNode->getResourceLinks()->count());
/** @var ResourceLink $link */
$link = $resourceNode->getResourceLinks()->first();
$this->assertNotNull($link->getStartVisibilityAt());
$this->assertNotNull($link->getEndVisibilityAt());
$this->assertTrue($link->hasSession());
$this->assertTrue($link->hasCourse());
$this->assertTrue($link->hasUser());
$this->assertTrue($link->hasGroup());
$this->assertTrue($link->isPublished());
$this->assertFalse($link->isPending());
$this->assertFalse($link->isDraft());
}
public function testGetResourceNodeFileContent(): void
@ -91,6 +211,7 @@ class ResourceNodeRepositoryTest extends AbstractApiTest
$this->assertSame('desc', $resourceFile->getDescription());
$this->assertNotEmpty($resourceFile->getWidth());
$this->assertNotEmpty($resourceFile->getHeight());
$this->assertIsArray($resourceFile->getMetadata());
$content = $repo->getResourceNodeFileContent($node);
$this->assertNotEmpty($content);

@ -366,7 +366,7 @@ class SessionRepositoryTest extends AbstractApiTest
$this->assertSame(1, $session->getCourses()->count());
// 3. Add student to session - course.
$course = $courseRepo->find($course->getId());
$course = $this->getCourse($course->getId());
/** @var User $user */
$user = $userRepo->find($user->getId());
@ -425,8 +425,6 @@ class SessionRepositoryTest extends AbstractApiTest
public function testGeneralCoachesInSession(): void
{
self::bootKernel();
$sessionRepo = self::getContainer()->get(SessionRepository::class);
$session = $this->createSession('test for general coaches');
@ -443,8 +441,6 @@ class SessionRepositoryTest extends AbstractApiTest
public function testAdminInSession(): void
{
self::bootKernel();
$sessionRepo = self::getContainer()->get(SessionRepository::class);
$session = $this->createSession('test for session admin');

@ -38,12 +38,15 @@ class SysAnnouncementRepositoryTest extends WebTestCase
$this->assertSame(1, $count);
$em = $this->getEntityManager();
$sysAnnouncement = (new SysAnnouncement())
->setTitle('Welcome to Chamilo!')
->setContent('content')
->setLang('lang')
->setUrl($this->getAccessUrl())
->setDateStart(new DateTime())
->setDateEnd(new DateTime('now +30 days'))
->setRoles(['ROLE_ANOTHER'])
->addRole('ROLE_ANONYMOUS')
->addRole('ROLE_USER') // connected users
;
@ -52,6 +55,11 @@ class SysAnnouncementRepositoryTest extends WebTestCase
$repo->update($sysAnnouncement);
$this->assertNotNull($sysAnnouncement->getDateStart());
$this->assertNotNull($sysAnnouncement->getDateEnd());
$this->assertNotNull($sysAnnouncement->getLang());
$this->assertCount(3, $sysAnnouncement->getRoles());
$this->assertTrue($sysAnnouncement->isVisible());
$this->assertSame(2, $repo->count([]));
$repo->delete($sysAnnouncement->getId());
@ -73,7 +81,7 @@ class SysAnnouncementRepositoryTest extends WebTestCase
$repo = self::getContainer()->get(SysAnnouncementRepository::class);
$user = $this->getUser('admin');
$items = $repo->getAnnouncements($user, $this->getAccessUrl(), '');
$this->assertSame(1, \count($items));
$this->assertCount(1, $items);
$career = (new Career())
->setName('Doctor')
@ -95,6 +103,7 @@ class SysAnnouncementRepositoryTest extends WebTestCase
->setDateStart(new DateTime())
->setDateEnd(new DateTime('now +30 days'))
->setCareer($career)
->setPromotion($promotion)
->addRole('ROLE_ANONYMOUS')
->addRole('ROLE_USER') // connected users
;

@ -44,6 +44,9 @@ class TagRepositoryTest extends AbstractApiTest
$em->persist($tag);
$em->flush();
$this->assertSame('php', $tag->getTag());
$this->assertSame(0, $tag->getUserRelTags()->count());
$this->assertSame(1, $repo->count([]));
$tags = $repo->findTagsByField('php', $extraField);
@ -78,6 +81,9 @@ class TagRepositoryTest extends AbstractApiTest
->setTag($tag)
;
$em->persist($userRelTag);
$tag->getUserRelTags()->add($userRelTag);
$em->flush();
$em->clear();

@ -215,9 +215,9 @@ class TrackExerciseRepositoryTest extends AbstractApiTest
$this->assertSame(1, $trackExercise->getAttempts()->count());
$this->assertInstanceOf(TrackEAttempt::class, $trackExercise->getAttemptByQuestionId(1));
$this->assertNull($trackExercise->getAttemptByQuestionId(99));
$file = $this->getUploadedFile();
$em = $this->getEntityManager();
// Create asset.

@ -168,6 +168,7 @@ class ToolChainTest extends AbstractApiTest
;
$this->assertHasNoEntityViolations($resourceType);
$em->persist($resourceType);
$collection = new ArrayCollection();
$collection->add($resourceType);
@ -178,5 +179,7 @@ class ToolChainTest extends AbstractApiTest
$this->assertHasNoEntityViolations($tool);
$em->persist($tool);
$em->flush();
$this->assertNotNull($resourceType->getId());
}
}

@ -20,7 +20,6 @@ class CCalendarEventAttachmentRepositoryTest extends AbstractApiTest
public function testCreateEvent(): void
{
self::bootKernel();
$user = $this->createUser('test');
$course = $this->createCourse('new');
@ -55,6 +54,8 @@ class CCalendarEventAttachmentRepositoryTest extends AbstractApiTest
->addCourseLink($course)
;
$event->addAttachment($attachment);
$this->assertHasNoEntityViolations($attachment);
$repoAttachment->create($attachment);

@ -17,8 +17,6 @@ class CCourseDescriptionRepositoryTest extends AbstractApiTest
public function testCreate(): void
{
self::bootKernel();
$em = $this->getEntityManager();
$repo = self::getContainer()->get(CCourseDescriptionRepository::class);
@ -38,13 +36,13 @@ class CCourseDescriptionRepositoryTest extends AbstractApiTest
$em->flush();
$this->assertSame('title', (string) $item);
$this->assertNotNull($item->getProgress());
$this->assertSame($item->getIid(), $item->getResourceIdentifier());
$this->assertSame(1, $repo->count([]));
}
public function testGetDescriptions(): void
{
self::bootKernel();
$repo = self::getContainer()->get(CCourseDescriptionRepository::class);
$em = $this->getEntityManager();

@ -463,7 +463,7 @@ class CDocumentRepositoryTest extends AbstractApiTest
// Update course visibility to REGISTERED
$courseRepo = self::getContainer()->get(CourseRepository::class);
$course = $courseRepo->find($courseId);
$course = $this->getCourse($courseId);
$course->setVisibility(Course::REGISTERED);
$courseRepo->update($course);
@ -490,7 +490,7 @@ class CDocumentRepositoryTest extends AbstractApiTest
// Update course visibility to CLOSED
$courseRepo = self::getContainer()->get(CourseRepository::class);
$course = $courseRepo->find($courseId);
$course = $this->getCourse($courseId);
$course->setVisibility(Course::CLOSED);
$courseRepo->update($course);
@ -508,7 +508,7 @@ class CDocumentRepositoryTest extends AbstractApiTest
// Update course visibility to HIDDEN
$courseRepo = self::getContainer()->get(CourseRepository::class);
$course = $courseRepo->find($courseId);
$course = $this->getCourse($courseId);
$course->setVisibility(Course::HIDDEN);
$courseRepo->update($course);

@ -50,7 +50,11 @@ class CGroupRepositoryTest extends AbstractApiTest
$em->persist($item);
$em->flush();
$this->assertTrue($item->getSelfRegistrationAllowed());
$this->assertTrue($item->getSelfUnregistrationAllowed());
$this->assertSame(1, $repo->count([]));
$this->assertNotNull($repo->findOneByTitle('Group'));
$repo->delete($item);
@ -118,6 +122,9 @@ class CGroupRepositoryTest extends AbstractApiTest
$em->persist($group);
$em->flush();
$this->assertFalse($group->hasTutors());
$this->assertFalse($group->hasMembers());
$groupRelUser = (new CGroupRelUser())
->setStatus(1)
->setUser($student)
@ -140,6 +147,7 @@ class CGroupRepositoryTest extends AbstractApiTest
/** @var CGroup $group */
$group = $groupRepo->find($group->getIid());
$this->assertSame($group->getResourceIdentifier(), $group->getIid());
$this->assertSame(1, $group->getMembers()->count());
$this->assertSame(1, $group->getTutors()->count());
@ -153,7 +161,7 @@ class CGroupRepositoryTest extends AbstractApiTest
$this->assertSame(1, $groupRepo->count([]));
$this->assertNotNull($groupRepo->findOneByTitle('Group'));
$course = $courseRepo->find($course->getId());
$course = $this->getCourse($course->getId());
$courseRepo->delete($course);
$this->assertSame(0, $groupRepo->count([]));

@ -6,7 +6,9 @@ declare(strict_types=1);
namespace Chamilo\Tests\CourseBundle\Repository;
use Chamilo\CoreBundle\Repository\Node\CourseRepository;
use Chamilo\CourseBundle\Entity\CStudentPublication;
use Chamilo\CourseBundle\Entity\CStudentPublicationRelUser;
use Chamilo\CourseBundle\Repository\CStudentPublicationRepository;
use Chamilo\Tests\AbstractApiTest;
use Chamilo\Tests\ChamiloTestTrait;
@ -54,15 +56,19 @@ class CStudentPublicationRepositoryTest extends AbstractApiTest
$this->assertSame(1, $repo->count([]));
}
public function testCreateWithAssignment(): void
public function testCreateWithPublicationRelUser(): void
{
$em = $this->getEntityManager();
$repo = self::getContainer()->get(CStudentPublicationRepository::class);
$courseRepo = self::getContainer()->get(CourseRepository::class);
$publicationRelUserRepo = $em->getRepository(CStudentPublicationRelUser::class);
$course = $this->createCourse('new');
$teacher = $this->createUser('teacher');
$student = $this->createUser('student');
$item = (new CStudentPublication())
$publication = (new CStudentPublication())
->setTitle('publi')
->setDescription('desc')
->setParent($course)
@ -70,10 +76,26 @@ class CStudentPublicationRepositoryTest extends AbstractApiTest
->setWeight(100)
->setCreator($teacher)
;
$em->persist($item);
$em->persist($publication);
$pubRelUser = (new CStudentPublicationRelUser())
->setUser($student)
->setPublication($publication)
;
$em->persist($pubRelUser);
$em->flush();
$this->assertSame(1, $repo->count([]));
$this->assertSame(1, $courseRepo->count([]));
$this->assertSame(1, $publicationRelUserRepo->count([]));
$course = $this->getCourse($course->getId());
$courseRepo->delete($course);
$this->assertSame(0, $repo->count([]));
$this->assertSame(0, $courseRepo->count([]));
$this->assertSame(0, $publicationRelUserRepo->count([]));
}
public function testFindAllByCourse(): void

@ -6,7 +6,6 @@ declare(strict_types=1);
namespace Chamilo\Tests\CourseBundle\Repository;
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Repository\Node\CourseRepository;
use Chamilo\CourseBundle\Entity\CSurvey;
use Chamilo\CourseBundle\Entity\CSurveyAnswer;
@ -161,8 +160,7 @@ class CSurveyRepositoryTest extends AbstractApiTest
$this->assertSame(1, $surveyOptionRepo->count([]));
$this->assertSame(1, $courseRepo->count([]));
/** @var Course $course */
$course = $courseRepo->find($course->getId());
$course = $this->getCourse($course->getId());
$courseRepo->delete($course);
$this->assertSame(0, $courseRepo->count([]));

@ -160,7 +160,7 @@ class CThematicAdvanceRepositoryTest extends AbstractApiTest
$this->assertSame(1, $attendanceRepo->count([]));
$this->assertSame(1, $advanceRepo->count([]));
$course = $courseRepo->find($course->getId());
$course = $this->getCourse($course->getId());
$courseRepo->delete($course);
$this->assertSame(0, $courseRepo->count([]));

@ -99,7 +99,7 @@ class CThematicPlanRepositoryTest extends AbstractApiTest
$this->assertSame(1, $planRepo->count([]));
$this->assertSame(1, $courseRepo->count([]));
$course = $courseRepo->find($course->getId());
$course = $this->getCourse($course->getId());
$courseRepo->delete($course);
$this->assertSame(0, $thematicRepo->count([]));

Loading…
Cancel
Save