Tests: Add phpunit tests

pull/3959/head
Julio 3 years ago
parent 30c8cfed91
commit 0ccaf0a888
  1. 37
      tests/CoreBundle/Repository/LanguageRepositoryTest.php
  2. 45
      tests/CoreBundle/Repository/PromotionRepositoryTest.php
  3. 47
      tests/CoreBundle/Repository/TagRepositoryTest.php
  4. 33
      tests/CourseBundle/Repository/CDocumentRepositoryTest.php

@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\Tests\CoreBundle\Repository;
use Chamilo\CoreBundle\Entity\Language;
use Chamilo\CoreBundle\Repository\LanguageRepository;
use Chamilo\Tests\AbstractApiTest;
use Chamilo\Tests\ChamiloTestTrait;
class LanguageRepositoryTest extends AbstractApiTest
{
use ChamiloTestTrait;
public function testCreate(): void
{
self::bootKernel();
$em = $this->getManager();
$repo = self::getContainer()->get(LanguageRepository::class);
$defaultCount = $repo->count([]);
$item = (new Language())
->setAvailable(true)
->setOriginalName('language')
->setEnglishName('language')
->setIsocode('lan')
;
$this->assertHasNoEntityViolations($item);
$em->persist($item);
$em->flush();
$this->assertSame($defaultCount + 1, $repo->count([]));
}
}

@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\Tests\CoreBundle\Repository;
use Chamilo\CoreBundle\Entity\Career;
use Chamilo\CoreBundle\Entity\Promotion;
use Chamilo\CoreBundle\Repository\PromotionRepository;
use Chamilo\Tests\AbstractApiTest;
use Chamilo\Tests\ChamiloTestTrait;
class PromotionRepositoryTest extends AbstractApiTest
{
use ChamiloTestTrait;
public function testCreate(): void
{
self::bootKernel();
$em = $this->getManager();
$repo = self::getContainer()->get(PromotionRepository::class);
$defaultCount = $repo->count([]);
$career = (new Career())
->setName('Doctor')
;
$em->persist($career);
$em->flush();
$item = (new Promotion())
->setName('2000')
->setDescription('Promotion of 2000')
->setCareer($career)
->setStatus(1)
;
$this->assertHasNoEntityViolations($item);
$em->persist($item);
$em->flush();
$this->assertSame($defaultCount + 1, $repo->count([]));
}
}

@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\Tests\CoreBundle\Repository;
use Chamilo\CoreBundle\Entity\ExtraField;
use Chamilo\CoreBundle\Entity\Tag;
use Chamilo\CoreBundle\Repository\TagRepository;
use Chamilo\Tests\AbstractApiTest;
use Chamilo\Tests\ChamiloTestTrait;
class TagRepositoryTest extends AbstractApiTest
{
use ChamiloTestTrait;
public function testCreate(): void
{
self::bootKernel();
$em = $this->getManager();
$repo = self::getContainer()->get(TagRepository::class);
$defaultCount = $repo->count([]);
$extraField = (new ExtraField())
->setDisplayText('test')
->setVariable('test')
->setExtraFieldType(ExtraField::USER_FIELD_TYPE)
->setFieldType(\ExtraField::FIELD_TYPE_TEXT)
;
$em->persist($extraField);
$em->flush();
$tag = (new Tag())
->setTag('php')
->setCount(1)
->setField($extraField)
;
$this->assertHasNoEntityViolations($tag);
$em->persist($tag);
$em->flush();
$this->assertSame($defaultCount + 1, $repo->count([]));
}
}

@ -44,14 +44,16 @@ class CDocumentRepositoryTest extends AbstractApiTest
$course = $this->createCourse('Test');
// Create folder.
$resourceLinkList = [[
'cid' => $course->getId(),
'visibility' => ResourceLink::VISIBILITY_PUBLISHED,
]];
$resourceLinkList = [
[
'cid' => $course->getId(),
'visibility' => ResourceLink::VISIBILITY_PUBLISHED,
],
];
$folderName = 'folder1';
$token = $this->getUserToken([]);
$this->createClientWithCredentials($token)->request(
$response = $this->createClientWithCredentials($token)->request(
'POST',
'/api/documents',
[
@ -73,6 +75,27 @@ class CDocumentRepositoryTest extends AbstractApiTest
'title' => $folderName,
'parentResourceNode' => $course->getResourceNode()->getId(),
]);
// Update.
$id = $response->toArray()['@id'];
$this->createClientWithCredentials($token)->request(
'PUT',
$id,
[
'json' => [
'title' => 'edited',
],
]
);
$this->assertResponseIsSuccessful();
$this->assertResponseStatusCodeSame(200);
$this->assertJsonContains([
'@context' => '/api/contexts/Documents',
'@type' => 'Documents',
'title' => 'edited',
]);
}
public function testUploadFile(): void

Loading…
Cancel
Save