Minor - add test

pull/4032/head
Julio 4 years ago
parent bd508dff32
commit 9a267dce3c
  1. 78
      tests/CoreBundle/Repository/TrackExerciseRepositoryTest.php

@ -11,8 +11,8 @@ use Chamilo\CoreBundle\Entity\AttemptFeedback;
use Chamilo\CoreBundle\Entity\AttemptFile;
use Chamilo\CoreBundle\Entity\TrackEAttempt;
use Chamilo\CoreBundle\Entity\TrackExercise;
use Chamilo\CoreBundle\Repository\AssetRepository;
use Chamilo\CoreBundle\Repository\Node\CourseRepository;
use Chamilo\CoreBundle\Repository\SessionRepository;
use Chamilo\CoreBundle\Repository\TrackExerciseRepository;
use Chamilo\CourseBundle\Entity\CQuiz;
use Chamilo\CourseBundle\Repository\CQuizRepository;
@ -89,6 +89,75 @@ class TrackExerciseRepositoryTest extends AbstractApiTest
$this->assertSame(0, $courseRepo->count([]));
}
public function testCreateInSession(): void
{
self::bootKernel();
$em = $this->getEntityManager();
$course = $this->createCourse('new');
$session = $this->createSession('session 1');
$teacher = $this->createUser('teacher');
$student = $this->createUser('student');
$courseRepo = self::getContainer()->get(CourseRepository::class);
$sessionRepo = self::getContainer()->get(SessionRepository::class);
$trackExerciseRepo = self::getContainer()->get(TrackExerciseRepository::class);
$exerciseRepo = self::getContainer()->get(CQuizRepository::class);
$this->assertSame(1, $courseRepo->count([]));
$exercise = (new CQuiz())
->setTitle('exercise')
->setParent($course)
->setCreator($teacher)
;
$em->persist($exercise);
$em->flush();
$trackExercise = (new TrackExercise())
->setQuestionsToCheck('')
->setExeDate(new DateTime())
->setStartDate(new DateTime())
->setSession($session)
->setStatus('completed')
->setCourse($course)
->setScore(100)
->setMaxScore(100)
->setDataTracking('')
->setUser($student)
->setUserIp('127.0.0.1')
->setStepsCounter(1)
->setOrigLpId(0)
->setOrigLpItemId(0)
->setOrigLpItemViewId(0)
->setExeDuration(10)
->setExpiredTimeControl(new DateTime())
->setExeExoId($exercise->getIid())
;
$em->persist($trackExercise);
$this->assertHasNoEntityViolations($trackExercise);
$em->flush();
$this->assertSame(1, $trackExerciseRepo->count([]));
$this->assertSame(1, $exerciseRepo->count([]));
$this->assertSame(1, $courseRepo->count([]));
$trackExerciseRepo->delete($trackExercise);
$this->assertSame(1, $courseRepo->count([]));
$this->assertSame(0, $trackExerciseRepo->count([]));
$this->assertSame(1, $exerciseRepo->count([]));
$em->remove($session);
$em->flush();
$this->assertSame(0, $trackExerciseRepo->count([]));
$this->assertSame(1, $exerciseRepo->count([]));
$this->assertSame(1, $courseRepo->count([]));
$this->assertSame(0, $sessionRepo->count([]));
}
public function testCreateWithAttempt(): void
{
self::bootKernel();
@ -150,7 +219,6 @@ class TrackExerciseRepositoryTest extends AbstractApiTest
$file = $this->getUploadedFile();
$assetRepo = self::getContainer()->get(AssetRepository::class);
$em = $this->getEntityManager();
// Create asset.
@ -217,5 +285,11 @@ class TrackExerciseRepositoryTest extends AbstractApiTest
$this->assertSame(0, $courseRepo->count([]));
$this->assertSame(0, $exerciseRepo->count([]));
$this->assertSame(0, $trackExerciseRepo->count([]));
$teacher = $this->getUser('teacher');
$this->assertNotNull($teacher);
$student = $this->getUser('student');
$this->assertNotNull($student);
}
}

Loading…
Cancel
Save