You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.7 KiB
64 lines
1.7 KiB
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/* For licensing terms, see /license.txt */
|
|
|
|
namespace Chamilo\Tests\CourseBundle\Repository;
|
|
|
|
use Chamilo\CourseBundle\Entity\CQuiz;
|
|
use Chamilo\CourseBundle\Repository\CQuizRepository;
|
|
use Chamilo\Tests\AbstractApiTest;
|
|
use Chamilo\Tests\ChamiloTestTrait;
|
|
|
|
class CQuizRepositoryTest extends AbstractApiTest
|
|
{
|
|
use ChamiloTestTrait;
|
|
|
|
public function testCreate(): void
|
|
{
|
|
self::bootKernel();
|
|
|
|
$em = $this->getEntityManager();
|
|
$repo = self::getContainer()->get(CQuizRepository::class);
|
|
|
|
$course = $this->createCourse('new');
|
|
$teacher = $this->createUser('teacher');
|
|
|
|
$item = (new CQuiz())
|
|
->setTitle('exercise')
|
|
->setParent($course)
|
|
->setCreator($teacher)
|
|
;
|
|
$this->assertHasNoEntityViolations($item);
|
|
$em->persist($item);
|
|
$em->flush();
|
|
|
|
$this->assertSame('exercise', (string) $item);
|
|
$this->assertSame(1, $repo->count([]));
|
|
|
|
$link = $repo->getLink($item, $this->getContainer()->get('router'));
|
|
$this->assertSame('/main/exercise/overview.php?exerciseId='.$item->getIid(), $link);
|
|
}
|
|
|
|
public function testFindAllByCourse(): void
|
|
{
|
|
self::bootKernel();
|
|
|
|
$repo = self::getContainer()->get(CQuizRepository::class);
|
|
|
|
$course = $this->createCourse('new');
|
|
$teacher = $this->createUser('teacher');
|
|
|
|
$exercise = (new CQuiz())
|
|
->setTitle('exercise')
|
|
->setParent($course)
|
|
->setCreator($teacher)
|
|
->addCourseLink($course)
|
|
;
|
|
$repo->create($exercise);
|
|
|
|
$qb = $repo->findAllByCourse($course);
|
|
$this->assertSame(1, \count($qb->getQuery()->getResult()));
|
|
}
|
|
}
|
|
|