You are here

public function EntityDisplayModeTest::testEntityFormModeUI in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/field_ui/src/Tests/EntityDisplayModeTest.php \Drupal\field_ui\Tests\EntityDisplayModeTest::testEntityFormModeUI()

Tests the EntityFormMode user interface.

File

core/modules/field_ui/src/Tests/EntityDisplayModeTest.php, line 86
Contains \Drupal\field_ui\Tests\EntityDisplayModeTest.

Class

EntityDisplayModeTest
Tests the entity display modes UI.

Namespace

Drupal\field_ui\Tests

Code

public function testEntityFormModeUI() {

  // Test the listing page.
  $this
    ->drupalGet('admin/structure/display-modes/form');
  $this
    ->assertResponse(403);
  $this
    ->drupalLogin($this
    ->drupalCreateUser(array(
    'administer display modes',
  )));
  $this
    ->drupalGet('admin/structure/display-modes/form');
  $this
    ->assertResponse(200);
  $this
    ->assertText(t('Add new form mode'));
  $this
    ->assertLinkByHref('admin/structure/display-modes/form/add');
  $this
    ->drupalGet('admin/structure/display-modes/form/add/entity_test_no_label');
  $this
    ->assertResponse(404);
  $this
    ->drupalGet('admin/structure/display-modes/form/add');
  $this
    ->assertNoLink(t('Entity Test without label'), 'An entity type with no form cannot have form modes.');

  // Test adding a view mode including dots in machine_name.
  $this
    ->clickLink(t('Test entity'));
  $edit = array(
    'id' => strtolower($this
      ->randomMachineName()) . '.' . strtolower($this
      ->randomMachineName()),
    'label' => $this
      ->randomString(),
  );
  $this
    ->drupalPostForm(NULL, $edit, t('Save'));
  $this
    ->assertRaw('The machine-readable name must contain only lowercase letters, numbers, and underscores.');

  // Test adding a form mode.
  $edit = array(
    'id' => strtolower($this
      ->randomMachineName()),
    'label' => $this
      ->randomString(),
  );
  $this
    ->drupalPostForm(NULL, $edit, t('Save'));
  $this
    ->assertRaw(t('Saved the %label form mode.', array(
    '%label' => $edit['label'],
  )));

  // Test editing the form mode.
  $this
    ->drupalGet('admin/structure/display-modes/form/manage/entity_test.' . $edit['id']);

  // Test deleting the form mode.
  $this
    ->clickLink(t('Delete'));
  $this
    ->assertRaw(t('Are you sure you want to delete the form mode %label?', array(
    '%label' => $edit['label'],
  )));
  $this
    ->drupalPostForm(NULL, NULL, t('Delete'));
  $this
    ->assertRaw(t('The form mode %label has been deleted.', array(
    '%label' => $edit['label'],
  )));
}