Minor - add tests

pull/4020/head^2
Julio 3 years ago
parent 0c3e6dbc74
commit 38ad4c7d73
  1. 13
      src/CoreBundle/Entity/Listener/CourseListener.php
  2. 14
      src/CoreBundle/Entity/Listener/MessageListener.php
  3. 11
      src/CoreBundle/Entity/Listener/SessionListener.php
  4. 14
      src/CoreBundle/Settings/SettingsManager.php
  5. 10
      tests/CourseBundle/Repository/CCourseSettingRepositoryTest.php
  6. 2
      tests/CourseBundle/Repository/CForumPostRepositoryTest.php
  7. 2
      tests/CourseBundle/Repository/CGlossaryRepositoryTest.php
  8. 16
      tests/CourseBundle/Repository/CGroupCategoryRepositoryTest.php
  9. 32
      tests/CourseBundle/Repository/CGroupRepositoryTest.php
  10. 15
      tests/CourseBundle/Repository/CLinkCategoryRepositoryTest.php
  11. 17
      tests/CourseBundle/Repository/CLinkRepositoryTest.php
  12. 2
      tests/CourseBundle/Repository/CLpCategoryRepositoryTest.php
  13. 15
      tests/CourseBundle/Repository/CLpItemRepositoryTest.php
  14. 7
      tests/CourseBundle/Repository/CLpRepositoryTest.php
  15. 3
      tests/CourseBundle/Repository/CStudentPublicationRepositoryTest.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');
}
}
}*/
}
}
}*/
}

@ -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
{
}
}

@ -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');
}*/
}
}
}
}*/
}

@ -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)

@ -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([]));
}
}

@ -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());

@ -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);

@ -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);

@ -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());

@ -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([]));
}
}

@ -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([]));
}
}

@ -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([]));

@ -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)

@ -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());

@ -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);

Loading…
Cancel
Save