3 namespace Drupal\Tests\field_ui\Functional;
5 use Drupal\Tests\BrowserTestBase;
8 * Tests the entity display modes UI.
12 class EntityDisplayModeTest extends BrowserTestBase {
19 public static $modules = ['block', 'entity_test', 'field_ui'];
24 protected function setUp() {
27 $this->drupalPlaceBlock('local_actions_block');
28 $this->drupalPlaceBlock('page_title_block');
32 * Tests the EntityViewMode user interface.
34 public function testEntityViewModeUI() {
35 // Test the listing page.
36 $this->drupalGet('admin/structure/display-modes/view');
37 $this->assertResponse(403);
38 $this->drupalLogin($this->drupalCreateUser(['administer display modes']));
39 $this->drupalGet('admin/structure/display-modes/view');
40 $this->assertResponse(200);
41 $this->assertText(t('Add view mode'));
42 $this->assertLinkByHref('admin/structure/display-modes/view/add');
43 $this->assertLinkByHref('admin/structure/display-modes/view/add/entity_test');
45 $this->drupalGet('admin/structure/display-modes/view/add/entity_test_mulrev');
46 $this->assertResponse(404);
48 $this->drupalGet('admin/structure/display-modes/view/add');
49 $this->assertNoLink(t('Test entity - revisions and data table'), 'An entity type with no view builder cannot have view modes.');
51 // Test adding a view mode including dots in machine_name.
52 $this->clickLink(t('Test entity'));
54 'id' => strtolower($this->randomMachineName()) . '.' . strtolower($this->randomMachineName()),
55 'label' => $this->randomString(),
57 $this->drupalPostForm(NULL, $edit, t('Save'));
58 $this->assertRaw('The machine-readable name must contain only lowercase letters, numbers, and underscores.');
60 // Test adding a view mode.
62 'id' => strtolower($this->randomMachineName()),
63 'label' => $this->randomString(),
65 $this->drupalPostForm(NULL, $edit, t('Save'));
66 $this->assertRaw(t('Saved the %label view mode.', ['%label' => $edit['label']]));
68 // Test editing the view mode.
69 $this->drupalGet('admin/structure/display-modes/view/manage/entity_test.' . $edit['id']);
71 // Test deleting the view mode.
72 $this->clickLink(t('Delete'));
73 $this->assertRaw(t('Are you sure you want to delete the view mode %label?', ['%label' => $edit['label']]));
74 $this->drupalPostForm(NULL, NULL, t('Delete'));
75 $this->assertRaw(t('The view mode %label has been deleted.', ['%label' => $edit['label']]));
79 * Tests the EntityFormMode user interface.
81 public function testEntityFormModeUI() {
82 // Test the listing page.
83 $this->drupalGet('admin/structure/display-modes/form');
84 $this->assertResponse(403);
85 $this->drupalLogin($this->drupalCreateUser(['administer display modes']));
86 $this->drupalGet('admin/structure/display-modes/form');
87 $this->assertResponse(200);
88 $this->assertText(t('Add form mode'));
89 $this->assertLinkByHref('admin/structure/display-modes/form/add');
91 $this->drupalGet('admin/structure/display-modes/form/add/entity_test_no_label');
92 $this->assertResponse(404);
94 $this->drupalGet('admin/structure/display-modes/form/add');
95 $this->assertNoLink(t('Entity Test without label'), 'An entity type with no form cannot have form modes.');
97 // Test adding a view mode including dots in machine_name.
98 $this->clickLink(t('Test entity'));
100 'id' => strtolower($this->randomMachineName()) . '.' . strtolower($this->randomMachineName()),
101 'label' => $this->randomString(),
103 $this->drupalPostForm(NULL, $edit, t('Save'));
104 $this->assertRaw('The machine-readable name must contain only lowercase letters, numbers, and underscores.');
106 // Test adding a form mode.
108 'id' => strtolower($this->randomMachineName()),
109 'label' => $this->randomString(),
111 $this->drupalPostForm(NULL, $edit, t('Save'));
112 $this->assertRaw(t('Saved the %label form mode.', ['%label' => $edit['label']]));
114 // Test editing the form mode.
115 $this->drupalGet('admin/structure/display-modes/form/manage/entity_test.' . $edit['id']);
117 // Test deleting the form mode.
118 $this->clickLink(t('Delete'));
119 $this->assertRaw(t('Are you sure you want to delete the form mode %label?', ['%label' => $edit['label']]));
120 $this->drupalPostForm(NULL, NULL, t('Delete'));
121 $this->assertRaw(t('The form mode %label has been deleted.', ['%label' => $edit['label']]));