You are here

public function LingotekDashboardTest::testDashboardAddLanguageAndThenLocale in Lingotek Translation 3.7.x

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testDashboardAddLanguageAndThenLocale()
  2. 4.0.x tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testDashboardAddLanguageAndThenLocale()
  3. 3.0.x tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testDashboardAddLanguageAndThenLocale()
  4. 3.1.x tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testDashboardAddLanguageAndThenLocale()
  5. 3.2.x tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testDashboardAddLanguageAndThenLocale()
  6. 3.3.x tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testDashboardAddLanguageAndThenLocale()
  7. 3.4.x tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testDashboardAddLanguageAndThenLocale()
  8. 3.5.x tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testDashboardAddLanguageAndThenLocale()
  9. 3.6.x tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testDashboardAddLanguageAndThenLocale()
  10. 3.8.x tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testDashboardAddLanguageAndThenLocale()

Test that different locales from same language can be added.

File

tests/src/Functional/LingotekDashboardTest.php, line 170

Class

LingotekDashboardTest
Tests the Lingotek dashboard.

Namespace

Drupal\Tests\lingotek\Functional

Code

public function testDashboardAddLanguageAndThenLocale() {
  $url = Url::fromRoute('lingotek.dashboard_endpoint')
    ->setAbsolute()
    ->toString();
  $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', $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');

  /** @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_ES',
  ], $returned_languages);
  $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-ar', $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-ar');

  /** @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',
    'es_ES',
  ], $returned_languages);
}