Skip to content

Commit 0ccaf0a

Browse files
committed
Tests: Add phpunit tests
1 parent 30c8cfe commit 0ccaf0a

File tree

4 files changed

+157
-5
lines changed

4 files changed

+157
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/* For licensing terms, see /license.txt */
6+
7+
namespace Chamilo\Tests\CoreBundle\Repository;
8+
9+
use Chamilo\CoreBundle\Entity\Language;
10+
use Chamilo\CoreBundle\Repository\LanguageRepository;
11+
use Chamilo\Tests\AbstractApiTest;
12+
use Chamilo\Tests\ChamiloTestTrait;
13+
14+
class LanguageRepositoryTest extends AbstractApiTest
15+
{
16+
use ChamiloTestTrait;
17+
18+
public function testCreate(): void
19+
{
20+
self::bootKernel();
21+
22+
$em = $this->getManager();
23+
$repo = self::getContainer()->get(LanguageRepository::class);
24+
$defaultCount = $repo->count([]);
25+
$item = (new Language())
26+
->setAvailable(true)
27+
->setOriginalName('language')
28+
->setEnglishName('language')
29+
->setIsocode('lan')
30+
;
31+
$this->assertHasNoEntityViolations($item);
32+
$em->persist($item);
33+
$em->flush();
34+
35+
$this->assertSame($defaultCount + 1, $repo->count([]));
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/* For licensing terms, see /license.txt */
6+
7+
namespace Chamilo\Tests\CoreBundle\Repository;
8+
9+
use Chamilo\CoreBundle\Entity\Career;
10+
use Chamilo\CoreBundle\Entity\Promotion;
11+
use Chamilo\CoreBundle\Repository\PromotionRepository;
12+
use Chamilo\Tests\AbstractApiTest;
13+
use Chamilo\Tests\ChamiloTestTrait;
14+
15+
class PromotionRepositoryTest extends AbstractApiTest
16+
{
17+
use ChamiloTestTrait;
18+
19+
public function testCreate(): void
20+
{
21+
self::bootKernel();
22+
23+
$em = $this->getManager();
24+
$repo = self::getContainer()->get(PromotionRepository::class);
25+
$defaultCount = $repo->count([]);
26+
27+
$career = (new Career())
28+
->setName('Doctor')
29+
;
30+
$em->persist($career);
31+
$em->flush();
32+
33+
$item = (new Promotion())
34+
->setName('2000')
35+
->setDescription('Promotion of 2000')
36+
->setCareer($career)
37+
->setStatus(1)
38+
;
39+
$this->assertHasNoEntityViolations($item);
40+
$em->persist($item);
41+
$em->flush();
42+
43+
$this->assertSame($defaultCount + 1, $repo->count([]));
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/* For licensing terms, see /license.txt */
6+
7+
namespace Chamilo\Tests\CoreBundle\Repository;
8+
9+
use Chamilo\CoreBundle\Entity\ExtraField;
10+
use Chamilo\CoreBundle\Entity\Tag;
11+
use Chamilo\CoreBundle\Repository\TagRepository;
12+
use Chamilo\Tests\AbstractApiTest;
13+
use Chamilo\Tests\ChamiloTestTrait;
14+
15+
class TagRepositoryTest extends AbstractApiTest
16+
{
17+
use ChamiloTestTrait;
18+
19+
public function testCreate(): void
20+
{
21+
self::bootKernel();
22+
23+
$em = $this->getManager();
24+
$repo = self::getContainer()->get(TagRepository::class);
25+
$defaultCount = $repo->count([]);
26+
27+
$extraField = (new ExtraField())
28+
->setDisplayText('test')
29+
->setVariable('test')
30+
->setExtraFieldType(ExtraField::USER_FIELD_TYPE)
31+
->setFieldType(\ExtraField::FIELD_TYPE_TEXT)
32+
;
33+
$em->persist($extraField);
34+
$em->flush();
35+
36+
$tag = (new Tag())
37+
->setTag('php')
38+
->setCount(1)
39+
->setField($extraField)
40+
;
41+
$this->assertHasNoEntityViolations($tag);
42+
$em->persist($tag);
43+
$em->flush();
44+
45+
$this->assertSame($defaultCount + 1, $repo->count([]));
46+
}
47+
}

tests/CourseBundle/Repository/CDocumentRepositoryTest.php

+28-5
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,16 @@ public function testCreateFolder(): void
4444
$course = $this->createCourse('Test');
4545

4646
// Create folder.
47-
$resourceLinkList = [[
48-
'cid' => $course->getId(),
49-
'visibility' => ResourceLink::VISIBILITY_PUBLISHED,
50-
]];
47+
$resourceLinkList = [
48+
[
49+
'cid' => $course->getId(),
50+
'visibility' => ResourceLink::VISIBILITY_PUBLISHED,
51+
],
52+
];
5153

5254
$folderName = 'folder1';
5355
$token = $this->getUserToken([]);
54-
$this->createClientWithCredentials($token)->request(
56+
$response = $this->createClientWithCredentials($token)->request(
5557
'POST',
5658
'/api/documents',
5759
[
@@ -73,6 +75,27 @@ public function testCreateFolder(): void
7375
'title' => $folderName,
7476
'parentResourceNode' => $course->getResourceNode()->getId(),
7577
]);
78+
79+
// Update.
80+
$id = $response->toArray()['@id'];
81+
82+
$this->createClientWithCredentials($token)->request(
83+
'PUT',
84+
$id,
85+
[
86+
'json' => [
87+
'title' => 'edited',
88+
],
89+
]
90+
);
91+
92+
$this->assertResponseIsSuccessful();
93+
$this->assertResponseStatusCodeSame(200);
94+
$this->assertJsonContains([
95+
'@context' => '/api/contexts/Documents',
96+
'@type' => 'Documents',
97+
'title' => 'edited',
98+
]);
7699
}
77100

78101
public function testUploadFile(): void

0 commit comments

Comments
 (0)