You are here

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

Code

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']);
}