Tests: Add phpunit tests

pull/3965/head
Julio 4 years ago
parent e4424a1cea
commit 4e8a5fcedb
  1. 33
      tests/CoreBundle/Migrations/MigrationTest.php
  2. 3
      tests/CoreBundle/Repository/MessageRepositoryTest.php
  3. 2
      tests/CoreBundle/Repository/Node/AccessUrlRepositoryTest.php
  4. 24
      tests/CoreBundle/Tool/HandlerCollectionTest.php
  5. 48
      tests/CoreBundle/Tool/ToolChainTest.php
  6. 26
      tests/CourseBundle/Repository/CDocumentRepositoryTest.php

@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\Tests\CoreBundle\Migrations;
use Chamilo\Tests\ChamiloTestTrait;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Console\Tester\CommandTester;
class MigrationTest extends KernelTestCase
{
use ChamiloTestTrait;
public function testMigrations(): void
{
$kernel = static::createKernel();
$application = new Application($kernel);
$command = $application->find('doctrine:migrations:status');
$commandTester = new CommandTester($command);
$commandTester->execute([
// pass arguments to the helper
'--no-interaction',
]);
$output = $commandTester->getDisplay();
$this->assertStringContainsString('Chamilo\CoreBundle\Migrations\Schema\V200', $output);
}
}

@ -47,6 +47,9 @@ class MessageRepositoryTest extends AbstractApiTest
$this->assertHasNoEntityViolations($message);
$messageRepo->update($message);
$transport = $this->getContainer()->get('messenger.transport.sync_priority_high');
$this->assertCount(1, $transport->getSent());
// 1. Message exists in the inbox.
$count = $messageRepo->count(['msgType' => Message::MESSAGE_TYPE_INBOX]);
$this->assertSame(1, $count);

@ -69,7 +69,7 @@ class AccessUrlRepositoryTest extends KernelTestCase
$this->assertTrue($accessUrl->hasUser($user));
$this->assertSame($accessUrl->getId(), $accessUrl->getResourceIdentifier());
$this->assertSame(null, $accessUrl->getLimitCourses());
$this->assertNull($accessUrl->getLimitCourses());
$this->assertSame(2, $repo->count([]));
$this->assertSame(0, $accessUrl->getSettings()->count());
}

@ -6,7 +6,6 @@ declare(strict_types=1);
namespace Chamilo\Tests\CoreBundle\Tool;
use Chamilo\CoreBundle\Repository\ResourceRepository;
use Chamilo\CoreBundle\Tool\AbstractTool;
use Chamilo\CoreBundle\Tool\Agenda;
use Chamilo\CoreBundle\Tool\HandlerCollection;
@ -51,27 +50,6 @@ class HandlerCollectionTest extends AbstractApiTest
$handler = self::getContainer()->get(HandlerCollection::class);
$collection = $handler->getCollection();
foreach ($collection as $tool) {
$name = $tool->getName();
$this->assertNotEmpty($name);
$types = $tool->getResourceTypes();
//$icon = $tool->getIcon();
//$this->assertNotEmpty($icon, sprintf("Icons for tool %s doesnt exists", $name));
$em = $this->getManager();
/*if (!empty($types)) {
foreach ($types as $entityName) {
$repo = $em->getRepository($entityName);
//var_dump($repo->getClassName());
$msg = sprintf(
'Error in tool %s, entity: %s repo: %s not instance of ResourceRepository',
$name,
$entityName,
\get_class($repo)
);
$this->assertInstanceOf(ResourceRepository::class, $repo, $msg);
}
}*/
}
$this->assertTrue(\count($collection) > 0);
}
}

@ -10,6 +10,7 @@ use Chamilo\CoreBundle\Entity\AccessUrl;
use Chamilo\CoreBundle\Entity\BranchSync;
use Chamilo\CoreBundle\Entity\PersonalFile;
use Chamilo\CoreBundle\Entity\ResourceType;
use Chamilo\CoreBundle\Entity\Tool;
use Chamilo\CoreBundle\Tool\AbstractTool;
use Chamilo\CoreBundle\Tool\GlobalTool;
use Chamilo\CoreBundle\Tool\ToolChain;
@ -57,6 +58,23 @@ class ToolChainTest extends AbstractApiTest
$type = $toolChain->getResourceTypeNameByEntity(PersonalFile::class);
$this->assertSame($typeName, $type);
$type = $toolChain->getResourceTypeNameByEntity('test');
$this->assertNull($type);
}
public function testSetToolPermissions(): void
{
self::bootKernel();
$toolChain = self::getContainer()->get(ToolChain::class);
$em = $this->getManager();
$toolRepo = $em->getRepository(Tool::class);
$agendaTool = $toolRepo->findOneBy(['name' => 'agenda']);
$this->assertNotNull($agendaTool);
$toolChain->setToolPermissions($agendaTool);
}
public function testGetTools(): void
@ -65,9 +83,35 @@ class ToolChainTest extends AbstractApiTest
$toolChain = self::getContainer()->get(ToolChain::class);
$count = $toolChain->getTools();
$tools = $toolChain->getTools();
foreach ($tools as $tool) {
$name = $tool->getName();
$this->assertNotEmpty($name);
$link = $tool->getLink();
$this->assertNotEmpty($link, sprintf('Link for tool %s is empty', $name));
$types = $tool->getResourceTypes();
//$icon = $tool->getIcon();
//$this->assertNotEmpty($icon, sprintf("Icons for tool %s doesnt exists", $name));
//$em = $this->getManager();
/*if (!empty($types)) {
foreach ($types as $entityName) {
$repo = $em->getRepository($entityName);
//var_dump($repo->getClassName());
$msg = sprintf(
'Error in tool %s, entity: %s repo: %s not instance of ResourceRepository',
$name,
$entityName,
\get_class($repo)
);
$this->assertInstanceOf(ResourceRepository::class, $repo, $msg);
}
}*/
}
$this->assertTrue(\count($count) > 0);
$this->assertTrue(\count($tools) > 0);
}
public function testCreateTools(): void

@ -19,8 +19,9 @@ class CDocumentRepositoryTest extends AbstractApiTest
{
use ChamiloTestTrait;
public function testGetDocumentsAsAdmin(): void
public function testGetDocuments(): void
{
// Test as admin.
$token = $this->getUserToken([]);
$response = $this->createClientWithCredentials($token)->request('GET', '/api/documents');
$this->assertResponseIsSuccessful();
@ -38,6 +39,8 @@ class CDocumentRepositoryTest extends AbstractApiTest
$this->assertCount(0, $response->toArray()['hydra:member']);
$this->assertMatchesResourceCollectionJsonSchema(CDocument::class);
// Test as user
}
public function testCreateFolder(): void
@ -185,6 +188,15 @@ class CDocumentRepositoryTest extends AbstractApiTest
// Test access with another user. He cannot see the file, no cid is pass as a parameter.
$this->createUser('another');
$token = $this->getUserToken(
[
'username' => 'another',
'password' => 'another',
],
true
);
$client = $this->getClientWithGuiCredentials('another', 'another');
$client->request(
'GET',
@ -195,6 +207,15 @@ class CDocumentRepositoryTest extends AbstractApiTest
);
$this->assertResponseStatusCodeSame(403); // Unauthorized
$this->createClientWithCredentials($token)->request('GET', '/api/documents', [
'query' => [
'loadNode' => 1,
'resourceNode.parent' => $course->getResourceNode()->getId(),
'cid' => $courseId,
],
]);
$this->assertResponseStatusCodeSame(403); // Unauthorized
// Test access with another user. He CAN see the file, the cid is pass as a parameter
// and the course is open to the world by default.
$client->request(
@ -366,13 +387,14 @@ class CDocumentRepositoryTest extends AbstractApiTest
$document = (new CDocument())
->setFiletype('file')
->setTitle('title')
->setTitle('title 123')
->setParent($course)
;
$documentRepo->addResourceNode($document, $admin, $course);
$this->assertInstanceOf(ResourceNode::class, $document->getResourceNode());
$this->assertSame('title 123', (string) $document);
}
public function testSetVisibility(): void

Loading…
Cancel
Save