Prechádzať zdrojové kódy

add test for FileStorage::getDownloadIri

Olivier Massot 3 rokov pred
rodič
commit
62bd117011
1 zmenil súbory, kde vykonal 23 pridanie a 1 odobranie
  1. 23 1
      tests/Service/Storage/FileStorageTest.php

+ 23 - 1
tests/Service/Storage/FileStorageTest.php

@@ -1,6 +1,7 @@
 <?php /** @noinspection DuplicatedCode */
 
 use ApiPlatform\Core\Api\IriConverterInterface;
+use App\ApiResources\DownloadRequest;
 use App\Entity\Access\Access;
 use App\Entity\Core\File;
 use App\Entity\Organization\Organization;
@@ -24,7 +25,6 @@ class TestableFileStorage extends FileStorage {
     #[Pure] public function getOrganizationAndPersonFromOwner(mixed $owner): array {
         return parent::getOrganizationAndPersonFromOwner($owner);
     }
-
 }
 
 
@@ -75,6 +75,28 @@ class FileStorageTest extends TestCase
         $this->assertFalse($fileStorage->exists($file));
     }
 
+    public function testGetDownloadIri(): void
+    {
+        $fileStorage = $this->getMockBuilder(TestableFileStorage::class)
+            ->setConstructorArgs([$this->filesystemMap, $this->entityManager, $this->accessRepository, $this->iriConverter])
+            ->setMethodsExcept(['getDownloadIri'])
+            ->getMock();
+
+        $file = $this->getMockBuilder(File::class)->getMock();
+        $file->method('getId')->willReturn(1);
+
+        $this->iriConverter
+            ->expects(self::once())
+            ->method('getItemIriFromResourceClass')
+            ->with(DownloadRequest::class, ['fileId' => 1])
+            ->willReturn('/api/download/1');
+
+        $this->assertEquals(
+            '/api/download/1',
+            $fileStorage->getDownloadIri($file)
+        );
+    }
+
     public function testListByOwner(): void
     {
         $fileStorage = $this->getMockBuilder(TestableFileStorage::class)