diff --git a/tests/CoreBundle/Migrations/MigrationTest.php b/tests/CoreBundle/Migrations/MigrationTest.php new file mode 100644 index 0000000000..8741167618 --- /dev/null +++ b/tests/CoreBundle/Migrations/MigrationTest.php @@ -0,0 +1,33 @@ +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); + } +} diff --git a/tests/CoreBundle/Repository/MessageRepositoryTest.php b/tests/CoreBundle/Repository/MessageRepositoryTest.php index 4210786f59..8c165f1a54 100644 --- a/tests/CoreBundle/Repository/MessageRepositoryTest.php +++ b/tests/CoreBundle/Repository/MessageRepositoryTest.php @@ -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); diff --git a/tests/CoreBundle/Repository/Node/AccessUrlRepositoryTest.php b/tests/CoreBundle/Repository/Node/AccessUrlRepositoryTest.php index 9edb51ae5b..80f74154d2 100644 --- a/tests/CoreBundle/Repository/Node/AccessUrlRepositoryTest.php +++ b/tests/CoreBundle/Repository/Node/AccessUrlRepositoryTest.php @@ -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()); } diff --git a/tests/CoreBundle/Tool/HandlerCollectionTest.php b/tests/CoreBundle/Tool/HandlerCollectionTest.php index 4df1f7cebd..20d97487c9 100644 --- a/tests/CoreBundle/Tool/HandlerCollectionTest.php +++ b/tests/CoreBundle/Tool/HandlerCollectionTest.php @@ -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); } } diff --git a/tests/CoreBundle/Tool/ToolChainTest.php b/tests/CoreBundle/Tool/ToolChainTest.php index dec4cbe51e..df316db101 100644 --- a/tests/CoreBundle/Tool/ToolChainTest.php +++ b/tests/CoreBundle/Tool/ToolChainTest.php @@ -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 diff --git a/tests/CourseBundle/Repository/CDocumentRepositoryTest.php b/tests/CourseBundle/Repository/CDocumentRepositoryTest.php index a849ae470f..9b944ca0e8 100644 --- a/tests/CourseBundle/Repository/CDocumentRepositoryTest.php +++ b/tests/CourseBundle/Repository/CDocumentRepositoryTest.php @@ -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