|
@@ -1,4 +1,6 @@
|
|
|
-<?php /** @noinspection DuplicatedCode */
|
|
|
|
|
|
|
+<?php
|
|
|
|
|
+
|
|
|
|
|
+namespace App\Tests\Service\Storage;
|
|
|
|
|
|
|
|
use ApiPlatform\Core\Api\IriConverterInterface;
|
|
use ApiPlatform\Core\Api\IriConverterInterface;
|
|
|
use App\ApiResources\DownloadRequest;
|
|
use App\ApiResources\DownloadRequest;
|
|
@@ -10,11 +12,13 @@ use App\Enum\Core\FileStatusEnum;
|
|
|
use App\Enum\Core\FileTypeEnum;
|
|
use App\Enum\Core\FileTypeEnum;
|
|
|
use App\Repository\Access\AccessRepository;
|
|
use App\Repository\Access\AccessRepository;
|
|
|
use App\Service\Storage\LocalStorage;
|
|
use App\Service\Storage\LocalStorage;
|
|
|
|
|
+use DateTime;
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
use Gaufrette\Filesystem;
|
|
use Gaufrette\Filesystem;
|
|
|
use JetBrains\PhpStorm\Pure;
|
|
use JetBrains\PhpStorm\Pure;
|
|
|
use Knp\Bundle\GaufretteBundle\FilesystemMap;
|
|
use Knp\Bundle\GaufretteBundle\FilesystemMap;
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
+use RuntimeException;
|
|
|
|
|
|
|
|
class TestableLocalStorage extends LocalStorage {
|
|
class TestableLocalStorage extends LocalStorage {
|
|
|
public const FS_KEY = parent::FS_KEY;
|
|
public const FS_KEY = parent::FS_KEY;
|
|
@@ -47,6 +51,9 @@ class LocalStorageTest extends TestCase
|
|
|
$this->filesystemMap->method('get')->with(TestableLocalStorage::FS_KEY)->willReturn($this->filesystem);
|
|
$this->filesystemMap->method('get')->with(TestableLocalStorage::FS_KEY)->willReturn($this->filesystem);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @see LocalStorage::exists()
|
|
|
|
|
+ */
|
|
|
public function testExists(): void {
|
|
public function testExists(): void {
|
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
|
->setConstructorArgs([$this->filesystemMap, $this->entityManager, $this->accessRepository, $this->iriConverter])
|
|
->setConstructorArgs([$this->filesystemMap, $this->entityManager, $this->accessRepository, $this->iriConverter])
|
|
@@ -61,6 +68,9 @@ class LocalStorageTest extends TestCase
|
|
|
$this->assertTrue($fileStorage->exists($file));
|
|
$this->assertTrue($fileStorage->exists($file));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @see LocalStorage::exists()
|
|
|
|
|
+ */
|
|
|
public function testExistsInexistant(): void {
|
|
public function testExistsInexistant(): void {
|
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
|
->setConstructorArgs([$this->filesystemMap, $this->entityManager, $this->accessRepository, $this->iriConverter])
|
|
->setConstructorArgs([$this->filesystemMap, $this->entityManager, $this->accessRepository, $this->iriConverter])
|
|
@@ -75,6 +85,9 @@ class LocalStorageTest extends TestCase
|
|
|
$this->assertFalse($fileStorage->exists($file));
|
|
$this->assertFalse($fileStorage->exists($file));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @see LocalStorage::getDownloadIri()
|
|
|
|
|
+ */
|
|
|
public function testGetDownloadIri(): void
|
|
public function testGetDownloadIri(): void
|
|
|
{
|
|
{
|
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
@@ -97,6 +110,9 @@ class LocalStorageTest extends TestCase
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @see LocalStorage::listByOwner()
|
|
|
|
|
+ */
|
|
|
public function testListByOwner(): void
|
|
public function testListByOwner(): void
|
|
|
{
|
|
{
|
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
@@ -116,6 +132,9 @@ class LocalStorageTest extends TestCase
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @see LocalStorage::read()
|
|
|
|
|
+ */
|
|
|
public function testRead(): void
|
|
public function testRead(): void
|
|
|
{
|
|
{
|
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
@@ -134,6 +153,9 @@ class LocalStorageTest extends TestCase
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @see LocalStorage::prepareFile()
|
|
|
|
|
+ */
|
|
|
public function testPrepareFile(): void
|
|
public function testPrepareFile(): void
|
|
|
{
|
|
{
|
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
@@ -172,6 +194,9 @@ class LocalStorageTest extends TestCase
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @see LocalStorage::prepareFile()
|
|
|
|
|
+ */
|
|
|
public function testPrepareFileDefaultValues(): void
|
|
public function testPrepareFileDefaultValues(): void
|
|
|
{
|
|
{
|
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
@@ -198,6 +223,9 @@ class LocalStorageTest extends TestCase
|
|
|
$this->assertEquals('text/plain', $file->getMimeType());
|
|
$this->assertEquals('text/plain', $file->getMimeType());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @see LocalStorage::prepareFile()
|
|
|
|
|
+ */
|
|
|
public function testPrepareFileNoFlush(): void
|
|
public function testPrepareFileNoFlush(): void
|
|
|
{
|
|
{
|
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
@@ -225,6 +253,9 @@ class LocalStorageTest extends TestCase
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @see LocalStorage::writeFile()
|
|
|
|
|
+ */
|
|
|
public function testWriteFileNewFile(): void {
|
|
public function testWriteFileNewFile(): void {
|
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
|
->setConstructorArgs([$this->filesystemMap, $this->entityManager, $this->accessRepository, $this->iriConverter])
|
|
->setConstructorArgs([$this->filesystemMap, $this->entityManager, $this->accessRepository, $this->iriConverter])
|
|
@@ -276,6 +307,9 @@ class LocalStorageTest extends TestCase
|
|
|
$this->assertEquals($file, $returned);
|
|
$this->assertEquals($file, $returned);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @see LocalStorage::writeFile()
|
|
|
|
|
+ */
|
|
|
public function testWriteFileExistingFile(): void {
|
|
public function testWriteFileExistingFile(): void {
|
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
|
->setConstructorArgs([$this->filesystemMap, $this->entityManager, $this->accessRepository, $this->iriConverter])
|
|
->setConstructorArgs([$this->filesystemMap, $this->entityManager, $this->accessRepository, $this->iriConverter])
|
|
@@ -325,6 +359,9 @@ class LocalStorageTest extends TestCase
|
|
|
$this->assertEquals($file, $returned);
|
|
$this->assertEquals($file, $returned);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @see LocalStorage::writeFile()
|
|
|
|
|
+ */
|
|
|
public function testWriteFileExistingButMissingFile(): void
|
|
public function testWriteFileExistingButMissingFile(): void
|
|
|
{
|
|
{
|
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
@@ -353,9 +390,12 @@ class LocalStorageTest extends TestCase
|
|
|
$this->expectException(RuntimeException::class);
|
|
$this->expectException(RuntimeException::class);
|
|
|
$this->expectDeprecationMessage('The file `' . $key . '` does not exist in the file storage');
|
|
$this->expectDeprecationMessage('The file `' . $key . '` does not exist in the file storage');
|
|
|
|
|
|
|
|
- $returned = $fileStorage->writeFile($file, '12346', $author);
|
|
|
|
|
|
|
+ $fileStorage->writeFile($file, '12346', $author);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @see LocalStorage::writeFile()
|
|
|
|
|
+ */
|
|
|
public function testWriteFileWithAccessOwner(): void {
|
|
public function testWriteFileWithAccessOwner(): void {
|
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
|
->setConstructorArgs([$this->filesystemMap, $this->entityManager, $this->accessRepository, $this->iriConverter])
|
|
->setConstructorArgs([$this->filesystemMap, $this->entityManager, $this->accessRepository, $this->iriConverter])
|
|
@@ -395,7 +435,9 @@ class LocalStorageTest extends TestCase
|
|
|
$fileStorage->writeFile($file, $content, $author);
|
|
$fileStorage->writeFile($file, $content, $author);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @see LocalStorage::writeFile()
|
|
|
|
|
+ */
|
|
|
public function testWriteFileWithNoName(): void
|
|
public function testWriteFileWithNoName(): void
|
|
|
{
|
|
{
|
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
@@ -414,6 +456,9 @@ class LocalStorageTest extends TestCase
|
|
|
$fileStorage->writeFile($file, '...', $author);
|
|
$fileStorage->writeFile($file, '...', $author);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @see LocalStorage::makeFile()
|
|
|
|
|
+ */
|
|
|
public function testMakeFile(): void {
|
|
public function testMakeFile(): void {
|
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
|
->setConstructorArgs([$this->filesystemMap, $this->entityManager, $this->accessRepository, $this->iriConverter])
|
|
->setConstructorArgs([$this->filesystemMap, $this->entityManager, $this->accessRepository, $this->iriConverter])
|
|
@@ -447,6 +492,9 @@ class LocalStorageTest extends TestCase
|
|
|
'mime/type');
|
|
'mime/type');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @see LocalStorage::delete()
|
|
|
|
|
+ */
|
|
|
public function testDelete(): void {
|
|
public function testDelete(): void {
|
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
|
->setConstructorArgs([$this->filesystemMap, $this->entityManager, $this->accessRepository, $this->iriConverter])
|
|
->setConstructorArgs([$this->filesystemMap, $this->entityManager, $this->accessRepository, $this->iriConverter])
|
|
@@ -470,6 +518,9 @@ class LocalStorageTest extends TestCase
|
|
|
$this->assertEquals($file, $returned);
|
|
$this->assertEquals($file, $returned);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @see LocalStorage::delete()
|
|
|
|
|
+ */
|
|
|
public function testDeleteFailed(): void {
|
|
public function testDeleteFailed(): void {
|
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
|
->setConstructorArgs([$this->filesystemMap, $this->entityManager, $this->accessRepository, $this->iriConverter])
|
|
->setConstructorArgs([$this->filesystemMap, $this->entityManager, $this->accessRepository, $this->iriConverter])
|
|
@@ -494,6 +545,9 @@ class LocalStorageTest extends TestCase
|
|
|
$fileStorage->delete($file, $author);
|
|
$fileStorage->delete($file, $author);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @see LocalStorage::getPrefix()
|
|
|
|
|
+ */
|
|
|
public function testGetPrefixAccess(): void {
|
|
public function testGetPrefixAccess(): void {
|
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
|
->setConstructorArgs([$this->filesystemMap, $this->entityManager, $this->accessRepository, $this->iriConverter])
|
|
->setConstructorArgs([$this->filesystemMap, $this->entityManager, $this->accessRepository, $this->iriConverter])
|
|
@@ -512,6 +566,9 @@ class LocalStorageTest extends TestCase
|
|
|
$this->assertEquals('organization/2/1', $prefix);
|
|
$this->assertEquals('organization/2/1', $prefix);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @see LocalStorage::getPrefix()
|
|
|
|
|
+ */
|
|
|
public function testGetPrefixOrganization(): void {
|
|
public function testGetPrefixOrganization(): void {
|
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
|
->setConstructorArgs([$this->filesystemMap, $this->entityManager, $this->accessRepository, $this->iriConverter])
|
|
->setConstructorArgs([$this->filesystemMap, $this->entityManager, $this->accessRepository, $this->iriConverter])
|
|
@@ -526,6 +583,9 @@ class LocalStorageTest extends TestCase
|
|
|
$this->assertEquals('organization/1', $prefix);
|
|
$this->assertEquals('organization/1', $prefix);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @see LocalStorage::getPrefix()
|
|
|
|
|
+ */
|
|
|
public function testGetPrefixPerson(): void {
|
|
public function testGetPrefixPerson(): void {
|
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
|
->setConstructorArgs([$this->filesystemMap, $this->entityManager, $this->accessRepository, $this->iriConverter])
|
|
->setConstructorArgs([$this->filesystemMap, $this->entityManager, $this->accessRepository, $this->iriConverter])
|
|
@@ -540,6 +600,9 @@ class LocalStorageTest extends TestCase
|
|
|
$this->assertEquals('person/1', $prefix);
|
|
$this->assertEquals('person/1', $prefix);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @see LocalStorage::getPrefix()
|
|
|
|
|
+ */
|
|
|
public function testGetPrefixTemp(): void {
|
|
public function testGetPrefixTemp(): void {
|
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
|
->setConstructorArgs([$this->filesystemMap, $this->entityManager, $this->accessRepository, $this->iriConverter])
|
|
->setConstructorArgs([$this->filesystemMap, $this->entityManager, $this->accessRepository, $this->iriConverter])
|
|
@@ -554,6 +617,9 @@ class LocalStorageTest extends TestCase
|
|
|
$this->assertEquals('temp/organization/1', $prefix);
|
|
$this->assertEquals('temp/organization/1', $prefix);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @see LocalStorage::getPrefix()
|
|
|
|
|
+ */
|
|
|
public function testGetPrefixWithType(): void {
|
|
public function testGetPrefixWithType(): void {
|
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
|
->setConstructorArgs([$this->filesystemMap, $this->entityManager, $this->accessRepository, $this->iriConverter])
|
|
->setConstructorArgs([$this->filesystemMap, $this->entityManager, $this->accessRepository, $this->iriConverter])
|
|
@@ -568,6 +634,9 @@ class LocalStorageTest extends TestCase
|
|
|
$this->assertEquals('organization/1/licence_cmf', $prefix);
|
|
$this->assertEquals('organization/1/licence_cmf', $prefix);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @see LocalStorage::guessMimeTypeFromFilename()
|
|
|
|
|
+ */
|
|
|
public function testGuessMimeTypeFromFilename(): void {
|
|
public function testGuessMimeTypeFromFilename(): void {
|
|
|
$this->assertEquals('application/pdf', TestableLocalStorage::guessMimeTypeFromFilename('file.pdf'));
|
|
$this->assertEquals('application/pdf', TestableLocalStorage::guessMimeTypeFromFilename('file.pdf'));
|
|
|
$this->assertEquals('text/csv', TestableLocalStorage::guessMimeTypeFromFilename('file.csv'));
|
|
$this->assertEquals('text/csv', TestableLocalStorage::guessMimeTypeFromFilename('file.csv'));
|
|
@@ -579,6 +648,9 @@ class LocalStorageTest extends TestCase
|
|
|
$this->assertEquals(null, TestableLocalStorage::guessMimeTypeFromFilename('file.invalid'));
|
|
$this->assertEquals(null, TestableLocalStorage::guessMimeTypeFromFilename('file.invalid'));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @see LocalStorage::getMimeTypeFromExt()
|
|
|
|
|
+ */
|
|
|
public function testGuessMimeTypeFromExt(): void {
|
|
public function testGuessMimeTypeFromExt(): void {
|
|
|
$this->assertEquals('application/pdf', TestableLocalStorage::getMimeTypeFromExt('pdf'));
|
|
$this->assertEquals('application/pdf', TestableLocalStorage::getMimeTypeFromExt('pdf'));
|
|
|
$this->assertEquals('text/csv', TestableLocalStorage::getMimeTypeFromExt('csv'));
|
|
$this->assertEquals('text/csv', TestableLocalStorage::getMimeTypeFromExt('csv'));
|
|
@@ -591,6 +663,9 @@ class LocalStorageTest extends TestCase
|
|
|
$this->assertEquals(null, TestableLocalStorage::getMimeTypeFromExt('invalid'));
|
|
$this->assertEquals(null, TestableLocalStorage::getMimeTypeFromExt('invalid'));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @see LocalStorage::getOrganizationAndPersonFromOwner()
|
|
|
|
|
+ */
|
|
|
public function testGetOrganizationAndPersonFromOwner(): void {
|
|
public function testGetOrganizationAndPersonFromOwner(): void {
|
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
$fileStorage = $this->getMockBuilder(TestableLocalStorage::class)
|
|
|
->setConstructorArgs([$this->filesystemMap, $this->entityManager, $this->accessRepository, $this->iriConverter])
|
|
->setConstructorArgs([$this->filesystemMap, $this->entityManager, $this->accessRepository, $this->iriConverter])
|