From de004c7c331b66e3cf676b4dc8afada672c64c37 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 6 Sep 2021 15:33:06 +0200 Subject: [PATCH] test(storage): default permissions with client --- phpunit.xml | 2 +- .../Storage/StorageCustomClientTest.php | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/phpunit.xml b/phpunit.xml index 2fbb75e22..ceba1dcbf 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -6,7 +6,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="false" + stopOnFailure="true" > diff --git a/tests/e2e/Services/Storage/StorageCustomClientTest.php b/tests/e2e/Services/Storage/StorageCustomClientTest.php index 19266256a..59fc63d2e 100644 --- a/tests/e2e/Services/Storage/StorageCustomClientTest.php +++ b/tests/e2e/Services/Storage/StorageCustomClientTest.php @@ -2,6 +2,8 @@ namespace Tests\E2E\Services\Storage; +use CURLFile; +use Tests\E2E\Client; use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Scopes\SideClient; @@ -11,4 +13,30 @@ class StorageCustomClientTest extends Scope use StorageBase; use ProjectCustom; use SideClient; + + public function testCreateFileDefaultPermissions():void + { + /** + * Test for SUCCESS + */ + $file = $this->client->call(Client::METHOD_POST, '/storage/files', array_merge([ + 'content-type' => 'multipart/form-data', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'logo.png'), + 'folderId' => 'xyz', + ]); + + $this->assertEquals($file['headers']['status-code'], 201); + $this->assertNotEmpty($file['body']['$id']); + $this->assertNotEmpty($file['body']['$permissions']); + $this->assertArrayHasKey('write', $file['body']['$permissions']); + $this->assertArrayHasKey('read', $file['body']['$permissions']); + $this->assertContains('user:'.$this->getUser()['$id'], $file['body']['$permissions']['read']); + $this->assertContains('user:'.$this->getUser()['$id'], $file['body']['$permissions']['write']); + $this->assertIsInt($file['body']['dateCreated']); + $this->assertEquals('logo.png', $file['body']['name']); + $this->assertEquals('image/png', $file['body']['mimeType']); + $this->assertEquals(47218, $file['body']['sizeOriginal']); + } } \ No newline at end of file