You are here

public function ConfigTranslationListUiTest::doFieldListTest in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/config_translation/tests/src/Functional/ConfigTranslationListUiTest.php \Drupal\Tests\config_translation\Functional\ConfigTranslationListUiTest::doFieldListTest()
  2. 9 core/modules/config_translation/tests/src/Functional/ConfigTranslationListUiTest.php \Drupal\Tests\config_translation\Functional\ConfigTranslationListUiTest::doFieldListTest()

Tests the field listing for the translate operation.

File

core/modules/config_translation/tests/src/Functional/ConfigTranslationListUiTest.php, line 394

Class

ConfigTranslationListUiTest
Visit all lists.

Namespace

Drupal\Tests\config_translation\Functional

Code

public function doFieldListTest() {

  // Create a base content type.
  $content_type = $this
    ->drupalCreateContentType([
    'type' => mb_strtolower($this
      ->randomMachineName(16)),
    'name' => $this
      ->randomMachineName(),
  ]);

  // Create a block content type.
  $block_content_type = BlockContentType::create([
    'id' => 'basic',
    'label' => 'Basic',
    'revision' => FALSE,
  ]);
  $block_content_type
    ->save();
  $field = FieldConfig::create([
    // The field storage is guaranteed to exist because it is supplied by the
    // block_content module.
    'field_storage' => FieldStorageConfig::loadByName('block_content', 'body'),
    'bundle' => $block_content_type
      ->id(),
    'label' => 'Body',
    'settings' => [
      'display_summary' => FALSE,
    ],
  ]);
  $field
    ->save();

  // Look at a few fields on a few entity types.
  $pages = [
    [
      'list' => 'admin/structure/types/manage/' . $content_type
        ->id() . '/fields',
      'field' => 'node.' . $content_type
        ->id() . '.body',
    ],
    [
      'list' => 'admin/structure/block/block-content/manage/basic/fields',
      'field' => 'block_content.basic.body',
    ],
  ];
  foreach ($pages as $values) {

    // Get fields listing.
    $this
      ->drupalGet($values['list']);
    $translate_link = $values['list'] . '/' . $values['field'] . '/translate';

    // Test if the link to translate the field is on the page.
    $this
      ->assertSession()
      ->linkByHrefExists($translate_link);

    // Test if the link to translate actually goes to the translate page.
    $this
      ->drupalGet($translate_link);
    $this
      ->assertSession()
      ->responseContains('<th>Language</th>');
  }
}