You are here

public function MetatagConfigTranslationTest::testConfigTranslationsExist in Metatag 8

Confirm the config defaults show on the translations page.

File

tests/src/Functional/MetatagConfigTranslationTest.php, line 82

Class

MetatagConfigTranslationTest
Ensures that the Metatag config translations work correctly.

Namespace

Drupal\Tests\metatag\Functional

Code

public function testConfigTranslationsExist() {

  // Ensure the config shows on the admin form.
  $this
    ->drupalGet('admin/config/regional/config-translation');
  $session = $this
    ->assertSession();
  $session
    ->statusCodeEquals(200);
  $session
    ->pageTextContains('Metatag defaults');

  // Load the main metatag_defaults config translation page.
  $this
    ->drupalGet('admin/config/regional/config-translation/metatag_defaults');
  $session
    ->statusCodeEquals(200);

  // @todo Update this to confirm the H1 is loaded.
  $session
    ->responseContains($this
    ->t('Metatag defaults'));

  // Load all of the Metatag defaults.
  $defaults = \Drupal::configFactory()
    ->listAll('metatag.metatag_defaults');

  /** @var \Drupal\Core\Config\ConfigManagerInterface $config_manager */
  $config_manager = \Drupal::service('config.manager');

  // Confirm each of the configs is available on the translation form.
  foreach ($defaults as $config_name) {
    if ($config_entity = $config_manager
      ->loadConfigEntityByName($config_name)) {
      $session
        ->pageTextContains($config_entity
        ->label());
    }
  }

  // Confirm that each config translation page can be loaded.
  foreach ($defaults as $config_name) {
    if ($config_entity = $config_manager
      ->loadConfigEntityByName($config_name)) {
      $this
        ->drupalGet('admin/config/search/metatag/' . $config_entity
        ->id() . '/translate');
      $session
        ->statusCodeEquals(200);
    }
    else {
      $this
        ->error('Unable to load a Metatag default config: ' . $config_name);
    }
  }
}