1
0
Fork 0
mirror of synced 2024-07-03 05:31:38 +12:00
appwrite/tests/old/ProjectLocaleTest.php

194 lines
7.1 KiB
PHP
Raw Normal View History

2019-10-21 21:15:12 +13:00
<?php
namespace Tests\E2E;
use Tests\E2E\Client;
class ProjectLocaleTest extends BaseProjects
{
2019-11-04 08:05:26 +13:00
public function testRegisterSuccess(): array
2019-10-21 21:15:12 +13:00
{
return $this->initProject([]);
}
/**
* @depends testRegisterSuccess
*/
2019-11-04 08:05:26 +13:00
public function testLocaleReadSuccess(array $data): array
2019-10-21 21:15:12 +13:00
{
2020-01-13 00:11:16 +13:00
$response = $this->client->call(Client::METHOD_GET, '/locale', [
2019-10-21 21:15:12 +13:00
'content-type' => 'application/json',
2020-01-13 00:11:16 +13:00
'x-appwrite-project' => $this->getProject()['$uid'],
2019-10-21 21:15:12 +13:00
]);
2020-01-13 00:11:16 +13:00
$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']);
2019-11-04 08:05:26 +13:00
2019-10-21 21:15:12 +13:00
return $data;
}
/**
* @depends testRegisterSuccess
*/
2019-11-04 08:05:26 +13:00
public function testLocaleCountriesReadSuccess(array $data): array
2019-10-21 21:15:12 +13:00
{
2020-01-13 00:11:16 +13:00
$response = $this->client->call(Client::METHOD_GET, '/locale/countries', [
2019-10-21 21:15:12 +13:00
'content-type' => 'application/json',
2020-01-13 00:11:16 +13:00
'x-appwrite-project' => $this->getProject()['$uid'],
2019-10-21 21:15:12 +13:00
]);
2020-01-13 00:11:16 +13:00
$this->assertEquals($response['headers']['status-code'], 200);
$this->assertIsArray($response['body']);
$this->assertCount(194, $response['body']);
$this->assertEquals($response['body']['US'], 'United States');
2019-11-04 08:05:26 +13:00
2019-10-21 21:15:12 +13:00
// Test locale code change to ES
2020-01-13 00:11:16 +13:00
$response = $this->client->call(Client::METHOD_GET, '/locale/countries', [
2019-10-21 21:15:12 +13:00
'content-type' => 'application/json',
2020-01-13 00:11:16 +13:00
'x-appwrite-project' => $this->getProject()['$uid'],
2019-10-21 21:15:12 +13:00
'x-appwrite-locale' => 'es',
]);
2020-01-13 00:11:16 +13:00
$this->assertEquals($response['headers']['status-code'], 200);
$this->assertIsArray($response['body']);
$this->assertCount(194, $response['body']);
$this->assertEquals($response['body']['US'], 'Estados Unidos');
2019-10-21 21:15:12 +13:00
return $data;
}
/**
* @depends testRegisterSuccess
*/
2019-11-04 08:05:26 +13:00
public function testLocaleCountriesEUReadSuccess(array $data): array
2019-10-21 21:30:16 +13:00
{
2020-01-13 00:11:16 +13:00
$response = $this->client->call(Client::METHOD_GET, '/locale/countries/eu', [
2019-10-21 21:30:16 +13:00
'content-type' => 'application/json',
2020-01-13 00:11:16 +13:00
'x-appwrite-project' => $this->getProject()['$uid'],
2019-10-21 21:30:16 +13:00
]);
2020-01-13 00:11:16 +13:00
$this->assertEquals($response['headers']['status-code'], 200);
$this->assertIsArray($response['body']);
$this->assertCount(28, $response['body']);
$this->assertEquals($response['body']['DE'], 'Germany');
2019-11-04 08:05:26 +13:00
2019-10-21 21:30:16 +13:00
// Test locale code change to ES
2020-01-13 00:11:16 +13:00
$response = $this->client->call(Client::METHOD_GET, '/locale/countries/eu', [
2019-10-21 21:30:16 +13:00
'content-type' => 'application/json',
2020-01-13 00:11:16 +13:00
'x-appwrite-project' => $this->getProject()['$uid'],
2019-10-21 21:30:16 +13:00
'x-appwrite-locale' => 'es',
]);
2020-01-13 00:11:16 +13:00
$this->assertEquals($response['headers']['status-code'], 200);
$this->assertIsArray($response['body']);
$this->assertCount(28, $response['body']);
$this->assertEquals($response['body']['DE'], 'Alemania');
2019-10-21 21:30:16 +13:00
return $data;
}
/**
* @depends testRegisterSuccess
*/
2019-11-04 08:05:26 +13:00
public function testLocaleContinentsReadSuccess(array $data): array
2019-10-21 21:15:12 +13:00
{
2020-01-13 00:11:16 +13:00
$response = $this->client->call(Client::METHOD_GET, '/locale/continents', [
2019-10-21 21:15:12 +13:00
'content-type' => 'application/json',
2020-01-13 00:11:16 +13:00
'x-appwrite-project' => $this->getProject()['$uid'],
2019-10-21 21:15:12 +13:00
]);
2020-01-13 00:11:16 +13:00
$this->assertEquals($response['headers']['status-code'], 200);
$this->assertIsArray($response['body']);
$this->assertCount(7, $response['body']);
$this->assertEquals($response['body']['NA'], 'North America');
2019-11-04 08:05:26 +13:00
2019-10-21 21:15:12 +13:00
// Test locale code change to ES
2020-01-13 00:11:16 +13:00
$response = $this->client->call(Client::METHOD_GET, '/locale/continents', [
2019-10-21 21:15:12 +13:00
'content-type' => 'application/json',
2020-01-13 00:11:16 +13:00
'x-appwrite-project' => $this->getProject()['$uid'],
2019-10-21 21:15:12 +13:00
'x-appwrite-locale' => 'es',
]);
2020-01-13 00:11:16 +13:00
$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');
2019-10-21 21:15:12 +13:00
return $data;
}
2019-10-21 21:30:16 +13:00
/**
* @depends testRegisterSuccess
*/
2019-11-04 08:05:26 +13:00
public function testLocaleCurrenciesReadSuccess(array $data): array
2019-10-21 21:30:16 +13:00
{
2020-01-13 00:11:16 +13:00
$response = $this->client->call(Client::METHOD_GET, '/locale/currencies', [
2019-10-21 21:30:16 +13:00
'content-type' => 'application/json',
2020-01-13 00:11:16 +13:00
'x-appwrite-project' => $this->getProject()['$uid'],
2019-10-21 21:30:16 +13:00
]);
2020-01-13 00:11:16 +13:00
$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');
2019-11-04 08:05:26 +13:00
2019-10-21 21:30:16 +13:00
return $data;
}
2019-11-18 18:05:10 +13:00
/**
* @depends testRegisterSuccess
*/
public function testLocaleLangsSuccess(array $data): array
{
$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 $key => $lang) {
2020-01-13 00:11:16 +13:00
$response = $this->client->call(Client::METHOD_GET, '/locale/countries', [
2019-11-18 18:05:10 +13:00
'content-type' => 'application/json',
2020-01-13 00:11:16 +13:00
'x-appwrite-project' => $this->getProject()['$uid'],
2019-11-18 18:05:10 +13:00
'x-appwrite-locale' => $lang,
]);
2020-01-13 00:11:16 +13:00
foreach ($response['body'] as $i => $code) {
2019-11-18 18:05:10 +13:00
$this->assertArrayHasKey($i, $defaultCountries, $i . ' country should be removed from ' . $lang);
}
foreach (array_keys($defaultCountries) as $i => $code) {
2020-01-13 00:11:16 +13:00
$this->assertArrayHasKey($code, $response['body'], $code . ' country is missing from ' . $lang . ' (total: ' . count($response['body']) . ')');
2019-11-18 18:05:10 +13:00
}
2020-01-13 00:11:16 +13:00
$this->assertEquals($response['headers']['status-code'], 200);
$this->assertCount(194, $response['body']);
2019-11-18 18:05:10 +13:00
2020-01-13 00:11:16 +13:00
$response = $this->client->call(Client::METHOD_GET, '/locale/continents', [
2019-11-18 18:05:10 +13:00
'content-type' => 'application/json',
2020-01-13 00:11:16 +13:00
'x-appwrite-project' => $this->getProject()['$uid'],
2019-11-18 18:05:10 +13:00
'x-appwrite-locale' => $lang,
]);
2020-01-13 00:11:16 +13:00
foreach ($response['body'] as $i => $code) {
2019-11-18 18:05:10 +13:00
$this->assertArrayHasKey($i, $defaultContinents, $i . ' continent should be removed from ' . $lang);
}
foreach (array_keys($defaultContinents) as $i => $code) {
2020-01-13 00:11:16 +13:00
$this->assertArrayHasKey($code, $response['body'], $code . ' continent is missing from ' . $lang . ' (total: ' . count($response['body']) . ')');
2019-11-18 18:05:10 +13:00
}
2020-01-13 00:11:16 +13:00
$this->assertEquals($response['headers']['status-code'], 200);
$this->assertCount(7, $response['body']);
2019-11-18 18:05:10 +13:00
}
return $data;
}
2019-10-21 21:15:12 +13:00
}