You are here

protected function LocaleUpdateBase::assertTranslation in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/locale/tests/src/Functional/LocaleUpdateBase.php \Drupal\Tests\locale\Functional\LocaleUpdateBase::assertTranslation()

Checks the translation of a string.

Parameters

string $source: Translation source string.

string $translation: Translation to check. Use empty string to check for a non-existent translation.

string $langcode: Language code of the language to translate to.

string $message: (optional) A message to display with the assertion.

3 calls to LocaleUpdateBase::assertTranslation()
LocaleUpdateTest::testEnableLanguage in core/modules/locale/tests/src/Functional/LocaleUpdateTest.php
Tests automatic translation import when a language is added.
LocaleUpdateTest::testEnableUninstallModule in core/modules/locale/tests/src/Functional/LocaleUpdateTest.php
Tests automatic translation import when a module is enabled.
LocaleUpdateTest::testUpdateImportModeNone in core/modules/locale/tests/src/Functional/LocaleUpdateTest.php
Tests translation import and don't overwrite any translation.

File

core/modules/locale/tests/src/Functional/LocaleUpdateBase.php, line 304

Class

LocaleUpdateBase
Base class for testing updates to string translations.

Namespace

Drupal\Tests\locale\Functional

Code

protected function assertTranslation($source, $translation, $langcode, $message = '') {
  $query = Database::getConnection()
    ->select('locales_target', 'lt');
  $query
    ->innerJoin('locales_source', 'ls', '[ls].[lid] = [lt].[lid]');
  $db_translation = $query
    ->fields('lt', [
    'translation',
  ])
    ->condition('ls.source', $source)
    ->condition('lt.language', $langcode)
    ->execute()
    ->fetchField();
  $db_translation = $db_translation == FALSE ? '' : $db_translation;
  $this
    ->assertEquals($translation, $db_translation, $message ? $message : new FormattableMarkup('Correct translation of %source (%language)', [
    '%source' => $source,
    '%language' => $langcode,
  ]));
}