public function LingotekDashboardTest::testDisabledLanguageInStats in Lingotek Translation 3.8.x
Same name and namespace in other branches
- 8.2 tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testDisabledLanguageInStats()
- 4.0.x tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testDisabledLanguageInStats()
- 3.0.x tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testDisabledLanguageInStats()
- 3.1.x tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testDisabledLanguageInStats()
- 3.2.x tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testDisabledLanguageInStats()
- 3.3.x tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testDisabledLanguageInStats()
- 3.4.x tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testDisabledLanguageInStats()
- 3.5.x tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testDisabledLanguageInStats()
- 3.6.x tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testDisabledLanguageInStats()
- 3.7.x tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testDisabledLanguageInStats()
Tests that disabled language appear as disabled in stats.
File
- tests/
src/ Functional/ LingotekDashboardTest.php, line 486
Class
- LingotekDashboardTest
- Tests the Lingotek dashboard.
Namespace
Drupal\Tests\lingotek\FunctionalCode
public function testDisabledLanguageInStats() {
$url = Url::fromRoute('lingotek.dashboard_endpoint')
->setAbsolute()
->toString();
// Add a language.
$post = [
'code' => 'es_ES',
'language' => 'Spanish (Spain)',
'native' => 'Español (España)',
'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('POST', $response['method']);
$this
->assertIdentical('es', $response['xcode']);
$this
->assertIdentical('es_ES', $response['locale']);
$this
->assertIdentical(1, $response['active']);
$this
->assertIdentical(1, $response['enabled']);
// Rebuild the container so that the new languages are picked up by services
// that hold a list of languages.
$this
->rebuildContainer();
/** @var LanguageManagerInterface $language_manager */
$language_manager = \Drupal::service('language_manager');
$languages = $language_manager
->getLanguages();
$this
->assertIdentical(2, count($languages));
// Check the stats.
$request = $this->client
->get($url, [
'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('GET', $response['method']);
$this
->assertIdentical(2, $response['count']);
$this
->assertIdentical('en', $response['languages']['en_US']['xcode']);
$this
->assertIdentical(1, $response['languages']['en_US']['active']);
$this
->assertIdentical(1, $response['languages']['en_US']['enabled']);
$this
->assertIdentical('es', $response['languages']['es_ES']['xcode']);
$this
->assertIdentical(1, $response['languages']['es_ES']['active']);
$this
->assertIdentical(1, $response['languages']['es_ES']['enabled']);
// Disable Spanish.
$request = $this->client
->delete($url, [
'body' => http_build_query([
'code' => 'es_ES',
]),
'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('DELETE', $response['method']);
$this
->assertIdentical('es', $response['language']);
$this
->assertIdentical('Language disabled: es_ES', $response['message']);
// Rebuild the container so that the new languages are picked up by services
// that hold a list of languages.
$this
->rebuildContainer();
// Check the stats.
$request = $this->client
->get($url, [
'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('GET', $response['method']);
$this
->assertIdentical(2, $response['count']);
$this
->assertIdentical('en', $response['languages']['en_US']['xcode']);
$this
->assertIdentical(1, $response['languages']['en_US']['active']);
$this
->assertIdentical(1, $response['languages']['en_US']['enabled']);
$this
->assertIdentical('es', $response['languages']['es_ES']['xcode']);
$this
->assertIdentical(0, $response['languages']['es_ES']['active']);
$this
->assertIdentical(1, $response['languages']['es_ES']['enabled']);
}