You are here

public function LingotekDashboardTest::testDashboardAddLocaleAndThenLanguage in Lingotek Translation 8

Test that different locales from same language can be added.

File

src/Tests/LingotekDashboardTest.php, line 165
Contains \Drupal\lingotek\Tests\LingotekDashboardTest.

Class

LingotekDashboardTest
Tests the Lingotek dashboard.

Namespace

Drupal\lingotek\Tests

Code

public function testDashboardAddLocaleAndThenLanguage() {

  // Login as admin.
  $this
    ->drupalLogin($this->rootUser);
  $post = [
    'code' => 'es_AR',
    'language' => 'Spanish (Argentina)',
    'native' => 'Español',
    'direction' => '',
  ];
  $request = $this
    ->drupalPost('/admin/lingotek/dashboard_endpoint', 'application/json', $post);
  $response = json_decode($request, TRUE);
  $esArLanguage = ConfigurableLanguage::load('es');

  /** @var $esArLanguage ConfigurableLanguageInterface */
  $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
    ->drupalGet('/admin/lingotek/dashboard_endpoint');
  $response = json_decode($request, 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
    ->drupalPost('/admin/lingotek/dashboard_endpoint', 'application/json', $post);
  $response = json_decode($request, TRUE);
  $esEsLanguage = ConfigurableLanguage::load('es-es');

  /** @var $esEsLanguage ConfigurableLanguageInterface */
  $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
    ->drupalGet('/admin/lingotek/dashboard_endpoint');
  $response = json_decode($request, TRUE);
  $returned_languages = array_keys($response['languages']);
  $this
    ->assertIdentical([
    'en_US',
    'es_AR',
    'es_ES',
  ], $returned_languages);
}