diff --git a/tests/e2e/Services/Storage/StorageBase.php b/tests/e2e/Services/Storage/StorageBase.php index 6879645a22..c67cfcc99a 100644 --- a/tests/e2e/Services/Storage/StorageBase.php +++ b/tests/e2e/Services/Storage/StorageBase.php @@ -30,7 +30,7 @@ trait StorageBase 'name' => 'Test Bucket', 'fileSecurity' => true, 'maximumFileSize' => 2000000, //2MB - 'allowedFileExtensions' => ['jpg', 'png', 'jfif'], + 'allowedFileExtensions' => ['jpg', 'png', 'jfif', 'webp'], 'permissions' => [ Permission::read(Role::any()), Permission::create(Role::any()), @@ -263,7 +263,39 @@ trait StorageBase $this->assertEquals(400, $res['headers']['status-code']); $this->assertEquals(Exception::STORAGE_INVALID_APPWRITE_ID, $res['body']['type']); - return ['bucketId' => $bucketId, 'fileId' => $file['body']['$id'], 'largeFileId' => $largeFile['body']['$id'], 'largeBucketId' => $bucket2['body']['$id']]; + /** + * Test for SUCCESS - Upload and view webp image + */ + $webpFile = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', array_merge([ + 'content-type' => 'multipart/form-data', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'fileId' => ID::unique(), + 'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/image.webp'), 'image/webp', 'image.webp'), + 'permissions' => [ + Permission::read(Role::any()), + Permission::update(Role::any()), + Permission::delete(Role::any()), + ], + ]); + $this->assertEquals(201, $webpFile['headers']['status-code']); + $this->assertNotEmpty($webpFile['body']['$id']); + $this->assertEquals('image.webp', $webpFile['body']['name']); + $this->assertEquals('image/webp', $webpFile['body']['mimeType']); + + $webpFileId = $webpFile['body']['$id']; + + // View webp file + $webpView = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $webpFileId . '/view', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->assertEquals(200, $webpView['headers']['status-code']); + $this->assertEquals('image/webp', $webpView['headers']['content-type']); + $this->assertNotEmpty($webpView['body']); + + return ['bucketId' => $bucketId, 'fileId' => $file['body']['$id'], 'largeFileId' => $largeFile['body']['$id'], 'largeBucketId' => $bucket2['body']['$id'], 'webpFileId' => $webpFileId]; } public function testCreateBucketFileZstdCompression(): array @@ -416,7 +448,7 @@ trait StorageBase ], ]); $this->assertEquals(200, $files['headers']['status-code']); - $this->assertEquals(0, count($files['body']['files'])); + $this->assertEquals(1, count($files['body']['files'])); $files = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $data['bucketId'] . '/files', array_merge([ 'content-type' => 'application/json', @@ -869,6 +901,31 @@ trait StorageBase return $data; } + /** + * @depends testCreateBucketFile + */ + public function testFilePreview(array $data): array + { + $bucketId = $data['bucketId']; + $fileId = $data['fileId']; + + // Preview PNG as webp + $preview = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/preview', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'width' => 300, + 'height' => 300, + 'output' => 'webp', + ]); + + $this->assertEquals(200, $preview['headers']['status-code']); + $this->assertEquals('image/webp', $preview['headers']['content-type']); + $this->assertNotEmpty($preview['body']); + + return $data; + } + /** * @depends testUpdateBucketFile */ diff --git a/tests/resources/image.webp b/tests/resources/image.webp new file mode 100644 index 0000000000..4a8791784a Binary files /dev/null and b/tests/resources/image.webp differ