Minor - add tests

pull/4020/head^2
Julio 3 years ago
parent 0a35c4c3de
commit 1fc64ccd33
  1. 6
      src/CoreBundle/Repository/CourseCategoryRepository.php
  2. 14
      tests/CoreBundle/Repository/CourseCategoryRepositoryTest.php
  3. 47
      tests/CoreBundle/Repository/LegalRepositoryTest.php

@ -21,6 +21,12 @@ class CourseCategoryRepository extends ServiceEntityRepository
parent::__construct($registry, CourseCategory::class); parent::__construct($registry, CourseCategory::class);
} }
public function update(CourseCategory $category): void
{
$this->getEntityManager()->persist($category);
$this->getEntityManager()->flush();
}
/** /**
* Get all course categories in an access url. * Get all course categories in an access url.
* *

@ -27,6 +27,10 @@ class CourseCategoryRepositoryTest extends AbstractApiTest
$item = (new CourseCategory()) $item = (new CourseCategory())
->setCode('Course cat') ->setCode('Course cat')
->setName('Course cat') ->setName('Course cat')
->setDescription('desc')
->setTreePos(1)
->setChildrenCount(0)
->setAuthCourseChild('auth')
; ;
$this->assertHasNoEntityViolations($item); $this->assertHasNoEntityViolations($item);
$em->persist($item); $em->persist($item);
@ -38,6 +42,16 @@ class CourseCategoryRepositoryTest extends AbstractApiTest
$this->assertSame('Course cat', $item->getCode()); $this->assertSame('Course cat', $item->getCode());
$this->assertSame('Course cat (Course cat)', (string) $item); $this->assertSame('Course cat (Course cat)', (string) $item);
$this->assertSame('desc', $item->getDescription());
$this->assertSame('Course cat', $item->getName());
$this->assertFalse($item->hasAsset());
$accessUrl = $this->getAccessUrl();
$this->assertFalse($item->hasUrl($accessUrl));
$item->addUrl($accessUrl);
$repo->update($item);
$this->assertTrue($item->hasUrl($accessUrl));
} }
public function testCreateWithParent(): void public function testCreateWithParent(): void

@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\Tests\CoreBundle\Repository;
use Chamilo\CoreBundle\Entity\Legal;
use Chamilo\CoreBundle\Repository\LegalRepository;
use Chamilo\Tests\AbstractApiTest;
use Chamilo\Tests\ChamiloTestTrait;
class LegalRepositoryTest extends AbstractApiTest
{
use ChamiloTestTrait;
public function testCreate(): void
{
$em = $this->getEntityManager();
$repo = self::getContainer()->get(LegalRepository::class);
$item = (new Legal())
->setContent('content')
->setType(1)
->setChanges('changes')
->setDate(1)
->setLanguageId(1)
->setVersion(1)
;
$this->assertHasNoEntityViolations($item);
$em->persist($item);
$em->flush();
$this->assertSame(1, $repo->count([]));
}
public function testFindOneByTypeAndLanguage(): void
{
$this->testCreate();
$repo = self::getContainer()->get(LegalRepository::class);
$legal = $repo->findOneByTypeAndLanguage(1, 1);
$this->assertCount(1, $legal);
}
}
Loading…
Cancel
Save