You are here

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

Same name and namespace in other branches
  1. 4.0.x tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testEndpointResponseWithEmptyLocale()
  2. 3.5.x tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testEndpointResponseWithEmptyLocale()
  3. 3.6.x tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testEndpointResponseWithEmptyLocale()
  4. 3.8.x tests/src/Functional/LingotekDashboardTest.php \Drupal\Tests\lingotek\Functional\LingotekDashboardTest::testEndpointResponseWithEmptyLocale()

Ensure language without locale doesn't mess with the response.

File

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

Class

LingotekDashboardTest
Tests the Lingotek dashboard.

Namespace

Drupal\Tests\lingotek\Functional

Code

public function testEndpointResponseWithEmptyLocale() {
  $basepath = \Drupal::request()
    ->getBasePath();
  $language = ConfigurableLanguage::create([
    'id' => 'en-hk',
    'name' => 'English (Hong-Kong)',
  ]);
  $language
    ->setThirdPartySetting('lingotek', 'locale', '');
  $language
    ->save();
  $url = Url::fromRoute('lingotek.dashboard_endpoint')
    ->setAbsolute()
    ->toString();

  // 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,
  ]);
  $responseData = Json::decode($request
    ->getBody());
  $this
    ->assertEquals($responseData['count'], 2);
  $this
    ->assertCount(2, $responseData['languages']);

  // We default to the known code, which is only the langcode.
  $this
    ->assertEquals($responseData['languages']['en-hk']['active'], 1);
  $this
    ->assertEquals($responseData['languages']['en_US']['active'], 1);
}