1
0
Fork 0
mirror of synced 2024-06-03 11:24:48 +12:00
appwrite/tests/e2e/Services/Locale/LocaleBase.php

280 lines
10 KiB
PHP
Raw Normal View History

2020-01-13 00:11:16 +13:00
<?php
namespace Tests\E2E\Services\Locale;
2020-10-31 08:53:27 +13:00
use Exception;
2020-01-13 00:11:16 +13:00
use Tests\E2E\Client;
trait LocaleBase
{
public function testGetLocale():array
{
/**
* Test for SUCCESS
*/
2020-01-13 00:47:08 +13:00
$response = $this->client->call(Client::METHOD_GET, '/locale', array_merge([
2020-01-13 00:11:16 +13:00
'content-type' => 'application/json',
2020-02-17 20:16:11 +13:00
'x-appwrite-project' => $this->getProject()['$id'],
2020-01-13 00:47:08 +13:00
], $this->getHeaders()));
2020-01-13 00:11:16 +13:00
2020-01-13 00:47:08 +13:00
$this->assertEquals($response['headers']['status-code'], 200);
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']);
/**
* Test for FAILURE
*/
2020-01-13 00:47:08 +13:00
2020-01-13 00:11:16 +13:00
return [];
}
public function testGetCountries():array
{
/**
* Test for SUCCESS
*/
2020-01-13 00:47:08 +13:00
$response = $this->client->call(Client::METHOD_GET, '/locale/countries', array_merge([
2020-01-13 00:11:16 +13:00
'content-type' => 'application/json',
2020-02-17 20:16:11 +13:00
'x-appwrite-project' => $this->getProject()['$id'],
2020-01-13 00:47:08 +13:00
], $this->getHeaders()));
2020-01-13 00:11:16 +13:00
$this->assertEquals($response['headers']['status-code'], 200);
$this->assertIsArray($response['body']);
2020-10-31 08:53:27 +13:00
$this->assertEquals(194, $response['body']['sum']);
$this->assertEquals($response['body']['countries'][0]['name'], 'Afghanistan');
$this->assertEquals($response['body']['countries'][0]['code'], 'AF');
2020-01-13 00:11:16 +13:00
// Test locale code change to ES
$response = $this->client->call(Client::METHOD_GET, '/locale/countries', [
'content-type' => 'application/json',
2020-02-17 20:16:11 +13:00
'x-appwrite-project' => $this->getProject()['$id'],
2020-01-13 00:11:16 +13:00
'x-appwrite-locale' => 'es',
]);
$this->assertEquals($response['headers']['status-code'], 200);
$this->assertIsArray($response['body']);
2020-10-31 08:53:27 +13:00
$this->assertEquals(194, $response['body']['sum']);
$this->assertEquals($response['body']['countries'][0]['name'], 'Afganistán');
$this->assertEquals($response['body']['countries'][0]['code'], 'AF');
2020-01-13 00:11:16 +13:00
/**
* Test for FAILURE
*/
return [];
}
public function testGetCountriesEU():array
{
/**
* Test for SUCCESS
*/
2020-01-13 00:47:08 +13:00
$response = $this->client->call(Client::METHOD_GET, '/locale/countries/eu', array_merge([
2020-01-13 00:11:16 +13:00
'content-type' => 'application/json',
2020-02-17 20:16:11 +13:00
'x-appwrite-project' => $this->getProject()['$id'],
2020-01-13 00:47:08 +13:00
], $this->getHeaders()));
2020-01-13 00:11:16 +13:00
$this->assertEquals($response['headers']['status-code'], 200);
2020-10-31 08:53:27 +13:00
$this->assertEquals(27, $response['body']['sum']);
$this->assertIsArray($response['body']['countries']);
$this->assertEquals($response['body']['countries'][0]['name'], 'Austria');
$this->assertEquals($response['body']['countries'][0]['code'], 'AT');
2020-01-13 00:11:16 +13:00
// Test locale code change to ES
$response = $this->client->call(Client::METHOD_GET, '/locale/countries/eu', [
'content-type' => 'application/json',
2020-02-17 20:16:11 +13:00
'x-appwrite-project' => $this->getProject()['$id'],
2020-01-13 00:11:16 +13:00
'x-appwrite-locale' => 'es',
]);
$this->assertEquals($response['headers']['status-code'], 200);
2020-10-31 08:53:27 +13:00
$this->assertEquals(27, $response['body']['sum']);
$this->assertIsArray($response['body']['countries']);
2021-07-26 19:05:08 +12:00
$this->assertEquals($response['body']['countries'][0]['name'], 'Alemania');
$this->assertEquals($response['body']['countries'][0]['code'], 'DE');
2020-10-31 08:53:27 +13:00
2020-01-13 00:11:16 +13:00
/**
* Test for FAILURE
*/
return [];
}
public function testGetCountriesPhones():array
{
/**
* Test for SUCCESS
*/
2020-01-13 00:47:08 +13:00
$response = $this->client->call(Client::METHOD_GET, '/locale/countries/phones', array_merge([
2020-01-13 00:11:16 +13:00
'content-type' => 'application/json',
2020-02-17 20:16:11 +13:00
'x-appwrite-project' => $this->getProject()['$id'],
2020-01-13 00:47:08 +13:00
], $this->getHeaders()));
2020-01-13 00:11:16 +13:00
$this->assertEquals($response['headers']['status-code'], 200);
$this->assertIsArray($response['body']);
2020-10-31 08:53:27 +13:00
$this->assertEquals(194, $response['body']['sum']);
$this->assertIsArray($response['body']['phones']);
$this->assertEquals($response['body']['phones'][0]['code'], '+1');
2020-11-21 21:02:25 +13:00
$this->assertEquals($response['body']['phones'][0]['countryName'], 'Canada');
$this->assertEquals($response['body']['phones'][0]['countryCode'], 'CA');
2020-01-13 00:11:16 +13:00
/**
* Test for FAILURE
*/
return [];
}
public function testGetContinents():array
{
/**
* Test for SUCCESS
*/
2020-01-13 00:47:08 +13:00
$response = $this->client->call(Client::METHOD_GET, '/locale/continents', array_merge([
2020-01-13 00:11:16 +13:00
'content-type' => 'application/json',
2020-02-17 20:16:11 +13:00
'x-appwrite-project' => $this->getProject()['$id'],
2020-01-13 00:47:08 +13:00
], $this->getHeaders()));
2020-01-13 00:11:16 +13:00
$this->assertEquals($response['headers']['status-code'], 200);
2020-10-31 08:53:27 +13:00
$this->assertEquals(7, $response['body']['sum']);
$this->assertIsArray($response['body']['continents']);
$this->assertEquals($response['body']['continents'][0]['code'], 'AF');
$this->assertEquals($response['body']['continents'][0]['name'], 'Africa');
2020-01-13 00:11:16 +13:00
// Test locale code change to ES
$response = $this->client->call(Client::METHOD_GET, '/locale/continents', [
'content-type' => 'application/json',
2020-02-17 20:16:11 +13:00
'x-appwrite-project' => $this->getProject()['$id'],
2020-01-13 00:11:16 +13:00
'x-appwrite-locale' => 'es',
]);
$this->assertEquals($response['headers']['status-code'], 200);
2020-10-31 08:53:27 +13:00
$this->assertEquals(7, $response['body']['sum']);
$this->assertIsArray($response['body']['continents']);
2021-07-26 19:05:08 +12:00
$this->assertEquals($response['body']['continents'][0]['code'], 'NA');
$this->assertEquals($response['body']['continents'][0]['name'], 'América del Norte');
2020-01-13 00:11:16 +13:00
/**
* Test for FAILURE
*/
return [];
}
public function testGetCurrencies():array
{
/**
* Test for SUCCESS
*/
2020-01-13 00:47:08 +13:00
$response = $this->client->call(Client::METHOD_GET, '/locale/currencies', array_merge([
2020-01-13 00:11:16 +13:00
'content-type' => 'application/json',
2020-02-17 20:16:11 +13:00
'x-appwrite-project' => $this->getProject()['$id'],
2020-01-13 00:47:08 +13:00
], $this->getHeaders()));
2020-01-13 00:11:16 +13:00
$this->assertEquals($response['headers']['status-code'], 200);
$this->assertIsArray($response['body']);
2020-10-31 08:53:27 +13:00
$this->assertEquals(117, $response['body']['sum']);
$this->assertEquals($response['body']['currencies'][0]['symbol'], '$');
$this->assertEquals($response['body']['currencies'][0]['name'], 'US Dollar');
2020-01-13 00:11:16 +13:00
/**
* Test for FAILURE
*/
return [];
}
2020-05-25 01:07:05 +12:00
public function testGetLanguages():array
{
/**
* Test for SUCCESS
*/
2020-05-25 01:16:56 +12:00
$response = $this->client->call(Client::METHOD_GET, '/locale/languages', array_merge([
2020-05-25 01:07:05 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
$this->assertEquals($response['headers']['status-code'], 200);
$this->assertIsArray($response['body']);
2021-12-02 04:09:57 +13:00
$this->assertEquals(184, $response['body']['sum']);
2020-05-25 01:07:05 +12:00
2020-10-31 08:53:27 +13:00
$this->assertEquals($response['body']['languages'][0]['code'], 'aa');
$this->assertEquals($response['body']['languages'][0]['name'], 'Afar');
$this->assertEquals($response['body']['languages'][0]['nativeName'], 'Afar');
2020-05-25 01:07:05 +12:00
2021-12-02 04:09:57 +13:00
$this->assertEquals($response['body']['languages'][183]['code'], 'zu');
$this->assertEquals($response['body']['languages'][183]['name'], 'Zulu');
$this->assertEquals($response['body']['languages'][183]['nativeName'], 'isiZulu');
2020-05-25 01:07:05 +12:00
/**
* Test for FAILURE
*/
return [];
}
2021-04-27 22:45:21 +12:00
public function testLanguages(): array
2020-01-13 00:11:16 +13:00
{
/**
* Test for SUCCESS
*/
2020-07-13 16:43:24 +12:00
$languages = require('app/config/locale/codes.php');
2021-07-24 02:35:21 +12:00
$defaultCountries = require('app/config/locale/countries.php');
$defaultContinents = require('app/config/locale/continents.php');
2020-01-13 00:11:16 +13:00
foreach ($languages as $lang) {
$response = $this->client->call(Client::METHOD_GET, '/locale/countries', [
'content-type' => 'application/json',
2020-02-17 20:16:11 +13:00
'x-appwrite-project' => $this->getProject()['$id'],
2020-01-13 00:11:16 +13:00
'x-appwrite-locale' => $lang,
]);
2020-07-01 07:04:56 +12:00
2020-10-31 08:53:27 +13:00
if(!\is_array($response['body']['countries'])) {
2021-07-24 02:35:21 +12:00
throw new Exception('Failed to iterate locale: '.$lang);
2020-01-13 00:11:16 +13:00
}
2020-10-31 08:53:27 +13:00
foreach ($response['body']['countries'] as $i => $code) {
2021-07-24 02:35:21 +12:00
$this->assertContains($code['code'], $defaultCountries, $code['code'] . ' country should be removed from ' . $lang);
2020-01-13 00:11:16 +13:00
}
2020-10-31 08:53:27 +13:00
// foreach (array_keys($defaultCountries) as $i => $code) {
// $this->assertArrayHasKey($code, $response['body']['countries'], $code . ' country is missing from ' . $lang . ' (total: ' . count($response['body']['countries']) . ')');
// }
2020-01-13 00:11:16 +13:00
$this->assertEquals($response['headers']['status-code'], 200);
2020-10-31 08:53:27 +13:00
$this->assertEquals(194, $response['body']['sum']);
2020-01-13 00:11:16 +13:00
$response = $this->client->call(Client::METHOD_GET, '/locale/continents', [
'content-type' => 'application/json',
2020-02-17 20:16:11 +13:00
'x-appwrite-project' => $this->getProject()['$id'],
2020-01-13 00:11:16 +13:00
'x-appwrite-locale' => $lang,
]);
2020-10-31 08:53:27 +13:00
foreach ($response['body']['continents'] as $i => $code) {
2021-07-24 02:35:21 +12:00
$this->assertContains($code['code'], $defaultContinents, $code['code'] . ' continent should be removed from ' . $lang);
2020-01-13 00:11:16 +13:00
}
2020-10-31 08:53:27 +13:00
// foreach (array_keys($defaultContinents) as $i => $code) {
// $this->assertArrayHasKey($code, $response['body']['continents'], $code . ' continent is missing from ' . $lang . ' (total: ' . count($response['body']['continents']) . ')');
// }
2020-01-13 00:11:16 +13:00
$this->assertEquals($response['headers']['status-code'], 200);
2020-10-31 08:53:27 +13:00
$this->assertEquals(7, $response['body']['sum']);
2020-01-13 00:11:16 +13:00
}
/**
* Test for FAILURE
*/
return [];
}
}