Version 1
[yaffs-website] / web / core / modules / field_ui / tests / src / Functional / EntityDisplayModeTest.php
1 <?php
2
3 namespace Drupal\Tests\field_ui\Functional;
4
5 use Drupal\Tests\BrowserTestBase;
6
7 /**
8  * Tests the entity display modes UI.
9  *
10  * @group field_ui
11  */
12 class EntityDisplayModeTest extends BrowserTestBase {
13
14   /**
15    * Modules to enable.
16    *
17    * @var string[]
18    */
19   public static $modules = ['block', 'entity_test', 'field_ui'];
20
21   /**
22    * {@inheritdoc}
23    */
24   protected function setUp() {
25     parent::setUp();
26
27     $this->drupalPlaceBlock('local_actions_block');
28     $this->drupalPlaceBlock('page_title_block');
29   }
30
31   /**
32    * Tests the EntityViewMode user interface.
33    */
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');
44
45     $this->drupalGet('admin/structure/display-modes/view/add/entity_test_mulrev');
46     $this->assertResponse(404);
47
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.');
50
51     // Test adding a view mode including dots in machine_name.
52     $this->clickLink(t('Test entity'));
53     $edit = [
54       'id' => strtolower($this->randomMachineName()) . '.' . strtolower($this->randomMachineName()),
55       'label' => $this->randomString(),
56     ];
57     $this->drupalPostForm(NULL, $edit, t('Save'));
58     $this->assertRaw('The machine-readable name must contain only lowercase letters, numbers, and underscores.');
59
60     // Test adding a view mode.
61     $edit = [
62       'id' => strtolower($this->randomMachineName()),
63       'label' => $this->randomString(),
64     ];
65     $this->drupalPostForm(NULL, $edit, t('Save'));
66     $this->assertRaw(t('Saved the %label view mode.', ['%label' => $edit['label']]));
67
68     // Test editing the view mode.
69     $this->drupalGet('admin/structure/display-modes/view/manage/entity_test.' . $edit['id']);
70
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']]));
76   }
77
78   /**
79    * Tests the EntityFormMode user interface.
80    */
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');
90
91     $this->drupalGet('admin/structure/display-modes/form/add/entity_test_no_label');
92     $this->assertResponse(404);
93
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.');
96
97     // Test adding a view mode including dots in machine_name.
98     $this->clickLink(t('Test entity'));
99     $edit = [
100       'id' => strtolower($this->randomMachineName()) . '.' . strtolower($this->randomMachineName()),
101       'label' => $this->randomString(),
102     ];
103     $this->drupalPostForm(NULL, $edit, t('Save'));
104     $this->assertRaw('The machine-readable name must contain only lowercase letters, numbers, and underscores.');
105
106     // Test adding a form mode.
107     $edit = [
108       'id' => strtolower($this->randomMachineName()),
109       'label' => $this->randomString(),
110     ];
111     $this->drupalPostForm(NULL, $edit, t('Save'));
112     $this->assertRaw(t('Saved the %label form mode.', ['%label' => $edit['label']]));
113
114     // Test editing the form mode.
115     $this->drupalGet('admin/structure/display-modes/form/manage/entity_test.' . $edit['id']);
116
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']]));
122   }
123
124 }