You are here

public function SearchApiSortsUpdate8103Test::testUpdate8103 in Search API sorts 8

Tests that search_api_sorts_field translations are correctly updated.

See also

search_api_sorts_update_8103()

File

tests/src/Functional/Update/SearchApiSortsUpdate8103Test.php, line 80

Class

SearchApiSortsUpdate8103Test
Tests the Search api sorts upgrade path for update 8103.

Namespace

Drupal\Tests\search_api_sorts\Functional\Update

Code

public function testUpdate8103() {
  $this
    ->runUpdates();

  // Check the search_api_sorts_field in the default language without
  // translation.
  // Expected output: config exists in the default language with no
  // translation.
  $config = $this
    ->config('search_api_sorts.search_api_sorts_field.views_page---search_api_sorts_test_view__page_1_type');
  $this
    ->assertEquals('type', $config
    ->get('label'));
  $this
    ->assertEquals('en', $config
    ->get('langcode'));
  $fr_config = $this->languageManager
    ->getLanguageConfigOverride('fr', 'search_api_sorts.search_api_sorts_field.views_page---search_api_sorts_test_view__page_1_type');
  $this
    ->assertTrue($fr_config
    ->isNew());

  // Check the search_api_sorts_field in a different language without
  // translation.
  // Expected output: Label is replaced to the default language and
  // label is also added as translation.
  $config = $this
    ->config('search_api_sorts.search_api_sorts_field.views_page---search_api_sorts_test_view__page_1_id');
  $this
    ->assertEquals('Identifiant', $config
    ->get('label'));
  $this
    ->assertEquals('en', $config
    ->get('langcode'));
  $fr_config = $this->languageManager
    ->getLanguageConfigOverride('fr', 'search_api_sorts.search_api_sorts_field.views_page---search_api_sorts_test_view__page_1_id');
  $this
    ->assertFalse($fr_config
    ->isNew());
  $this
    ->assertEquals('Identifiant', $fr_config
    ->get('label'));

  // Check the search_api_sorts_field search_api_sorts_field in the default
  // language with a translation.
  // Expected output: config was already correct, so this should stay the
  // same.
  $config = $this
    ->config('search_api_sorts.search_api_sorts_field.views_page---search_api_sorts_test_view__page_1_created');
  $this
    ->assertEquals('created', $config
    ->get('label'));
  $this
    ->assertEquals('en', $config
    ->get('langcode'));
  $fr_config = $this->languageManager
    ->getLanguageConfigOverride('fr', 'search_api_sorts.search_api_sorts_field.views_page---search_api_sorts_test_view__page_1_created');
  $this
    ->assertFalse($fr_config
    ->isNew());
  $this
    ->assertEquals('Créé sur', $fr_config
    ->get('label'));

  // Check the search_api_sorts_field search_api_sorts_field iin a different
  // language with a translation in the default language.
  // Expected output: English label should be moved to the default config
  // and the French label is added as a translation.
  $config = $this
    ->config('search_api_sorts.search_api_sorts_field.views_page---search_api_sorts_test_view__page_1_title');
  $this
    ->assertEquals('Title', $config
    ->get('label'));
  $this
    ->assertEquals('en', $config
    ->get('langcode'));
  $fr_config = $this->languageManager
    ->getLanguageConfigOverride('fr', 'search_api_sorts.search_api_sorts_field.views_page---search_api_sorts_test_view__page_1_title');
  $this
    ->assertFalse($fr_config
    ->isNew());
  $this
    ->assertEquals('Titre', $fr_config
    ->get('label'));
}