From 38ad4c7d73186260684d46f26229a6e999809568 Mon Sep 17 00:00:00 2001 From: Julio Date: Mon, 1 Nov 2021 09:19:17 +0100 Subject: [PATCH] Minor - add tests --- .../Entity/Listener/CourseListener.php | 13 +++----- .../Entity/Listener/MessageListener.php | 14 -------- .../Entity/Listener/SessionListener.php | 11 +++---- src/CoreBundle/Settings/SettingsManager.php | 14 +++----- .../CCourseSettingRepositoryTest.php | 10 +++++- .../Repository/CForumPostRepositoryTest.php | 2 ++ .../Repository/CGlossaryRepositoryTest.php | 2 ++ .../CGroupCategoryRepositoryTest.php | 16 ++++++++++ .../Repository/CGroupRepositoryTest.php | 32 ++++++++++++++----- .../CLinkCategoryRepositoryTest.php | 15 ++++++--- .../Repository/CLinkRepositoryTest.php | 17 +++++++--- .../Repository/CLpCategoryRepositoryTest.php | 2 ++ .../Repository/CLpItemRepositoryTest.php | 15 +++++++++ .../Repository/CLpRepositoryTest.php | 7 ++++ .../CStudentPublicationRepositoryTest.php | 3 ++ 15 files changed, 117 insertions(+), 56 deletions(-) diff --git a/src/CoreBundle/Entity/Listener/CourseListener.php b/src/CoreBundle/Entity/Listener/CourseListener.php index 88120a1e35..ad0b58a2c9 100644 --- a/src/CoreBundle/Entity/Listener/CourseListener.php +++ b/src/CoreBundle/Entity/Listener/CourseListener.php @@ -74,14 +74,11 @@ class CourseListener $this->checkLimit($repo, $course, $url);*/ } - /** - * @throws Exception - */ - protected function checkLimit(CourseRepository $repo, Course $course, AccessUrl $url): void + /*protected function checkLimit(CourseRepository $repo, Course $course, AccessUrl $url): void { - //$limit = $url->getLimitCourses(); + $limit = $url->getLimitCourses(); - /*if (!empty($limit)) { + if (!empty($limit)) { $count = $repo->getCountCoursesByUrl($url); if ($count >= $limit) { api_warn_hosting_contact('hosting_limit_courses', $limit); @@ -101,6 +98,6 @@ class CourseListener throw new \Exception('PortalActiveCoursesLimitReached'); } } - }*/ - } + } + }*/ } diff --git a/src/CoreBundle/Entity/Listener/MessageListener.php b/src/CoreBundle/Entity/Listener/MessageListener.php index 50fcaab830..4c184bcd6f 100644 --- a/src/CoreBundle/Entity/Listener/MessageListener.php +++ b/src/CoreBundle/Entity/Listener/MessageListener.php @@ -20,16 +20,6 @@ class MessageListener $this->bus = $bus; } - /** - * This code is executed when a new course is created. - * - * new object : prePersist - * edited object: preUpdate - */ - public function prePersist(Message $message, LifecycleEventArgs $args): void - { - } - public function postPersist(Message $message, LifecycleEventArgs $args): void { if ($message) { @@ -49,8 +39,4 @@ class MessageListener } } } - - public function preUpdate(Message $message, LifecycleEventArgs $args): void - { - } } diff --git a/src/CoreBundle/Entity/Listener/SessionListener.php b/src/CoreBundle/Entity/Listener/SessionListener.php index 78366bebd0..c6feb4bf02 100644 --- a/src/CoreBundle/Entity/Listener/SessionListener.php +++ b/src/CoreBundle/Entity/Listener/SessionListener.php @@ -57,20 +57,17 @@ class SessionListener { } - /** - * @throws Exception - */ - protected function checkLimit(SessionRepository $repo, AccessUrl $url): void + /*protected function checkLimit(SessionRepository $repo, AccessUrl $url): void { $limit = $url->getLimitSessions(); if (!empty($limit)) { - /*$count = $repo->getCountSessionByUrl($url); + $count = $repo->getCountSessionByUrl($url); if ($count >= $limit) { api_warn_hosting_contact('hosting_limit_sessions', $limit); throw new \Exception('PortalSessionsLimitReached'); - }*/ + } } - } + }*/ } diff --git a/src/CoreBundle/Settings/SettingsManager.php b/src/CoreBundle/Settings/SettingsManager.php index 5eca6862f3..b8eccd282f 100644 --- a/src/CoreBundle/Settings/SettingsManager.php +++ b/src/CoreBundle/Settings/SettingsManager.php @@ -301,8 +301,7 @@ class SettingsManager implements SettingsManagerInterface $parameter->setCategory($simpleCategoryName); $this->manager->persist($parameter); } else { - $parameter = new SettingsCurrent(); - $parameter + $parameter = (new SettingsCurrent()) ->setVariable($name) ->setCategory($simpleCategoryName) ->setTitle($name) @@ -348,11 +347,9 @@ class SettingsManager implements SettingsManagerInterface } } $settings->setParameters($parameters); - $persistedParameters = $this->repository->findBy( - [ - 'category' => $this->convertServiceToNameSpace($settings->getSchemaAlias()), - ] - ); + $persistedParameters = $this->repository->findBy([ + 'category' => $this->convertServiceToNameSpace($settings->getSchemaAlias()), + ]); $persistedParametersMap = []; foreach ($persistedParameters as $parameter) { $persistedParametersMap[$parameter->getTitle()] = $parameter; @@ -372,8 +369,7 @@ class SettingsManager implements SettingsManagerInterface $parameter = $persistedParametersMap[$name]; $parameter->setSelectedValue($value); } else { - $parameter = new SettingsCurrent(); - $parameter + $parameter = (new SettingsCurrent()) ->setVariable($name) ->setCategory($simpleCategoryName) ->setTitle($name) diff --git a/tests/CourseBundle/Repository/CCourseSettingRepositoryTest.php b/tests/CourseBundle/Repository/CCourseSettingRepositoryTest.php index 9ef81415a9..e40670b293 100644 --- a/tests/CourseBundle/Repository/CCourseSettingRepositoryTest.php +++ b/tests/CourseBundle/Repository/CCourseSettingRepositoryTest.php @@ -31,13 +31,21 @@ class CCourseSettingRepositoryTest extends AbstractApiTest ->setSubkey('subkey') ->setType('type') ->setComment('comment') - ->setSubkeytext('text') + ->setSubkeytext('subkey text') ->setCId($courseId) ; $this->assertHasNoEntityViolations($item); $em->persist($item); $em->flush(); + $this->assertSame('test', $item->getVariable()); + $this->assertSame('subkey', $item->getSubkey()); + $this->assertSame('subkey text', $item->getSubkeytext()); + $this->assertSame('type', $item->getType()); + $this->assertSame('comment', $item->getComment()); + $this->assertSame($courseId, $item->getCId()); + $this->assertSame('test', $item->getTitle()); + $this->assertSame('cat', $item->getCategory()); $this->assertSame($count + 1, $repo->count([])); } } diff --git a/tests/CourseBundle/Repository/CForumPostRepositoryTest.php b/tests/CourseBundle/Repository/CForumPostRepositoryTest.php index a3c10b2ca6..52ec5a7b0c 100644 --- a/tests/CourseBundle/Repository/CForumPostRepositoryTest.php +++ b/tests/CourseBundle/Repository/CForumPostRepositoryTest.php @@ -82,6 +82,8 @@ class CForumPostRepositoryTest extends AbstractApiTest $attachmentRepo->addFile($attachment, $file); $attachmentRepo->update($attachment); + $this->assertSame($attachment->getResourceIdentifier(), $attachment->getIid()); + $this->assertSame($file->getFilename(), (string) $attachment); $this->assertNotNull($attachment->getResourceNode()); $this->assertNotNull($attachment->getResourceNode()->getResourceFile()); diff --git a/tests/CourseBundle/Repository/CGlossaryRepositoryTest.php b/tests/CourseBundle/Repository/CGlossaryRepositoryTest.php index 9b250d65b7..1e30575b8c 100644 --- a/tests/CourseBundle/Repository/CGlossaryRepositoryTest.php +++ b/tests/CourseBundle/Repository/CGlossaryRepositoryTest.php @@ -39,6 +39,8 @@ class CGlossaryRepositoryTest extends AbstractApiTest $em->flush(); $this->assertSame('glossary', (string) $glossary); + $this->assertSame('desc', $glossary->getDescription()); + $this->assertSame(1, $glossary->getDisplayOrder()); $this->assertSame($glossary->getResourceIdentifier(), $glossary->getIid()); $router = $this->getContainer()->get(RouterInterface::class); diff --git a/tests/CourseBundle/Repository/CGroupCategoryRepositoryTest.php b/tests/CourseBundle/Repository/CGroupCategoryRepositoryTest.php index 4bfa40b794..0b37e3abfb 100644 --- a/tests/CourseBundle/Repository/CGroupCategoryRepositoryTest.php +++ b/tests/CourseBundle/Repository/CGroupCategoryRepositoryTest.php @@ -47,6 +47,22 @@ class CGroupCategoryRepositoryTest extends AbstractApiTest $em->persist($category); $em->flush(); + $this->assertSame('category', (string) $category); + $this->assertSame('desc', $category->getDescription()); + $this->assertTrue($category->getSelfRegAllowed()); + $this->assertTrue($category->getSelfUnregAllowed()); + $this->assertTrue($category->getAnnouncementsState()); + $this->assertTrue($category->getCalendarState()); + $this->assertTrue($category->getChatState()); + $this->assertTrue($category->getForumState()); + $this->assertTrue($category->getWikiState()); + $this->assertTrue($category->getWorkState()); + $this->assertSame(1, $category->getDocumentAccess()); + $this->assertSame(10, $category->getGroupsPerUser()); + $this->assertSame(100, $category->getMaxStudent()); + $this->assertSame('desc', $category->getDescription()); + + $this->assertSame($category->getResourceIdentifier(), $category->getIid()); $this->assertSame(1, $categoryRepo->count([])); $categoryRepo->delete($category); diff --git a/tests/CourseBundle/Repository/CGroupRepositoryTest.php b/tests/CourseBundle/Repository/CGroupRepositoryTest.php index 7cb46479fb..fddc90e4b9 100644 --- a/tests/CourseBundle/Repository/CGroupRepositoryTest.php +++ b/tests/CourseBundle/Repository/CGroupRepositoryTest.php @@ -28,7 +28,7 @@ class CGroupRepositoryTest extends AbstractApiTest $course = $this->createCourse('new'); $teacher = $this->createUser('teacher'); - $item = (new CGroup()) + $group = (new CGroup()) ->setName('Group') ->setParent($course) ->setCreator($teacher) @@ -46,18 +46,32 @@ class CGroupRepositoryTest extends AbstractApiTest ->setMaxStudent(100) ; - $this->assertHasNoEntityViolations($item); - $em->persist($item); + $this->assertHasNoEntityViolations($group); + $em->persist($group); $em->flush(); - $this->assertTrue($item->getSelfRegistrationAllowed()); - $this->assertTrue($item->getSelfUnregistrationAllowed()); + $this->assertTrue($group->getSelfRegistrationAllowed()); + $this->assertTrue($group->getSelfUnregistrationAllowed()); + + $this->assertFalse($group->hasTutors()); + $this->assertFalse($group->hasMembers()); + $this->assertTrue($group->getStatus()); + $this->assertSame('desc', $group->getDescription()); + $this->assertSame(100, $group->getMaxStudent()); + $this->assertSame(0, $group->getAnnouncementsState()); + $this->assertSame(0, $group->getChatState()); + $this->assertSame(0, $group->getDocState()); + $this->assertSame(0, $group->getDocumentAccess()); + $this->assertSame(0, $group->getCalendarState()); + $this->assertSame(0, $group->getWikiState()); + $this->assertSame(0, $group->getWorkState()); + $this->assertSame($group->getResourceIdentifier(), $group->getIid()); $this->assertSame(1, $repo->count([])); $this->assertNotNull($repo->findOneByTitle('Group')); - $repo->delete($item); + $repo->delete($group); $this->assertSame(0, $repo->count([])); } @@ -147,6 +161,8 @@ class CGroupRepositoryTest extends AbstractApiTest /** @var CGroup $group */ $group = $groupRepo->find($group->getIid()); + $this->assertSame($groupRelTutor->getCId(), $courseId); + $this->assertSame($group->getResourceIdentifier(), $group->getIid()); $this->assertSame(1, $group->getMembers()->count()); $this->assertSame(1, $group->getTutors()->count()); @@ -175,14 +191,14 @@ class CGroupRepositoryTest extends AbstractApiTest $course = $this->createCourse('new'); $teacher = $this->createUser('teacher'); - $item = (new CGroup()) + $group = (new CGroup()) ->setName('Group') ->setParent($course) ->setCreator($teacher) ->setMaxStudent(100) ->addCourseLink($course) ; - $repo->create($item); + $repo->create($group); $qb = $repo->findAllByCourse($course); $this->assertCount(1, $qb->getQuery()->getResult()); diff --git a/tests/CourseBundle/Repository/CLinkCategoryRepositoryTest.php b/tests/CourseBundle/Repository/CLinkCategoryRepositoryTest.php index 8de6a754ab..0961e5e26b 100644 --- a/tests/CourseBundle/Repository/CLinkCategoryRepositoryTest.php +++ b/tests/CourseBundle/Repository/CLinkCategoryRepositoryTest.php @@ -23,17 +23,24 @@ class CLinkCategoryRepositoryTest extends AbstractApiTest $course = $this->createCourse('new'); $teacher = $this->createUser('teacher'); - $item = (new CLinkCategory()) + $category = (new CLinkCategory()) ->setCategoryTitle('cat') + ->setDescription('desc') + ->setDisplayOrder(1) ->setParent($course) ->setCreator($teacher) ; - $this->assertHasNoEntityViolations($item); - $em->persist($item); + $this->assertHasNoEntityViolations($category); + $em->persist($category); $em->flush(); - $this->assertSame('cat', (string) $item); + $this->assertSame($category->getResourceIdentifier(), $category->getIid()); + $this->assertSame('cat', (string) $category); + $this->assertSame('desc', $category->getDescription()); + $this->assertSame('cat', $category->getCategoryTitle()); + $this->assertSame(1, $category->getDisplayOrder()); + $this->assertSame(1, $repo->count([])); } } diff --git a/tests/CourseBundle/Repository/CLinkRepositoryTest.php b/tests/CourseBundle/Repository/CLinkRepositoryTest.php index 620d58331c..eec8de8933 100644 --- a/tests/CourseBundle/Repository/CLinkRepositoryTest.php +++ b/tests/CourseBundle/Repository/CLinkRepositoryTest.php @@ -23,22 +23,29 @@ class CLinkRepositoryTest extends AbstractApiTest $course = $this->createCourse('new'); $teacher = $this->createUser('teacher'); - $item = (new CLink()) + $link = (new CLink()) ->setUrl('https://chamilo.org') ->setTitle('link') ->setDescription('desc') ->setDisplayOrder(1) - ->setTarget('blank') + ->setTarget('_blank') ->setCategory(null) ->setParent($course) ->setCreator($teacher) ; - $this->assertHasNoEntityViolations($item); - $em->persist($item); + $this->assertHasNoEntityViolations($link); + $em->persist($link); $em->flush(); - $this->assertSame('link', (string) $item); + $this->assertSame('link', (string) $link); + $this->assertSame($link->getResourceIdentifier(), $link->getIid()); + $this->assertSame('https://chamilo.org', $link->getUrl()); + $this->assertSame('link', $link->getTitle()); + $this->assertSame('desc', $link->getDescription()); + $this->assertSame(1, $link->getDisplayOrder()); + $this->assertSame('_blank', $link->getTarget()); + $this->assertSame(1, $repo->count([])); } } diff --git a/tests/CourseBundle/Repository/CLpCategoryRepositoryTest.php b/tests/CourseBundle/Repository/CLpCategoryRepositoryTest.php index 8df937bba3..1429420707 100644 --- a/tests/CourseBundle/Repository/CLpCategoryRepositoryTest.php +++ b/tests/CourseBundle/Repository/CLpCategoryRepositoryTest.php @@ -34,6 +34,8 @@ class CLpCategoryRepositoryTest extends AbstractApiTest $em->persist($category); $em->flush(); + $this->assertSame($category->getResourceIdentifier(), $category->getIid()); + $this->assertSame(1, $category->getPosition()); $this->assertSame('cat', (string) $category); $this->assertSame(1, $repo->count([])); diff --git a/tests/CourseBundle/Repository/CLpItemRepositoryTest.php b/tests/CourseBundle/Repository/CLpItemRepositoryTest.php index 396437fbcd..88c0b2546a 100644 --- a/tests/CourseBundle/Repository/CLpItemRepositoryTest.php +++ b/tests/CourseBundle/Repository/CLpItemRepositoryTest.php @@ -68,6 +68,21 @@ class CLpItemRepositoryTest extends AbstractApiTest $this->assertHasNoEntityViolations($lpItem); $lpItemRepo->create($lpItem); + $this->assertSame('lp item', $lpItem->getTitle()); + $this->assertSame('ref', $lpItem->getRef()); + $this->assertSame(100.0, $lpItem->getMinScore()); + $this->assertSame(100.0, $lpItem->getMaxScore()); + $this->assertSame(1, $lpItem->getDisplayOrder()); + $this->assertSame(100.0, $lpItem->getPrerequisiteMaxScore()); + $this->assertSame(100.0, $lpItem->getPrerequisiteMinScore()); + $this->assertSame('', $lpItem->getLaunchData()); + $this->assertSame('', $lpItem->getPrerequisite()); + $this->assertSame('', $lpItem->getParameters()); + $this->assertSame('', $lpItem->getAudio()); + $this->assertSame(0, $lpItem->getSearchDid()); + + $this->assertSame(0, $lpItem->getLvl()); + $em = $this->getEntityManager(); $view = (new CLpView()) ->setUser($student) diff --git a/tests/CourseBundle/Repository/CLpRepositoryTest.php b/tests/CourseBundle/Repository/CLpRepositoryTest.php index eebc540f9f..8708a86f6c 100644 --- a/tests/CourseBundle/Repository/CLpRepositoryTest.php +++ b/tests/CourseBundle/Repository/CLpRepositoryTest.php @@ -51,6 +51,13 @@ class CLpRepositoryTest extends AbstractApiTest $this->assertHasNoEntityViolations($lp); $repo->createLp($lp); + $this->assertSame('lp', $lp->getName()); + $this->assertSame('desc', $lp->getDescription()); + $this->assertSame('chamilo', $lp->getTheme()); + $this->assertSame('author', $lp->getAuthor()); + $this->assertSame('local', $lp->getContentLocal()); + $this->assertSame('maker', $lp->getContentMaker()); + $this->assertNotNull($lp->getResourceNode()); $this->assertSame(1, $lp->getItems()->count()); $this->assertFalse($lp->hasCategory()); diff --git a/tests/CourseBundle/Repository/CStudentPublicationRepositoryTest.php b/tests/CourseBundle/Repository/CStudentPublicationRepositoryTest.php index 272c697f03..ec6120779b 100644 --- a/tests/CourseBundle/Repository/CStudentPublicationRepositoryTest.php +++ b/tests/CourseBundle/Repository/CStudentPublicationRepositoryTest.php @@ -57,6 +57,9 @@ class CStudentPublicationRepositoryTest extends AbstractApiTest $this->assertSame('publi', (string) $item); $this->assertSame(1, $repo->count([])); + $this->assertSame($item->getResourceIdentifier(), $item->getIid()); + $this->assertSame('desc', $item->getDescription()); + $count = $repo->countUserPublications($teacher, $course); $this->assertSame(1, $count);