Chamilo is a learning management system focused on ease of use and accessibility
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
chamilo-lms/tests/CoreBundle/Controller/AssetControllerTest.php

112 lines
3.3 KiB

<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\Tests\CoreBundle\Controller;
use Chamilo\CoreBundle\Entity\Asset;
use Chamilo\CoreBundle\Repository\AssetRepository;
use Chamilo\Tests\ChamiloTestTrait;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\Response;
class AssetControllerTest extends WebTestCase
{
use ChamiloTestTrait;
public function testCreateWatermark(): void
{
$client = static::createClient();
$file = $this->getUploadedFile();
$assetRepo = self::getContainer()->get(AssetRepository::class);
// Create asset.
$asset = (new Asset())
->setTitle('test')
->setCategory(Asset::WATERMARK)
->setCrop('100,100,100,100')
->setFile($file)
;
$this->assertHasNoEntityViolations($asset);
$assetRepo->update($asset);
$folder = $assetRepo->getFolder($asset);
$this->assertSame('/watermark/'.$asset->getFile()->getFilename().'/', $folder);
$url = $assetRepo->getAssetUrl($asset);
$client->request('GET', $url);
$this->assertResponseIsSuccessful();
$asset = (new Asset())
->setTitle('test2')
->setCategory(Asset::WATERMARK)
->setCrop('100,100,100,100')
;
$assetRepo->createFromString($asset, 'text/html', 'hello');
$this->assertHasNoEntityViolations($asset);
$asset = (new Asset())
->setTitle('test3')
->setCategory(Asset::WATERMARK)
;
$file = [
'tmp_name' => $this->getUploadedFile()->getRealPath(),
'name' => $this->getUploadedFile()->getFilename(),
'type' => $this->getUploadedFile()->getMimeType(),
'size' => $this->getUploadedFile()->getSize(),
'error' => UPLOAD_ERR_OK,
];
$assetRepo->createFromRequest($asset, $file);
$this->assertHasNoEntityViolations($asset);
}
public function testCreateScormAsset(): void
{
$client = static::createClient();
$file = $this->getUploadedFile();
$assetRepo = self::getContainer()->get(AssetRepository::class);
$asset = (new Asset())
->setTitle('test')
->setCategory(Asset::SCORM)
->setFile($file)
;
$this->assertHasNoEntityViolations($asset);
$assetRepo->update($asset);
$url = $assetRepo->getAssetUrl($asset);
$client->request('GET', $url);
$this->assertResponseIsSuccessful();
}
public function testShowFile(): void
{
$client = static::createClient();
$file = $this->getUploadedFile();
$assetRepo = self::getContainer()->get(AssetRepository::class);
$em = $this->getEntityManager();
// Create asset.
$asset = (new Asset())
->setTitle('test')
->setCategory(Asset::WATERMARK)
->setFile($file)
;
$em->persist($asset);
$em->flush();
$url = $assetRepo->getAssetUrl($asset);
$client->request('GET', $url);
$this->assertResponseIsSuccessful();
$client->request('GET', $url.'not-existed');
$this->assertSame(Response::HTTP_INTERNAL_SERVER_ERROR, $client->getResponse()->getStatusCode());
}
}