parent
							
								
									b96d83574b
								
							
						
					
					
						commit
						2a84c60a87
					
				@ -0,0 +1,33 @@ | 
				
			||||
<?php | 
				
			||||
 | 
				
			||||
declare(strict_types=1); | 
				
			||||
 | 
				
			||||
/* For licensing terms, see /license.txt */ | 
				
			||||
 | 
				
			||||
namespace Chamilo\Tests\CoreBundle\Repository; | 
				
			||||
 | 
				
			||||
use Chamilo\CoreBundle\Repository\ResourceFactory; | 
				
			||||
use Chamilo\CoreBundle\Repository\ResourceRepository; | 
				
			||||
use Chamilo\CourseBundle\Repository\CDocumentRepository; | 
				
			||||
use Chamilo\Tests\ChamiloTestTrait; | 
				
			||||
use InvalidArgumentException; | 
				
			||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | 
				
			||||
 | 
				
			||||
class ResourceFactoryTest extends WebTestCase | 
				
			||||
{ | 
				
			||||
    use ChamiloTestTrait; | 
				
			||||
 | 
				
			||||
    public function testGetRepositoryService(): void | 
				
			||||
    { | 
				
			||||
        self::bootKernel(); | 
				
			||||
        $factory = self::getContainer()->get(ResourceFactory::class); | 
				
			||||
 | 
				
			||||
        $this->expectException(InvalidArgumentException::class); | 
				
			||||
        $factory->getRepositoryService('aaa', 'bbb'); | 
				
			||||
 | 
				
			||||
        $repository = $factory->getRepositoryService('document', 'files'); | 
				
			||||
 | 
				
			||||
        $this->assertInstanceOf(ResourceRepository::class, $repository); | 
				
			||||
        $this->assertInstanceOf(CDocumentRepository::class, $repository); | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -0,0 +1,77 @@ | 
				
			||||
<?php | 
				
			||||
 | 
				
			||||
declare(strict_types=1); | 
				
			||||
 | 
				
			||||
/* For licensing terms, see /license.txt */ | 
				
			||||
 | 
				
			||||
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; | 
				
			||||
use Chamilo\Tests\AbstractApiTest; | 
				
			||||
use Chamilo\Tests\ChamiloTestTrait; | 
				
			||||
use InvalidArgumentException; | 
				
			||||
 | 
				
			||||
class HandlerCollectionTest extends AbstractApiTest | 
				
			||||
{ | 
				
			||||
    use ChamiloTestTrait; | 
				
			||||
 | 
				
			||||
    public function testGetCollection(): void | 
				
			||||
    { | 
				
			||||
        self::bootKernel(); | 
				
			||||
 | 
				
			||||
        $handler = self::getContainer()->get(HandlerCollection::class); | 
				
			||||
 | 
				
			||||
        $collection = $handler->getCollection(); | 
				
			||||
 | 
				
			||||
        $this->assertNotEmpty($collection); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public function testGetHandler(): void | 
				
			||||
    { | 
				
			||||
        self::bootKernel(); | 
				
			||||
 | 
				
			||||
        $handler = self::getContainer()->get(HandlerCollection::class); | 
				
			||||
 | 
				
			||||
        $this->expectException(InvalidArgumentException::class); | 
				
			||||
        $handler->getHandler('bla bla'); | 
				
			||||
 | 
				
			||||
        $tool = $handler->getHandler('agenda'); | 
				
			||||
 | 
				
			||||
        $this->assertInstanceOf(AbstractTool::class, $tool); | 
				
			||||
        $this->assertInstanceOf(Agenda::class, $tool); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public function testRepositoryHandlers(): void | 
				
			||||
    { | 
				
			||||
        self::bootKernel(); | 
				
			||||
 | 
				
			||||
        $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); | 
				
			||||
                } | 
				
			||||
            }*/ | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -0,0 +1,121 @@ | 
				
			||||
<?php | 
				
			||||
 | 
				
			||||
declare(strict_types=1); | 
				
			||||
 | 
				
			||||
/* For licensing terms, see /license.txt */ | 
				
			||||
 | 
				
			||||
namespace Chamilo\Tests\CoreBundle\Tool; | 
				
			||||
 | 
				
			||||
use Chamilo\CoreBundle\Entity\AccessUrl; | 
				
			||||
use Chamilo\CoreBundle\Entity\BranchSync; | 
				
			||||
use Chamilo\CoreBundle\Entity\PersonalFile; | 
				
			||||
use Chamilo\CoreBundle\Entity\ResourceType; | 
				
			||||
use Chamilo\CoreBundle\Tool\AbstractTool; | 
				
			||||
use Chamilo\CoreBundle\Tool\GlobalTool; | 
				
			||||
use Chamilo\CoreBundle\Tool\ToolChain; | 
				
			||||
use Chamilo\Tests\AbstractApiTest; | 
				
			||||
use Chamilo\Tests\ChamiloTestTrait; | 
				
			||||
 | 
				
			||||
class ToolChainTest extends AbstractApiTest | 
				
			||||
{ | 
				
			||||
    use ChamiloTestTrait; | 
				
			||||
 | 
				
			||||
    public function testGetToolFromName(): void | 
				
			||||
    { | 
				
			||||
        self::bootKernel(); | 
				
			||||
 | 
				
			||||
        $toolChain = self::getContainer()->get(ToolChain::class); | 
				
			||||
 | 
				
			||||
        $tool = $toolChain->getToolFromName('global'); | 
				
			||||
 | 
				
			||||
        $this->assertInstanceOf(AbstractTool::class, $tool); | 
				
			||||
        $this->assertInstanceOf(GlobalTool::class, $tool); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public function testResourceType(): void | 
				
			||||
    { | 
				
			||||
        self::bootKernel(); | 
				
			||||
 | 
				
			||||
        $toolChain = self::getContainer()->get(ToolChain::class); | 
				
			||||
 | 
				
			||||
        $tool = $toolChain->getToolFromName('global'); | 
				
			||||
        $entity = $tool->getEntityByResourceType('urls'); | 
				
			||||
        $this->assertSame($entity, AccessUrl::class); | 
				
			||||
 | 
				
			||||
        $typeName = 'urls'; | 
				
			||||
        $type = $tool->getTypeNameByEntity(AccessUrl::class); | 
				
			||||
        $this->assertSame($typeName, $type); | 
				
			||||
 | 
				
			||||
        $type = $toolChain->getResourceTypeNameByEntity(AccessUrl::class); | 
				
			||||
        $this->assertSame($typeName, $type); | 
				
			||||
 | 
				
			||||
        $typeName = 'files'; | 
				
			||||
 | 
				
			||||
        $tool = $toolChain->getToolFromName('user'); | 
				
			||||
        $type = $tool->getTypeNameByEntity(PersonalFile::class); | 
				
			||||
        $this->assertSame($typeName, $type); | 
				
			||||
 | 
				
			||||
        $type = $toolChain->getResourceTypeNameByEntity(PersonalFile::class); | 
				
			||||
        $this->assertSame($typeName, $type); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public function testGetTools(): void | 
				
			||||
    { | 
				
			||||
        self::bootKernel(); | 
				
			||||
 | 
				
			||||
        $toolChain = self::getContainer()->get(ToolChain::class); | 
				
			||||
 | 
				
			||||
        $count = $toolChain->getTools(); | 
				
			||||
 | 
				
			||||
        $this->assertTrue(\count($count) > 0); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public function testCreateTools(): void | 
				
			||||
    { | 
				
			||||
        self::bootKernel(); | 
				
			||||
 | 
				
			||||
        $toolChain = self::getContainer()->get(ToolChain::class); | 
				
			||||
        $countBefore = \count($toolChain->getTools()); | 
				
			||||
 | 
				
			||||
        $toolChain->createTools(); | 
				
			||||
 | 
				
			||||
        $tools = $toolChain->getTools(); | 
				
			||||
 | 
				
			||||
        $this->assertSame($countBefore, \count($tools)); | 
				
			||||
 | 
				
			||||
        $em = $this->getManager(); | 
				
			||||
 | 
				
			||||
        // Delete BranchSync | 
				
			||||
        $branchRepo = $em->getRepository(BranchSync::class); | 
				
			||||
        $items = $branchRepo->findAll(); | 
				
			||||
        foreach ($items as $item) { | 
				
			||||
            $em->remove($item); | 
				
			||||
        } | 
				
			||||
        $em->flush(); | 
				
			||||
 | 
				
			||||
        // Delete AccessUrl | 
				
			||||
        $urlRepo = $em->getRepository(AccessUrl::class); | 
				
			||||
        $items = $urlRepo->findAll(); | 
				
			||||
        foreach ($items as $item) { | 
				
			||||
            $em->remove($item); | 
				
			||||
        } | 
				
			||||
        $em->flush(); | 
				
			||||
 | 
				
			||||
        $resourceTypeRepo = $em->getRepository(ResourceType::class); | 
				
			||||
 | 
				
			||||
        $items = $resourceTypeRepo->findAll(); | 
				
			||||
        foreach ($items as $item) { | 
				
			||||
            $em->remove($item); | 
				
			||||
        } | 
				
			||||
        $em->flush(); | 
				
			||||
 | 
				
			||||
        $items = $resourceTypeRepo->findAll(); | 
				
			||||
        $this->assertSame([], $items); | 
				
			||||
 | 
				
			||||
        $toolChain = self::getContainer()->get(ToolChain::class); | 
				
			||||
        $toolChain->createTools(); | 
				
			||||
 | 
				
			||||
        $items = $resourceTypeRepo->findAll(); | 
				
			||||
        $this->assertNotEmpty($items); | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -0,0 +1,28 @@ | 
				
			||||
<?php | 
				
			||||
 | 
				
			||||
declare(strict_types=1); | 
				
			||||
 | 
				
			||||
/* For licensing terms, see /license.txt */ | 
				
			||||
 | 
				
			||||
namespace Chamilo\Tests\CoreBundle\Twig\Extension; | 
				
			||||
 | 
				
			||||
use Chamilo\CoreBundle\Twig\Extension\ChamiloExtension; | 
				
			||||
use Chamilo\Tests\AbstractApiTest; | 
				
			||||
use Chamilo\Tests\ChamiloTestTrait; | 
				
			||||
 | 
				
			||||
class ChamiloExtensionTest extends AbstractApiTest | 
				
			||||
{ | 
				
			||||
    use ChamiloTestTrait; | 
				
			||||
 | 
				
			||||
    public function testGetIllustration(): void | 
				
			||||
    { | 
				
			||||
        self::bootKernel(); | 
				
			||||
 | 
				
			||||
        $extension = self::getContainer()->get(ChamiloExtension::class); | 
				
			||||
 | 
				
			||||
        $user = $this->createUser('test'); | 
				
			||||
        $illustrationUrl = $extension->getIllustration($user); | 
				
			||||
 | 
				
			||||
        $this->assertSame('/img/icons/32/unknown.png', $illustrationUrl); | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -0,0 +1,33 @@ | 
				
			||||
<?php | 
				
			||||
 | 
				
			||||
declare(strict_types=1); | 
				
			||||
 | 
				
			||||
/* For licensing terms, see /license.txt */ | 
				
			||||
 | 
				
			||||
namespace Chamilo\Tests\CoreBundle\Twig; | 
				
			||||
 | 
				
			||||
use Chamilo\CoreBundle\Twig\SettingsHelper; | 
				
			||||
use Chamilo\Tests\AbstractApiTest; | 
				
			||||
use Chamilo\Tests\ChamiloTestTrait; | 
				
			||||
use Sylius\Bundle\SettingsBundle\Model\SettingsInterface; | 
				
			||||
 | 
				
			||||
class SettingsHelperTest extends AbstractApiTest | 
				
			||||
{ | 
				
			||||
    use ChamiloTestTrait; | 
				
			||||
 | 
				
			||||
    public function testGetSettings(): void | 
				
			||||
    { | 
				
			||||
        self::bootKernel(); | 
				
			||||
 | 
				
			||||
        $helper = self::getContainer()->get(SettingsHelper::class); | 
				
			||||
 | 
				
			||||
        $settings = $helper->getSettings('admin'); | 
				
			||||
 | 
				
			||||
        $this->assertInstanceOf(SettingsInterface::class, $settings); | 
				
			||||
        $this->assertSame('chamilo_settings', $helper->getName()); | 
				
			||||
 | 
				
			||||
        $defaultTheme = $helper->getSettingsParameter('platform.theme'); | 
				
			||||
 | 
				
			||||
        $this->assertSame('chamilo', $defaultTheme); | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
					Loading…
					
					
				
		Reference in new issue