public function LingotekDashboardTest::testDashboardAddLocaleAndThenLanguage in Lingotek Translation 3.7.x
Same name and namespace in other branches
- 8.2 tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testDashboardAddLocaleAndThenLanguage()
- 4.0.x tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testDashboardAddLocaleAndThenLanguage()
- 3.0.x tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testDashboardAddLocaleAndThenLanguage()
- 3.1.x tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testDashboardAddLocaleAndThenLanguage()
- 3.2.x tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testDashboardAddLocaleAndThenLanguage()
- 3.3.x tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testDashboardAddLocaleAndThenLanguage()
- 3.4.x tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testDashboardAddLocaleAndThenLanguage()
- 3.5.x tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testDashboardAddLocaleAndThenLanguage()
- 3.6.x tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testDashboardAddLocaleAndThenLanguage()
- 3.8.x tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testDashboardAddLocaleAndThenLanguage()
Test that different locales from same language can be added.
File
- tests/
src/ Functional/ LingotekDashboardTest.php, line 259
Class
- LingotekDashboardTest
- Tests the Lingotek dashboard.
Namespace
Drupal\Tests\lingotek\FunctionalCode
public function testDashboardAddLocaleAndThenLanguage() {
$url = Url::fromRoute('lingotek.dashboard_endpoint')
->setAbsolute()
->toString();
$post = [
'code' => 'es_AR',
'language' => 'Spanish (Argentina)',
'native' => 'Español',
'direction' => '',
];
$request = $this->client
->post($url, [
'body' => http_build_query($post),
'cookies' => $this->cookies,
'headers' => [
'Accept' => 'application/json',
'Content-Type' => 'application/x-www-form-urlencoded',
],
'http_errors' => FALSE,
]);
$response = json_decode($request
->getBody(), TRUE);
$this
->assertIdentical('es', $response['xcode']);
$this
->assertIdentical('es_AR', $response['locale']);
$this
->assertIdentical(1, $response['active']);
$this
->assertIdentical(1, $response['enabled']);
$this
->assertIdentical(0, $response['source']['total']);
$this
->assertIdentical(0, $response['target']['total']);
$esArLanguage = ConfigurableLanguage::load('es');
/** @var \Drupal\language\ConfigurableLanguageInterface $esArLanguage */
$this
->assertNotNull($esArLanguage, 'Spanish (Argentina) language has been added.');
$this
->assertIdentical('Spanish (Argentina)', $esArLanguage
->getName());
$this
->assertIdentical(ConfigurableLanguage::DIRECTION_LTR, $esArLanguage
->getDirection());
// The language must be returned in the dashboard.
$request = $this->client
->get($url, [
'cookies' => $this->cookies,
'headers' => [
'Accept' => 'application/json',
],
'http_errors' => FALSE,
]);
$response = json_decode($request
->getBody(), TRUE);
$returned_languages = array_keys($response['languages']);
$this
->assertIdentical([
'en_US',
'es_AR',
], $returned_languages);
$post = [
'code' => 'es_ES',
'language' => 'Spanish (Spain)',
'native' => 'Español',
'direction' => '',
];
$request = $this->client
->post($url, [
'body' => http_build_query($post),
'cookies' => $this->cookies,
'headers' => [
'Accept' => 'application/json',
'Content-Type' => 'application/x-www-form-urlencoded',
],
'http_errors' => FALSE,
]);
$response = json_decode($request
->getBody(), TRUE);
$this
->assertIdentical('es-es', $response['xcode']);
$this
->assertIdentical('es_ES', $response['locale']);
$this
->assertIdentical(1, $response['active']);
$this
->assertIdentical(1, $response['enabled']);
$this
->assertIdentical(0, $response['source']['total']);
$this
->assertIdentical(0, $response['target']['total']);
$esEsLanguage = ConfigurableLanguage::load('es-es');
/** @var \Drupal\language\ConfigurableLanguageInterface $esEsLanguage */
$this
->assertNotNull($esEsLanguage, 'Spanish (Spain) language has been added.');
$this
->assertIdentical('Spanish (Spain)', $esEsLanguage
->getName());
$this
->assertIdentical(ConfigurableLanguage::DIRECTION_LTR, $esEsLanguage
->getDirection());
// The language must be returned in the dashboard.
$request = $this->client
->get($url, [
'cookies' => $this->cookies,
'headers' => [
'Accept' => 'application/json',
],
'http_errors' => FALSE,
]);
$response = json_decode($request
->getBody(), TRUE);
$returned_languages = array_keys($response['languages']);
$this
->assertIdentical([
'en_US',
'es_AR',
'es_ES',
], $returned_languages);
}