From 327b82dffc555bcdb2b158c07880208cf7bddcf2 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Sun, 12 Jan 2020 13:11:16 +0200 Subject: [PATCH] Improved e2e tests --- tests/e2e/Services/Account/AccountBase.php | 2 +- .../Account/AccountCustomServerTest.php | 4 +- tests/e2e/Services/Avatars/AvatarsBase.php | 414 ++++++++++++++++++ .../Avatars/AvatarsConsoleClientTest.php | 14 + .../Avatars/AvatarsCustomClientTest.php | 14 + .../Avatars/AvatarsCustomServerTest.php | 30 ++ tests/e2e/Services/Locale/LocaleBase.php | 236 ++++++++++ .../Locale/LocaleConsoleClientTest.php | 14 + .../Locale/LocaleCustomClientTest.php | 14 + .../Locale/LocaleCustomServerTest.php | 30 ++ tests/old/ProjectAvatarsTest.php | 172 ++++---- tests/old/ProjectLocaleTest.php | 128 +++--- 12 files changed, 919 insertions(+), 153 deletions(-) create mode 100644 tests/e2e/Services/Avatars/AvatarsBase.php create mode 100644 tests/e2e/Services/Avatars/AvatarsConsoleClientTest.php create mode 100644 tests/e2e/Services/Avatars/AvatarsCustomClientTest.php create mode 100644 tests/e2e/Services/Avatars/AvatarsCustomServerTest.php create mode 100644 tests/e2e/Services/Locale/LocaleBase.php create mode 100644 tests/e2e/Services/Locale/LocaleConsoleClientTest.php create mode 100644 tests/e2e/Services/Locale/LocaleCustomClientTest.php create mode 100644 tests/e2e/Services/Locale/LocaleCustomServerTest.php diff --git a/tests/e2e/Services/Account/AccountBase.php b/tests/e2e/Services/Account/AccountBase.php index e60e41ad2..77d60c72b 100644 --- a/tests/e2e/Services/Account/AccountBase.php +++ b/tests/e2e/Services/Account/AccountBase.php @@ -279,7 +279,7 @@ trait AccountBase */ public function testGetAccountLogs($data):array { - sleep(5); + sleep(10); $session = (isset($data['session'])) ? $data['session'] : ''; /** diff --git a/tests/e2e/Services/Account/AccountCustomServerTest.php b/tests/e2e/Services/Account/AccountCustomServerTest.php index 8561cbc33..14949544f 100644 --- a/tests/e2e/Services/Account/AccountCustomServerTest.php +++ b/tests/e2e/Services/Account/AccountCustomServerTest.php @@ -19,12 +19,12 @@ class AccountCustomServerTest extends Scope $name = 'User Name'; /** - * Test for SUCCESS + * Test for FAILURE */ $response = $this->client->call(Client::METHOD_POST, '/account', [ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$uid'], - 'X-Appwrite-Key' => $this->getProject()['apiKey'], + 'x-appwrite-key' => $this->getProject()['apiKey'], ], [ 'email' => $email, 'password' => $password, diff --git a/tests/e2e/Services/Avatars/AvatarsBase.php b/tests/e2e/Services/Avatars/AvatarsBase.php new file mode 100644 index 000000000..fd3998344 --- /dev/null +++ b/tests/e2e/Services/Avatars/AvatarsBase.php @@ -0,0 +1,414 @@ +client->call(Client::METHOD_GET, '/avatars/credit-cards/visa', [ + 'x-appwrite-project' => $this->getProject()['$uid'], + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); + $this->assertNotEmpty($response['body']); + + $response = $this->client->call(Client::METHOD_GET, '/avatars/credit-cards/visa', [ + 'x-appwrite-project' => $this->getProject()['$uid'], + ], [ + 'width' => 200, + 'height' => 200, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); + $this->assertNotEmpty($response['body']); + + $response = $this->client->call(Client::METHOD_GET, '/avatars/credit-cards/visa', [ + 'x-appwrite-project' => $this->getProject()['$uid'], + ], [ + 'width' => 300, + 'height' => 300, + 'quality' => 30, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); + $this->assertNotEmpty($response['body']); + + /** + * Test for FAILURE + */ + + $response = $this->client->call(Client::METHOD_GET, '/avatars/credit-cards/unknown', [ + 'x-appwrite-project' => $this->getProject()['$uid'], + ], [ + 'width' => 300, + 'height' => 300, + 'quality' => 30, + ]); + + $this->assertEquals(400, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_GET, '/avatars/credit-cards/visa', [ + 'x-appwrite-project' => $this->getProject()['$uid'], + ], [ + 'width' => 2001, + 'height' => 300, + 'quality' => 30, + ]); + + $this->assertEquals(400, $response['headers']['status-code']); + + return []; + } + + public function testGetBrowser():array + { + /** + * Test for SUCCESS + */ + $response = $this->client->call(Client::METHOD_GET, '/avatars/browsers/ch', [ + 'x-appwrite-project' => $this->getProject()['$uid'], + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); + $this->assertNotEmpty($response['body']); + + $response = $this->client->call(Client::METHOD_GET, '/avatars/browsers/ch', [ + 'x-appwrite-project' => $this->getProject()['$uid'], + ], [ + 'width' => 200, + 'height' => 200, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); + $this->assertNotEmpty($response['body']); + + $response = $this->client->call(Client::METHOD_GET, '/avatars/browsers/ch', [ + 'x-appwrite-project' => $this->getProject()['$uid'], + ], [ + 'width' => 300, + 'height' => 300, + 'quality' => 30, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); + $this->assertNotEmpty($response['body']); + + /** + * Test for FAILURE + */ + + $response = $this->client->call(Client::METHOD_GET, '/avatars/browsers/unknown', [ + 'x-appwrite-project' => $this->getProject()['$uid'], + ], [ + 'width' => 300, + 'height' => 300, + 'quality' => 30, + ]); + + $this->assertEquals(400, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_GET, '/avatars/browsers/ch', [ + 'x-appwrite-project' => $this->getProject()['$uid'], + ], [ + 'width' => 2001, + 'height' => 300, + 'quality' => 30, + ]); + + $this->assertEquals(400, $response['headers']['status-code']); + + return []; + } + + public function testGetFlag():array + { + /** + * Test for SUCCESS + */ + $response = $this->client->call(Client::METHOD_GET, '/avatars/flags/us', [ + 'x-appwrite-project' => $this->getProject()['$uid'], + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); + $this->assertNotEmpty($response['body']); + + $response = $this->client->call(Client::METHOD_GET, '/avatars/flags/us', [ + 'x-appwrite-project' => $this->getProject()['$uid'], + ], [ + 'width' => 200, + 'height' => 200, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); + $this->assertNotEmpty($response['body']); + + $response = $this->client->call(Client::METHOD_GET, '/avatars/flags/us', [ + 'x-appwrite-project' => $this->getProject()['$uid'], + ], [ + 'width' => 300, + 'height' => 300, + 'quality' => 30, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); + $this->assertNotEmpty($response['body']); + + /** + * Test for FAILURE + */ + $response = $this->client->call(Client::METHOD_GET, '/avatars/flags/unknown', [ + 'x-appwrite-project' => $this->getProject()['$uid'], + ], [ + 'width' => 300, + 'height' => 300, + 'quality' => 30, + ]); + + $this->assertEquals(400, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_GET, '/avatars/flags/us', [ + 'x-appwrite-project' => $this->getProject()['$uid'], + ], [ + 'width' => 2001, + 'height' => 300, + 'quality' => 30, + ]); + + $this->assertEquals(400, $response['headers']['status-code']); + + return []; + } + + public function testGetImage():array + { + /** + * Test for SUCCESS + */ + $response = $this->client->call(Client::METHOD_GET, '/avatars/image', [ + 'x-appwrite-project' => $this->getProject()['$uid'], + ], [ + 'url' => 'https://appwrite.io/images/apple.png', + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); + $this->assertNotEmpty($response['body']); + + $response = $this->client->call(Client::METHOD_GET, '/avatars/image', [ + 'x-appwrite-project' => $this->getProject()['$uid'], + ], [ + 'url' => 'https://appwrite.io/images/apple.png', + 'width' => 200, + 'height' => 200, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); + $this->assertNotEmpty($response['body']); + + $response = $this->client->call(Client::METHOD_GET, '/avatars/image', [ + 'x-appwrite-project' => $this->getProject()['$uid'], + ], [ + 'url' => 'https://appwrite.io/images/apple.png', + 'width' => 300, + 'height' => 300, + 'quality' => 30, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); + $this->assertNotEmpty($response['body']); + + /** + * Test for FAILURE + */ + $response = $this->client->call(Client::METHOD_GET, '/avatars/image', [ + 'x-appwrite-project' => $this->getProject()['$uid'], + ], [ + 'url' => 'https://appwrite.io/images/unknown.png', + 'width' => 300, + 'height' => 300, + 'quality' => 30, + ]); + + $this->assertEquals(404, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_GET, '/avatars/image', [ + 'x-appwrite-project' => $this->getProject()['$uid'], + ], [ + 'url' => 'https://appwrite.io/images/apple.png', + 'width' => 2001, + 'height' => 300, + 'quality' => 30, + ]); + + $this->assertEquals(400, $response['headers']['status-code']); + + // TODO Add test for non-image file (PDF, WORD) + + return []; + } + + public function testGetFavicon():array + { + /** + * Test for SUCCESS + */ + $response = $this->client->call(Client::METHOD_GET, '/avatars/favicon', [ + 'x-appwrite-project' => $this->getProject()['$uid'], + ], [ + 'url' => 'https://appwrite.io/', + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); + $this->assertNotEmpty($response['body']); + + // $response = $this->client->call(Client::METHOD_GET, '/avatars/favicon', [ + // 'x-appwrite-project' => $this->getProject()['$uid'], + // ], [ + // 'url' => 'https://www.bbc.com/', + // ]); + + // $this->assertEquals(200, $response['headers']['status-code']); + // $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); + // $this->assertNotEmpty($response['body']); + + // $response = $this->client->call(Client::METHOD_GET, '/avatars/favicon', [ + // 'x-appwrite-project' => $this->getProject()['$uid'], + // ], [ + // 'url' => 'https://edition.cnn.com/', + // ]); + + // $this->assertEquals(200, $response['headers']['status-code']); + // $this->assertEquals('image/x-icon; charset=UTF-8', $response['headers']['content-type']); + // $this->assertNotEmpty($response['body']); + + /** + * Test for FAILURE + */ + $response = $this->client->call(Client::METHOD_GET, '/avatars/favicon', [ + 'x-appwrite-project' => $this->getProject()['$uid'], + ], [ + 'url' => 'unknown-address', + ]); + + $this->assertEquals(400, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_GET, '/avatars/favicon', [ + 'x-appwrite-project' => $this->getProject()['$uid'], + ], [ + 'url' => 'http://unknown-address.test', + ]); + + $this->assertEquals(404, $response['headers']['status-code']); + + return []; + } + + public function testGetQR():array + { + /** + * Test for SUCCESS + */ + $response = $this->client->call(Client::METHOD_GET, '/avatars/qr', [ + 'x-appwrite-project' => $this->getProject()['$uid'], + ], [ + 'text' => 'url:https://appwrite.io/', + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); + $this->assertNotEmpty($response['body']); + + $response = $this->client->call(Client::METHOD_GET, '/avatars/qr', [ + 'x-appwrite-project' => $this->getProject()['$uid'], + ], [ + 'text' => 'url:https://appwrite.io/', + 'size' => 200, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); + $this->assertNotEmpty($response['body']); + + $response = $this->client->call(Client::METHOD_GET, '/avatars/qr', [ + 'x-appwrite-project' => $this->getProject()['$uid'], + ], [ + 'text' => 'url:https://appwrite.io/', + 'size' => 200, + 'margin' => 10, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); + $this->assertNotEmpty($response['body']); + + $response = $this->client->call(Client::METHOD_GET, '/avatars/qr', [ + 'x-appwrite-project' => $this->getProject()['$uid'], + ], [ + 'text' => 'url:https://appwrite.io/', + 'size' => 200, + 'margin' => 10, + 'download' => 1, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('attachment; filename="qr.png"', $response['headers']['content-disposition']); + $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); + $this->assertNotEmpty($response['body']); + + /** + * Test for FAILURE + */ + $response = $this->client->call(Client::METHOD_GET, '/avatars/qr', [ + 'x-appwrite-project' => $this->getProject()['$uid'], + ], [ + 'text' => 'url:https://appwrite.io/', + 'size' => 1001, + 'margin' => 10, + 'download' => 1, + ]); + + $this->assertEquals(400, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_GET, '/avatars/qr', [ + 'x-appwrite-project' => $this->getProject()['$uid'], + ], [ + 'text' => 'url:https://appwrite.io/', + 'size' => 400, + 'margin' => 11, + 'download' => 1, + ]); + + $this->assertEquals(400, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_GET, '/avatars/qr', [ + 'x-appwrite-project' => $this->getProject()['$uid'], + ], [ + 'text' => 'url:https://appwrite.io/', + 'size' => 400, + 'margin' => 10, + 'download' => 2, + ]); + + $this->assertEquals(400, $response['headers']['status-code']); + + return []; + } +} \ No newline at end of file diff --git a/tests/e2e/Services/Avatars/AvatarsConsoleClientTest.php b/tests/e2e/Services/Avatars/AvatarsConsoleClientTest.php new file mode 100644 index 000000000..5a86e33f9 --- /dev/null +++ b/tests/e2e/Services/Avatars/AvatarsConsoleClientTest.php @@ -0,0 +1,14 @@ +client->call(Client::METHOD_GET, '/avatars/credit-cards/visa', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + 'X-appwrite-key' => $this->getProject()['apiKey'], + ]); + + $this->assertEquals(401, $response['headers']['status-code']); + + return []; + } +} \ No newline at end of file diff --git a/tests/e2e/Services/Locale/LocaleBase.php b/tests/e2e/Services/Locale/LocaleBase.php new file mode 100644 index 000000000..7362b17f3 --- /dev/null +++ b/tests/e2e/Services/Locale/LocaleBase.php @@ -0,0 +1,236 @@ +client->call(Client::METHOD_GET, '/locale', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + ]); + + $this->assertArrayHasKey('ip', $response['body']); + $this->assertArrayHasKey('countryCode', $response['body']); + $this->assertArrayHasKey('country', $response['body']); + $this->assertArrayHasKey('continent', $response['body']); + $this->assertArrayHasKey('continentCode', $response['body']); + $this->assertArrayHasKey('eu', $response['body']); + $this->assertArrayHasKey('currency', $response['body']); + + /** + * Test for FAILURE + */ + + return []; + } + + public function testGetCountries():array + { + /** + * Test for SUCCESS + */ + $response = $this->client->call(Client::METHOD_GET, '/locale/countries', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + ]); + + $this->assertEquals($response['headers']['status-code'], 200); + $this->assertIsArray($response['body']); + $this->assertCount(194, $response['body']); + $this->assertEquals($response['body']['US'], 'United States'); + + // Test locale code change to ES + + $response = $this->client->call(Client::METHOD_GET, '/locale/countries', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + 'x-appwrite-locale' => 'es', + ]); + + $this->assertEquals($response['headers']['status-code'], 200); + $this->assertIsArray($response['body']); + $this->assertCount(194, $response['body']); + $this->assertEquals($response['body']['US'], 'Estados Unidos'); + + /** + * Test for FAILURE + */ + + return []; + } + + public function testGetCountriesEU():array + { + /** + * Test for SUCCESS + */ + $response = $this->client->call(Client::METHOD_GET, '/locale/countries/eu', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + ]); + + $this->assertEquals($response['headers']['status-code'], 200); + $this->assertIsArray($response['body']); + $this->assertCount(28, $response['body']); + $this->assertEquals($response['body']['DE'], 'Germany'); + + // Test locale code change to ES + + $response = $this->client->call(Client::METHOD_GET, '/locale/countries/eu', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + 'x-appwrite-locale' => 'es', + ]); + + $this->assertEquals($response['headers']['status-code'], 200); + $this->assertIsArray($response['body']); + $this->assertCount(28, $response['body']); + $this->assertEquals($response['body']['DE'], 'Alemania'); + + /** + * Test for FAILURE + */ + + return []; + } + + public function testGetCountriesPhones():array + { + /** + * Test for SUCCESS + */ + $response = $this->client->call(Client::METHOD_GET, '/locale/countries/phones', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + ]); + + $this->assertEquals($response['headers']['status-code'], 200); + $this->assertIsArray($response['body']); + $this->assertCount(194, $response['body']); + $this->assertEquals($response['body']['US'], 'United States +1'); + $this->assertEquals($response['body']['IL'], 'Israel +972'); + + /** + * Test for FAILURE + */ + + return []; + } + + public function testGetContinents():array + { + /** + * Test for SUCCESS + */ + $response = $this->client->call(Client::METHOD_GET, '/locale/continents', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + ]); + + $this->assertEquals($response['headers']['status-code'], 200); + $this->assertIsArray($response['body']); + $this->assertCount(7, $response['body']); + $this->assertEquals($response['body']['NA'], 'North America'); + + // Test locale code change to ES + $response = $this->client->call(Client::METHOD_GET, '/locale/continents', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + 'x-appwrite-locale' => 'es', + ]); + + $this->assertEquals($response['headers']['status-code'], 200); + $this->assertIsArray($response['body']); + $this->assertCount(7, $response['body']); + $this->assertEquals($response['body']['NA'], 'América del Norte'); + + + /** + * Test for FAILURE + */ + + return []; + } + + public function testGetCurrencies():array + { + /** + * Test for SUCCESS + */ + $response = $this->client->call(Client::METHOD_GET, '/locale/currencies', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + ]); + + $this->assertEquals($response['headers']['status-code'], 200); + $this->assertIsArray($response['body']); + $this->assertCount(117, $response['body']); + $this->assertEquals($response['body'][0]['symbol'], '$'); + $this->assertEquals($response['body'][0]['name'], 'US Dollar'); + + /** + * Test for FAILURE + */ + + return []; + } + + public function testLangaugaes(): array + { + /** + * Test for SUCCESS + */ + $languages = require('app/config/locales.php'); + $defaultCountries = require('app/config/locales/en.countries.php'); + $defaultContinents = require('app/config/locales/en.continents.php'); + + foreach ($languages as $lang) { + $response = $this->client->call(Client::METHOD_GET, '/locale/countries', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + 'x-appwrite-locale' => $lang, + ]); + + foreach ($response['body'] as $i => $code) { + $this->assertArrayHasKey($i, $defaultCountries, $i . ' country should be removed from ' . $lang); + } + + foreach (array_keys($defaultCountries) as $i => $code) { + $this->assertArrayHasKey($code, $response['body'], $code . ' country is missing from ' . $lang . ' (total: ' . count($response['body']) . ')'); + } + + $this->assertEquals($response['headers']['status-code'], 200); + $this->assertCount(194, $response['body']); + + $response = $this->client->call(Client::METHOD_GET, '/locale/continents', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + 'x-appwrite-locale' => $lang, + ]); + + foreach ($response['body'] as $i => $code) { + $this->assertArrayHasKey($i, $defaultContinents, $i . ' continent should be removed from ' . $lang); + } + + foreach (array_keys($defaultContinents) as $i => $code) { + $this->assertArrayHasKey($code, $response['body'], $code . ' continent is missing from ' . $lang . ' (total: ' . count($response['body']) . ')'); + } + + $this->assertEquals($response['headers']['status-code'], 200); + $this->assertCount(7, $response['body']); + } + + /** + * Test for FAILURE + */ + + return []; + } +} \ No newline at end of file diff --git a/tests/e2e/Services/Locale/LocaleConsoleClientTest.php b/tests/e2e/Services/Locale/LocaleConsoleClientTest.php new file mode 100644 index 000000000..e43f0f50a --- /dev/null +++ b/tests/e2e/Services/Locale/LocaleConsoleClientTest.php @@ -0,0 +1,14 @@ +client->call(Client::METHOD_GET, '/avatars/credit-cards/visa', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + 'X-appwrite-key' => $this->getProject()['apiKey'], + ]); + + $this->assertEquals(401, $response['headers']['status-code']); + + return []; + } +} \ No newline at end of file diff --git a/tests/old/ProjectAvatarsTest.php b/tests/old/ProjectAvatarsTest.php index 7fa39ea74..791a02bdb 100644 --- a/tests/old/ProjectAvatarsTest.php +++ b/tests/old/ProjectAvatarsTest.php @@ -16,36 +16,36 @@ class ProjectAvatarsTest extends BaseProjects */ public function testAvatarsCCReadSuccess(array $data): array { - $logo = $this->client->call(Client::METHOD_GET, '/avatars/credit-cards/visa', [ - 'x-appwrite-project' => $data['projectUid'], + $response = $this->client->call(Client::METHOD_GET, '/avatars/credit-cards/visa', [ + 'x-appwrite-project' => $this->getProject()['$uid'], ]); - $this->assertEquals(200, $logo['headers']['status-code']); - $this->assertEquals('image/png; charset=UTF-8', $logo['headers']['content-type']); - $this->assertNotEmpty($logo['body']); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); + $this->assertNotEmpty($response['body']); - $logo = $this->client->call(Client::METHOD_GET, '/avatars/credit-cards/visa', [ - 'x-appwrite-project' => $data['projectUid'], + $response = $this->client->call(Client::METHOD_GET, '/avatars/credit-cards/visa', [ + 'x-appwrite-project' => $this->getProject()['$uid'], ], [ 'width' => 200, 'height' => 200, ]); - $this->assertEquals(200, $logo['headers']['status-code']); - $this->assertEquals('image/png; charset=UTF-8', $logo['headers']['content-type']); - $this->assertNotEmpty($logo['body']); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); + $this->assertNotEmpty($response['body']); - $logo = $this->client->call(Client::METHOD_GET, '/avatars/credit-cards/visa', [ - 'x-appwrite-project' => $data['projectUid'], + $response = $this->client->call(Client::METHOD_GET, '/avatars/credit-cards/visa', [ + 'x-appwrite-project' => $this->getProject()['$uid'], ], [ 'width' => 300, 'height' => 300, 'quality' => 30, ]); - $this->assertEquals(200, $logo['headers']['status-code']); - $this->assertEquals('image/png; charset=UTF-8', $logo['headers']['content-type']); - $this->assertNotEmpty($logo['body']); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); + $this->assertNotEmpty($response['body']); return $data; } @@ -55,36 +55,36 @@ class ProjectAvatarsTest extends BaseProjects */ public function testAvatarsBrowserReadSuccess(array $data): array { - $logo = $this->client->call(Client::METHOD_GET, '/avatars/browsers/ch', [ - 'x-appwrite-project' => $data['projectUid'], + $response = $this->client->call(Client::METHOD_GET, '/avatars/browsers/ch', [ + 'x-appwrite-project' => $this->getProject()['$uid'], ]); - $this->assertEquals(200, $logo['headers']['status-code']); - $this->assertEquals('image/png; charset=UTF-8', $logo['headers']['content-type']); - $this->assertNotEmpty($logo['body']); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); + $this->assertNotEmpty($response['body']); - $logo = $this->client->call(Client::METHOD_GET, '/avatars/browsers/ch', [ - 'x-appwrite-project' => $data['projectUid'], + $response = $this->client->call(Client::METHOD_GET, '/avatars/browsers/ch', [ + 'x-appwrite-project' => $this->getProject()['$uid'], ], [ 'width' => 200, 'height' => 200, ]); - $this->assertEquals(200, $logo['headers']['status-code']); - $this->assertEquals('image/png; charset=UTF-8', $logo['headers']['content-type']); - $this->assertNotEmpty($logo['body']); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); + $this->assertNotEmpty($response['body']); - $logo = $this->client->call(Client::METHOD_GET, '/avatars/browsers/ch', [ - 'x-appwrite-project' => $data['projectUid'], + $response = $this->client->call(Client::METHOD_GET, '/avatars/browsers/ch', [ + 'x-appwrite-project' => $this->getProject()['$uid'], ], [ 'width' => 300, 'height' => 300, 'quality' => 30, ]); - $this->assertEquals(200, $logo['headers']['status-code']); - $this->assertEquals('image/png; charset=UTF-8', $logo['headers']['content-type']); - $this->assertNotEmpty($logo['body']); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); + $this->assertNotEmpty($response['body']); return $data; } @@ -94,36 +94,36 @@ class ProjectAvatarsTest extends BaseProjects */ public function testAvatarsFlagReadSuccess(array $data): array { - $logo = $this->client->call(Client::METHOD_GET, '/avatars/flags/us', [ - 'x-appwrite-project' => $data['projectUid'], + $response = $this->client->call(Client::METHOD_GET, '/avatars/flags/us', [ + 'x-appwrite-project' => $this->getProject()['$uid'], ]); - $this->assertEquals(200, $logo['headers']['status-code']); - $this->assertEquals('image/png; charset=UTF-8', $logo['headers']['content-type']); - $this->assertNotEmpty($logo['body']); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); + $this->assertNotEmpty($response['body']); - $logo = $this->client->call(Client::METHOD_GET, '/avatars/flags/us', [ - 'x-appwrite-project' => $data['projectUid'], + $response = $this->client->call(Client::METHOD_GET, '/avatars/flags/us', [ + 'x-appwrite-project' => $this->getProject()['$uid'], ], [ 'width' => 200, 'height' => 200, ]); - $this->assertEquals(200, $logo['headers']['status-code']); - $this->assertEquals('image/png; charset=UTF-8', $logo['headers']['content-type']); - $this->assertNotEmpty($logo['body']); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); + $this->assertNotEmpty($response['body']); - $logo = $this->client->call(Client::METHOD_GET, '/avatars/flags/us', [ - 'x-appwrite-project' => $data['projectUid'], + $response = $this->client->call(Client::METHOD_GET, '/avatars/flags/us', [ + 'x-appwrite-project' => $this->getProject()['$uid'], ], [ 'width' => 300, 'height' => 300, 'quality' => 30, ]); - $this->assertEquals(200, $logo['headers']['status-code']); - $this->assertEquals('image/png; charset=UTF-8', $logo['headers']['content-type']); - $this->assertNotEmpty($logo['body']); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); + $this->assertNotEmpty($response['body']); return $data; } @@ -133,30 +133,30 @@ class ProjectAvatarsTest extends BaseProjects */ public function testAvatarsRemoteImageReadSuccess(array $data): array { - $logo = $this->client->call(Client::METHOD_GET, '/avatars/image', [ - 'x-appwrite-project' => $data['projectUid'], + $response = $this->client->call(Client::METHOD_GET, '/avatars/image', [ + 'x-appwrite-project' => $this->getProject()['$uid'], ], [ 'url' => 'https://appwrite.io/images/apple.png', ]); - $this->assertEquals(200, $logo['headers']['status-code']); - $this->assertEquals('image/png; charset=UTF-8', $logo['headers']['content-type']); - $this->assertNotEmpty($logo['body']); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); + $this->assertNotEmpty($response['body']); - $logo = $this->client->call(Client::METHOD_GET, '/avatars/image', [ - 'x-appwrite-project' => $data['projectUid'], + $response = $this->client->call(Client::METHOD_GET, '/avatars/image', [ + 'x-appwrite-project' => $this->getProject()['$uid'], ], [ 'url' => 'https://appwrite.io/images/apple.png', 'width' => 200, 'height' => 200, ]); - $this->assertEquals(200, $logo['headers']['status-code']); - $this->assertEquals('image/png; charset=UTF-8', $logo['headers']['content-type']); - $this->assertNotEmpty($logo['body']); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); + $this->assertNotEmpty($response['body']); - $logo = $this->client->call(Client::METHOD_GET, '/avatars/image', [ - 'x-appwrite-project' => $data['projectUid'], + $response = $this->client->call(Client::METHOD_GET, '/avatars/image', [ + 'x-appwrite-project' => $this->getProject()['$uid'], ], [ 'url' => 'https://appwrite.io/images/apple.png', 'width' => 300, @@ -164,9 +164,9 @@ class ProjectAvatarsTest extends BaseProjects 'quality' => 30, ]); - $this->assertEquals(200, $logo['headers']['status-code']); - $this->assertEquals('image/png; charset=UTF-8', $logo['headers']['content-type']); - $this->assertNotEmpty($logo['body']); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); + $this->assertNotEmpty($response['body']); return $data; } @@ -176,15 +176,15 @@ class ProjectAvatarsTest extends BaseProjects */ public function testAvatarsFaviconReadSuccess(array $data): array { - $logo = $this->client->call(Client::METHOD_GET, '/avatars/favicon', [ - 'x-appwrite-project' => $data['projectUid'], + $response = $this->client->call(Client::METHOD_GET, '/avatars/favicon', [ + 'x-appwrite-project' => $this->getProject()['$uid'], ], [ 'url' => 'https://appwrite.io/', ]); - $this->assertEquals(200, $logo['headers']['status-code']); - $this->assertEquals('image/png; charset=UTF-8', $logo['headers']['content-type']); - $this->assertNotEmpty($logo['body']); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); + $this->assertNotEmpty($response['body']); return $data; } @@ -194,41 +194,41 @@ class ProjectAvatarsTest extends BaseProjects */ public function testAvatarsQRReadSuccess(array $data): array { - $logo = $this->client->call(Client::METHOD_GET, '/avatars/qr', [ - 'x-appwrite-project' => $data['projectUid'], + $response = $this->client->call(Client::METHOD_GET, '/avatars/qr', [ + 'x-appwrite-project' => $this->getProject()['$uid'], ], [ 'text' => 'url:https://appwrite.io/', ]); - $this->assertEquals(200, $logo['headers']['status-code']); - $this->assertEquals('image/png; charset=UTF-8', $logo['headers']['content-type']); - $this->assertNotEmpty($logo['body']); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); + $this->assertNotEmpty($response['body']); - $logo = $this->client->call(Client::METHOD_GET, '/avatars/qr', [ - 'x-appwrite-project' => $data['projectUid'], + $response = $this->client->call(Client::METHOD_GET, '/avatars/qr', [ + 'x-appwrite-project' => $this->getProject()['$uid'], ], [ 'text' => 'url:https://appwrite.io/', 'size' => 200, ]); - $this->assertEquals(200, $logo['headers']['status-code']); - $this->assertEquals('image/png; charset=UTF-8', $logo['headers']['content-type']); - $this->assertNotEmpty($logo['body']); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); + $this->assertNotEmpty($response['body']); - $logo = $this->client->call(Client::METHOD_GET, '/avatars/qr', [ - 'x-appwrite-project' => $data['projectUid'], + $response = $this->client->call(Client::METHOD_GET, '/avatars/qr', [ + 'x-appwrite-project' => $this->getProject()['$uid'], ], [ 'text' => 'url:https://appwrite.io/', 'size' => 200, 'margin' => 10, ]); - $this->assertEquals(200, $logo['headers']['status-code']); - $this->assertEquals('image/png; charset=UTF-8', $logo['headers']['content-type']); - $this->assertNotEmpty($logo['body']); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); + $this->assertNotEmpty($response['body']); - $logo = $this->client->call(Client::METHOD_GET, '/avatars/qr', [ - 'x-appwrite-project' => $data['projectUid'], + $response = $this->client->call(Client::METHOD_GET, '/avatars/qr', [ + 'x-appwrite-project' => $this->getProject()['$uid'], ], [ 'text' => 'url:https://appwrite.io/', 'size' => 200, @@ -236,10 +236,10 @@ class ProjectAvatarsTest extends BaseProjects 'download' => 1, ]); - $this->assertEquals(200, $logo['headers']['status-code']); - $this->assertEquals('attachment; filename="qr.png"', $logo['headers']['content-disposition']); - $this->assertEquals('image/png; charset=UTF-8', $logo['headers']['content-type']); - $this->assertNotEmpty($logo['body']); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('attachment; filename="qr.png"', $response['headers']['content-disposition']); + $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); + $this->assertNotEmpty($response['body']); return $data; } diff --git a/tests/old/ProjectLocaleTest.php b/tests/old/ProjectLocaleTest.php index 97dd215d9..7bcc15663 100644 --- a/tests/old/ProjectLocaleTest.php +++ b/tests/old/ProjectLocaleTest.php @@ -16,18 +16,18 @@ class ProjectLocaleTest extends BaseProjects */ public function testLocaleReadSuccess(array $data): array { - $locale = $this->client->call(Client::METHOD_GET, '/locale', [ + $response = $this->client->call(Client::METHOD_GET, '/locale', [ 'content-type' => 'application/json', - 'x-appwrite-project' => $data['projectUid'], + 'x-appwrite-project' => $this->getProject()['$uid'], ]); - $this->assertArrayHasKey('ip', $locale['body']); - $this->assertArrayHasKey('countryCode', $locale['body']); - $this->assertArrayHasKey('country', $locale['body']); - $this->assertArrayHasKey('continent', $locale['body']); - $this->assertArrayHasKey('continentCode', $locale['body']); - $this->assertArrayHasKey('eu', $locale['body']); - $this->assertArrayHasKey('currency', $locale['body']); + $this->assertArrayHasKey('ip', $response['body']); + $this->assertArrayHasKey('countryCode', $response['body']); + $this->assertArrayHasKey('country', $response['body']); + $this->assertArrayHasKey('continent', $response['body']); + $this->assertArrayHasKey('continentCode', $response['body']); + $this->assertArrayHasKey('eu', $response['body']); + $this->assertArrayHasKey('currency', $response['body']); return $data; } @@ -37,28 +37,28 @@ class ProjectLocaleTest extends BaseProjects */ public function testLocaleCountriesReadSuccess(array $data): array { - $countries = $this->client->call(Client::METHOD_GET, '/locale/countries', [ + $response = $this->client->call(Client::METHOD_GET, '/locale/countries', [ 'content-type' => 'application/json', - 'x-appwrite-project' => $data['projectUid'], + 'x-appwrite-project' => $this->getProject()['$uid'], ]); - $this->assertEquals($countries['headers']['status-code'], 200); - $this->assertIsArray($countries['body']); - $this->assertCount(194, $countries['body']); - $this->assertEquals($countries['body']['US'], 'United States'); + $this->assertEquals($response['headers']['status-code'], 200); + $this->assertIsArray($response['body']); + $this->assertCount(194, $response['body']); + $this->assertEquals($response['body']['US'], 'United States'); // Test locale code change to ES - $countries = $this->client->call(Client::METHOD_GET, '/locale/countries', [ + $response = $this->client->call(Client::METHOD_GET, '/locale/countries', [ 'content-type' => 'application/json', - 'x-appwrite-project' => $data['projectUid'], + 'x-appwrite-project' => $this->getProject()['$uid'], 'x-appwrite-locale' => 'es', ]); - $this->assertEquals($countries['headers']['status-code'], 200); - $this->assertIsArray($countries['body']); - $this->assertCount(194, $countries['body']); - $this->assertEquals($countries['body']['US'], 'Estados Unidos'); + $this->assertEquals($response['headers']['status-code'], 200); + $this->assertIsArray($response['body']); + $this->assertCount(194, $response['body']); + $this->assertEquals($response['body']['US'], 'Estados Unidos'); return $data; } @@ -68,28 +68,28 @@ class ProjectLocaleTest extends BaseProjects */ public function testLocaleCountriesEUReadSuccess(array $data): array { - $countries = $this->client->call(Client::METHOD_GET, '/locale/countries/eu', [ + $response = $this->client->call(Client::METHOD_GET, '/locale/countries/eu', [ 'content-type' => 'application/json', - 'x-appwrite-project' => $data['projectUid'], + 'x-appwrite-project' => $this->getProject()['$uid'], ]); - $this->assertEquals($countries['headers']['status-code'], 200); - $this->assertIsArray($countries['body']); - $this->assertCount(28, $countries['body']); - $this->assertEquals($countries['body']['DE'], 'Germany'); + $this->assertEquals($response['headers']['status-code'], 200); + $this->assertIsArray($response['body']); + $this->assertCount(28, $response['body']); + $this->assertEquals($response['body']['DE'], 'Germany'); // Test locale code change to ES - $countries = $this->client->call(Client::METHOD_GET, '/locale/countries/eu', [ + $response = $this->client->call(Client::METHOD_GET, '/locale/countries/eu', [ 'content-type' => 'application/json', - 'x-appwrite-project' => $data['projectUid'], + 'x-appwrite-project' => $this->getProject()['$uid'], 'x-appwrite-locale' => 'es', ]); - $this->assertEquals($countries['headers']['status-code'], 200); - $this->assertIsArray($countries['body']); - $this->assertCount(28, $countries['body']); - $this->assertEquals($countries['body']['DE'], 'Alemania'); + $this->assertEquals($response['headers']['status-code'], 200); + $this->assertIsArray($response['body']); + $this->assertCount(28, $response['body']); + $this->assertEquals($response['body']['DE'], 'Alemania'); return $data; } @@ -99,27 +99,27 @@ class ProjectLocaleTest extends BaseProjects */ public function testLocaleContinentsReadSuccess(array $data): array { - $continents = $this->client->call(Client::METHOD_GET, '/locale/continents', [ + $response = $this->client->call(Client::METHOD_GET, '/locale/continents', [ 'content-type' => 'application/json', - 'x-appwrite-project' => $data['projectUid'], + 'x-appwrite-project' => $this->getProject()['$uid'], ]); - $this->assertEquals($continents['headers']['status-code'], 200); - $this->assertIsArray($continents['body']); - $this->assertCount(7, $continents['body']); - $this->assertEquals($continents['body']['NA'], 'North America'); + $this->assertEquals($response['headers']['status-code'], 200); + $this->assertIsArray($response['body']); + $this->assertCount(7, $response['body']); + $this->assertEquals($response['body']['NA'], 'North America'); // Test locale code change to ES - $continents = $this->client->call(Client::METHOD_GET, '/locale/continents', [ + $response = $this->client->call(Client::METHOD_GET, '/locale/continents', [ 'content-type' => 'application/json', - 'x-appwrite-project' => $data['projectUid'], + 'x-appwrite-project' => $this->getProject()['$uid'], 'x-appwrite-locale' => 'es', ]); - $this->assertEquals($continents['headers']['status-code'], 200); - $this->assertIsArray($continents['body']); - $this->assertCount(7, $continents['body']); - $this->assertEquals($continents['body']['NA'], 'América del Norte'); + $this->assertEquals($response['headers']['status-code'], 200); + $this->assertIsArray($response['body']); + $this->assertCount(7, $response['body']); + $this->assertEquals($response['body']['NA'], 'América del Norte'); return $data; } @@ -129,16 +129,16 @@ class ProjectLocaleTest extends BaseProjects */ public function testLocaleCurrenciesReadSuccess(array $data): array { - $continents = $this->client->call(Client::METHOD_GET, '/locale/currencies', [ + $response = $this->client->call(Client::METHOD_GET, '/locale/currencies', [ 'content-type' => 'application/json', - 'x-appwrite-project' => $data['projectUid'], + 'x-appwrite-project' => $this->getProject()['$uid'], ]); - $this->assertEquals($continents['headers']['status-code'], 200); - $this->assertIsArray($continents['body']); - $this->assertCount(117, $continents['body']); - $this->assertEquals($continents['body'][0]['symbol'], '$'); - $this->assertEquals($continents['body'][0]['name'], 'US Dollar'); + $this->assertEquals($response['headers']['status-code'], 200); + $this->assertIsArray($response['body']); + $this->assertCount(117, $response['body']); + $this->assertEquals($response['body'][0]['symbol'], '$'); + $this->assertEquals($response['body'][0]['name'], 'US Dollar'); return $data; } @@ -153,39 +153,39 @@ class ProjectLocaleTest extends BaseProjects $defaultContinents = require('app/config/locales/en.continents.php'); foreach ($languages as $key => $lang) { - $countries = $this->client->call(Client::METHOD_GET, '/locale/countries', [ + $response = $this->client->call(Client::METHOD_GET, '/locale/countries', [ 'content-type' => 'application/json', - 'x-appwrite-project' => $data['projectUid'], + 'x-appwrite-project' => $this->getProject()['$uid'], 'x-appwrite-locale' => $lang, ]); - foreach ($countries['body'] as $i => $code) { + foreach ($response['body'] as $i => $code) { $this->assertArrayHasKey($i, $defaultCountries, $i . ' country should be removed from ' . $lang); } foreach (array_keys($defaultCountries) as $i => $code) { - $this->assertArrayHasKey($code, $countries['body'], $code . ' country is missing from ' . $lang . ' (total: ' . count($countries['body']) . ')'); + $this->assertArrayHasKey($code, $response['body'], $code . ' country is missing from ' . $lang . ' (total: ' . count($response['body']) . ')'); } - $this->assertEquals($countries['headers']['status-code'], 200); - $this->assertCount(194, $countries['body']); + $this->assertEquals($response['headers']['status-code'], 200); + $this->assertCount(194, $response['body']); - $continents = $this->client->call(Client::METHOD_GET, '/locale/continents', [ + $response = $this->client->call(Client::METHOD_GET, '/locale/continents', [ 'content-type' => 'application/json', - 'x-appwrite-project' => $data['projectUid'], + 'x-appwrite-project' => $this->getProject()['$uid'], 'x-appwrite-locale' => $lang, ]); - foreach ($continents['body'] as $i => $code) { + foreach ($response['body'] as $i => $code) { $this->assertArrayHasKey($i, $defaultContinents, $i . ' continent should be removed from ' . $lang); } foreach (array_keys($defaultContinents) as $i => $code) { - $this->assertArrayHasKey($code, $continents['body'], $code . ' continent is missing from ' . $lang . ' (total: ' . count($continents['body']) . ')'); + $this->assertArrayHasKey($code, $response['body'], $code . ' continent is missing from ' . $lang . ' (total: ' . count($response['body']) . ')'); } - $this->assertEquals($continents['headers']['status-code'], 200); - $this->assertCount(7, $continents['body']); + $this->assertEquals($response['headers']['status-code'], 200); + $this->assertCount(7, $response['body']); } return $data;