function ManageFieldsTest::testFieldDropButtonOperations

Same name and namespace in other branches
  1. 9 core/modules/field_ui/tests/src/Functional/ManageFieldsTest.php \Drupal\Tests\field_ui\Functional\ManageFieldsTest::testFieldDropButtonOperations()
  2. 8.9.x core/modules/field_ui/tests/src/Functional/ManageFieldsTest.php \Drupal\Tests\field_ui\Functional\ManageFieldsTest::testFieldDropButtonOperations()
  3. 11.x core/modules/field_ui/tests/src/Functional/ManageFieldsTest.php \Drupal\Tests\field_ui\Functional\ManageFieldsTest::testFieldDropButtonOperations()

Tests drop button operations on the manage fields page.

File

core/modules/field_ui/tests/src/Functional/ManageFieldsTest.php, line 62

Class

ManageFieldsTest
Tests the Manage Display page of a fieldable entity type.

Namespace

Drupal\Tests\field_ui\Functional

Code

public function testFieldDropButtonOperations() : void {
  $assert_session = $this->assertSession();
  $node_type = $this->drupalCreateContentType();
  $bundle = $node_type->id();
  /** @var \Drupal\field\FieldStorageConfigInterface $storage */
  $storage = $this->container
    ->get('entity_type.manager')
    ->getStorage('field_storage_config')
    ->create([
    'type' => 'string',
    'field_name' => 'highlander',
    'entity_type' => 'node',
  ]);
  $storage->save();
  $this->container
    ->get('entity_type.manager')
    ->getStorage('field_config')
    ->create([
    'field_storage' => $storage,
    'bundle' => $bundle,
  ])
    ->save();
  $this->drupalGet("/admin/structure/types/manage/{$bundle}/fields");
  // Check that the summary element for the string field type exists and has
  // the correct text (which comes from the FieldItemBase class).
  $element = $assert_session->elementExists('css', '#highlander');
  $summary = $assert_session->elementExists('css', '.field-settings-summary-cell > ul > li', $element);
  $field_label = $this->container
    ->get('plugin.manager.field.field_type')
    ->getDefinitions()['string']['label'];
  $this->assertEquals($field_label, $summary->getText());
  // Add an entity reference field, and check that its summary is custom.
  /** @var \Drupal\field\FieldStorageConfigInterface $storage */
  $storage = $this->container
    ->get('entity_type.manager')
    ->getStorage('field_storage_config')
    ->create([
    'type' => 'entity_reference',
    'field_name' => 'downlander',
    'entity_type' => 'node',
    'settings' => [
      'target_type' => 'node',
    ],
  ]);
  $storage->save();
  $this->container
    ->get('entity_type.manager')
    ->getStorage('field_config')
    ->create([
    'field_storage' => $storage,
    'bundle' => $bundle,
    'entity_type' => 'node',
    'settings' => [
      'handler_settings' => [
        'target_bundles' => [
          $bundle => $bundle,
        ],
      ],
    ],
  ])
    ->save();
  $this->drupalGet("/admin/structure/types/manage/{$bundle}/fields");
  $element = $assert_session->elementExists('css', '#downlander');
  $custom_summary_text = 'Reference type: Content';
  $allowed_bundles_text = "Content type: {$bundle}";
  $this->assertStringContainsString($custom_summary_text, $element->getText());
  $this->assertStringContainsString($allowed_bundles_text, $element->getText());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.