You are here

public function LingotekDashboardTest::testDashboardCanAddLanguage 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::testDashboardCanAddLanguage()
  2. 4.0.x tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testDashboardCanAddLanguage()
  3. 3.0.x tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testDashboardCanAddLanguage()
  4. 3.1.x tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testDashboardCanAddLanguage()
  5. 3.2.x tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testDashboardCanAddLanguage()
  6. 3.3.x tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testDashboardCanAddLanguage()
  7. 3.4.x tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testDashboardCanAddLanguage()
  8. 3.5.x tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testDashboardCanAddLanguage()
  9. 3.6.x tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testDashboardCanAddLanguage()
  10. 3.8.x tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testDashboardCanAddLanguage()

Test that a language can be added.

File

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

Class

LingotekDashboardTest
Tests the Lingotek dashboard.

Namespace

Drupal\Tests\lingotek\Functional

Code

public function testDashboardCanAddLanguage() {
  $url = Url::fromRoute('lingotek.dashboard_endpoint')
    ->setAbsolute()
    ->toString();
  $post = [
    'code' => 'it_IT',
    'language' => 'Italian',
    'native' => 'Italiano',
    '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('it', $response['xcode']);
  $this
    ->assertIdentical('it_IT', $response['locale']);
  $this
    ->assertIdentical(1, $response['active']);
  $this
    ->assertIdentical(1, $response['enabled']);
  $this
    ->assertIdentical(0, $response['source']['total']);
  $this
    ->assertIdentical(0, $response['target']['total']);
  $italian_language = ConfigurableLanguage::load('it');

  /** @var \Drupal\language\ConfigurableLanguageInterface $italian_language */
  $this
    ->assertNotNull($italian_language, 'Italian language has been added.');
  $this
    ->assertIdentical('Italian', $italian_language
    ->getName());
  $this
    ->assertIdentical(ConfigurableLanguage::DIRECTION_LTR, $italian_language
    ->getDirection());

  // @ToDo: The native language is not saved.
  // $config_translation = \Drupal::languageManager()->getLanguageConfigOverride('it', $italian_language->id());
}