Tests: Add phpunit tests

pull/3984/head
Julio 4 years ago
parent 4fd6236531
commit 70952b3a70
  1. 17
      src/CourseBundle/Repository/CLpItemRepository.php
  2. 12
      src/CourseBundle/Repository/CQuizRepository.php
  3. 3
      tests/CourseBundle/Repository/CLpCategoryRepositoryTest.php
  4. 27
      tests/CourseBundle/Repository/CLpRepositoryTest.php
  5. 24
      tests/CourseBundle/Repository/CQuizRepositoryTest.php

@ -37,21 +37,4 @@ final class CLpItemRepository extends ServiceEntityRepository
'lp' => $lpId,
]);
}
/**
* @return CLpItem[]
*/
public function getTree(int $lpId)
{
$qb = $this->createQueryBuilder('i');
$qb
->andWhere('lp = :lp AND path = :path')
->setParameters([
'lp' => $lpId,
'path' => 'root',
])
;
return $qb->getQuery()->getResult('tree');
}
}

@ -78,18 +78,18 @@ final class CQuizRepository extends ResourceRepository implements ResourceWithLi
{
$qb = $this->getOrCreateQueryBuilder($qb);
$qb
->andWhere("(
->andWhere('(
(
resource.startTime <> '' AND
resource.startTime IS NOT NULL AND
resource.startTime < :date AND
resource.endTime <> '' AND
resource.endTime IS NOT NULL AND
resource.endTime > :date
) OR
(resource.startTime <> '' AND resource.startTime < :date AND resource.endTime IS NULL) OR
(resource.startTime IS NULL AND resource.endTime <> '' AND resource.endTime > :date) OR
(resource.startTime IS NOT NULL AND resource.startTime < :date AND resource.endTime IS NULL) OR
(resource.startTime IS NULL AND resource.endTime IS NOT NULL AND resource.endTime > :date) OR
(resource.startTime IS NULL AND resource.endTime IS NULL)
)
")
')
->setParameter('date', $dateTime)
;

@ -36,5 +36,8 @@ class CLpCategoryRepositoryTest extends AbstractApiTest
$this->assertSame('cat', (string) $item);
$this->assertSame(1, $repo->count([]));
$link = $repo->getLink($item, $this->getContainer()->get('router'));
$this->assertSame('/main/lp/lp_controller.php?id='.$item->getIid().'&action=view_category', $link);
}
}

@ -15,7 +15,7 @@ class CLpRepositoryTest extends AbstractApiTest
{
use ChamiloTestTrait;
public function testCreate(): void
public function testCreateLp(): void
{
self::bootKernel();
@ -37,5 +37,30 @@ class CLpRepositoryTest extends AbstractApiTest
$this->assertSame(1, $lp->getItems()->count());
$this->assertSame('lp', (string) $lp);
$this->assertSame(1, $repo->count([]));
$link = $repo->getLink($lp, $this->getContainer()->get('router'));
$this->assertSame('/main/lp/lp_controller.php?lp_id='.$lp->getIid().'&action=view', $link);
}
public function testFindAllByCourse(): void
{
self::bootKernel();
$repo = self::getContainer()->get(CLpRepository::class);
$course = $this->createCourse('new');
$teacher = $this->createUser('teacher');
$lp = (new CLp())
->setName('lp')
->setParent($course)
->setCreator($teacher)
->setLpType(CLp::LP_TYPE)
->addCourseLink($course)
;
$repo->createLp($lp);
$qb = $repo->findAllByCourse($course);
$this->assertSame(1, \count($qb->getQuery()->getResult()));
}
}

@ -36,5 +36,29 @@ class CQuizRepositoryTest extends AbstractApiTest
$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()));
}
}

Loading…
Cancel
Save