pull/4020/head^2
Julio 3 years ago
parent 31dd1e6d2a
commit d40d17fbfd
  1. 57
      tests/CoreBundle/Repository/Node/CourseRepositoryTest.php
  2. 5
      tests/CoreBundle/Repository/Node/IllustrationRepositoryTest.php
  3. 83
      tests/CoreBundle/Repository/Node/UserRepositoryTest.php
  4. 6
      tests/CoreBundle/Repository/SessionRepositoryTest.php
  5. 8
      tests/CourseBundle/Repository/CSurveyRepositoryTest.php

@ -132,6 +132,63 @@ class CourseRepositoryTest extends AbstractApiTest
$this->assertSame(1, $course->getUrls()->count());
}
public function testDeleteCourse(): void
{
/** @var CourseRepository $courseRepo */
$courseRepo = self::getContainer()->get(CourseRepository::class);
$course = $this->createCourse('Test course');
$courseRepo->deleteCourse($course);
$this->assertSame(0, $courseRepo->count([]));
}
public function testGetCoursesByUser(): void
{
/** @var CourseRepository $courseRepo */
$courseRepo = self::getContainer()->get(CourseRepository::class);
$student = $this->createUser('student');
$course = $this->createCourse('Test course');
$courses = $courseRepo->getCoursesByUser($student, $this->getAccessUrl());
$this->assertCount(0, $courses);
$course->addUser($student, 0, '', CourseRelUser::STUDENT);
$courseRepo->update($course);
$courses = $courseRepo->getCoursesByUser($student, $this->getAccessUrl());
$this->assertCount(1, $courses);
}
public function testGetSubscribedUsers(): void
{
/** @var CourseRepository $courseRepo */
$courseRepo = self::getContainer()->get(CourseRepository::class);
$student = $this->createUser('student');
$course = $this->createCourse('Test course');
$qb = $courseRepo->getSubscribedUsers($course);
$this->assertCount(0, $qb->getQuery()->getResult());
$course->addUser($student, 0, '', CourseRelUser::STUDENT);
$courseRepo->update($course);
$qb = $courseRepo->getSubscribedUsers($course);
$this->assertCount(1, $qb->getQuery()->getResult());
$qb = $courseRepo->getSubscribedStudents($course);
$this->assertCount(1, $qb->getQuery()->getResult());
$qb = $courseRepo->getSubscribedCoaches($course);
$this->assertCount(1, $qb->getQuery()->getResult());
$qb = $courseRepo->getSubscribedTeachers($course);
$this->assertCount(0, $qb->getQuery()->getResult());
}
public function testCourseStudentSubscription(): void
{
$client = static::createClient();

@ -35,6 +35,11 @@ class IllustrationRepositoryTest extends WebTestCase
$url
);
$this->assertResponseIsSuccessful();
$this->assertSame(1, $repo->count([]));
$this->assertTrue($repo->hasIllustration($course));
$repo->deleteIllustration($course);
$this->assertSame(0, $repo->count([]));
}
public function testCreateUserIllustration(): void

@ -7,10 +7,12 @@ namespace Chamilo\Tests\CoreBundle\Repository\Node;
use Chamilo\CoreBundle\Entity\AccessUrl;
use Chamilo\CoreBundle\Entity\Group;
use Chamilo\CoreBundle\Entity\User;
use Chamilo\CoreBundle\Entity\UserRelUser;
use Chamilo\CoreBundle\Repository\Node\UserRepository;
use Chamilo\Tests\AbstractApiTest;
use Chamilo\Tests\ChamiloTestTrait;
use DateTime;
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
class UserRepositoryTest extends AbstractApiTest
{
@ -18,12 +20,89 @@ class UserRepositoryTest extends AbstractApiTest
public function testCount(): void
{
self::bootKernel();
$count = self::getContainer()->get(UserRepository::class)->count([]);
// Admin + anon (registered in the DataFixture\AccessUrlAdminFixtures.php)
$this->assertSame(2, $count);
}
public function testLoadUserByIdentifier(): void
{
$student = $this->createUser('student');
$userRepo = self::getContainer()->get(UserRepository::class);
$user = $userRepo->loadUserByIdentifier($student->getUsername());
$this->assertInstanceOf(User::class, $user);
}
public function testUpgradePassword(): void
{
$student = $this->createUser('student');
$userRepo = self::getContainer()->get(UserRepository::class);
$oldPassword = $student->getPassword();
$userRepo->upgradePassword($student, 'password');
$this->assertTrue($oldPassword !== $student->getPassword());
}
public function testGetRootUser(): void
{
$userRepo = self::getContainer()->get(UserRepository::class);
$user = $userRepo->getRootUser();
$this->assertInstanceOf(User::class, $user);
}
public function testDeleteUser(): void
{
$userRepo = self::getContainer()->get(UserRepository::class);
$student = $this->createUser('student');
$defaultCount = $userRepo->count([]);
$userRepo->deleteUser($student);
$this->assertSame($defaultCount - 1, $userRepo->count([]));
}
public function testFindByUsername(): void
{
$userRepo = self::getContainer()->get(UserRepository::class);
$this->expectException(UserNotFoundException::class);
$userRepo->findByUsername('no exist');
}
public function testGetCountUsersByUrl(): void
{
$userRepo = self::getContainer()->get(UserRepository::class);
$count = $userRepo->getCountUsersByUrl($this->getAccessUrl());
$this->assertNotEmpty($count);
}
public function testGetCountTeachersByUrl(): void
{
$userRepo = self::getContainer()->get(UserRepository::class);
$count = $userRepo->getCountTeachersByUrl($this->getAccessUrl());
$this->assertSame(0, $count);
$this->createUser('teacher', '', '', 'ROLE_TEACHER');
$count = $userRepo->getCountTeachersByUrl($this->getAccessUrl());
$this->assertSame(1, $count);
}
public function testGetAssignedHrmUserList(): void
{
$userRepo = self::getContainer()->get(UserRepository::class);
$student = $this->createUser('student');
$drh = $this->createUser('drh');
$drh->setRoles(['ROLE_RRHH']);
$userRepo->update($drh);
$student->addUserRelUser($drh, UserRelUser::USER_RELATION_TYPE_RRHH);
$userRepo->update($student);
$list = $userRepo->getAssignedHrmUserList($student->getId(), $this->getAccessUrl()->getId());
$this->assertCount(1, $list);
}
public function testCreateUser(): void
{
$student = $this->createUser('student');
@ -77,7 +156,6 @@ class UserRepositoryTest extends AbstractApiTest
public function testCreateAdmin(): void
{
self::bootKernel();
$admin = $this->createUser('admin2');
$userRepo = self::getContainer()->get(UserRepository::class);
@ -155,7 +233,6 @@ class UserRepositoryTest extends AbstractApiTest
;
$user->setRoleFromStatus(COURSEMANAGER);
$em->persist($user);
$userRepo->updateUser($user);

@ -269,6 +269,12 @@ class SessionRepositoryTest extends AbstractApiTest
$this->assertFalse($session->hasCourseCoachInCourse($drh, $course));
$this->assertTrue($session->hasCourseCoachInCourse($courseCoach, $course));
$coaches = $userRepo->getCoachesForSessionCourse($session, $course);
$this->assertCount(1, $coaches);
$sessions = $userRepo->getSessionAdmins($sessionAdmin);
$this->assertCount(1, $sessions);
$this->assertTrue($session->hasStudentInCourse($student, $course));
$this->assertFalse($session->hasStudentInCourse($sessionAdmin, $course));

@ -13,6 +13,7 @@ use Chamilo\CourseBundle\Entity\CSurveyInvitation;
use Chamilo\CourseBundle\Entity\CSurveyQuestion;
use Chamilo\CourseBundle\Entity\CSurveyQuestionOption;
use Chamilo\CourseBundle\Repository\CSurveyAnswerRepository;
use Chamilo\CourseBundle\Repository\CSurveyInvitationRepository;
use Chamilo\CourseBundle\Repository\CSurveyQuestionRepository;
use Chamilo\CourseBundle\Repository\CSurveyRepository;
use Chamilo\Tests\AbstractApiTest;
@ -77,7 +78,7 @@ class CSurveyRepositoryTest extends AbstractApiTest
$surveyRepo = self::getContainer()->get(CSurveyRepository::class);
$surveyQuestionRepo = self::getContainer()->get(CSurveyQuestionRepository::class);
$surveyAnswerRepo = self::getContainer()->get(CSurveyAnswerRepository::class);
$surveyInvitationRepo = $em->getRepository(CSurveyInvitation::class);
$surveyInvitationRepo = self::getContainer()->get(CSurveyInvitationRepository::class);
$surveyOptionRepo = $em->getRepository(CSurveyQuestionOption::class);
$course = $this->createCourse('new');
@ -87,6 +88,8 @@ class CSurveyRepositoryTest extends AbstractApiTest
$survey = (new CSurvey())
->setTitle('survey')
->setCode('survey')
->setAvailFrom(new DateTime())
->setAvailTill(new DateTime('now +30 days'))
->setParent($course)
->setCreator($teacher)
;
@ -168,6 +171,9 @@ class CSurveyRepositoryTest extends AbstractApiTest
$this->assertSame(1, $surveyOptionRepo->count([]));
$this->assertSame(1, $courseRepo->count([]));
$invitations = $surveyInvitationRepo->getUserPendingInvitations($student);
$this->assertCount(1, $invitations);
$course = $this->getCourse($course->getId());
$courseRepo->delete($course);

Loading…
Cancel
Save