Version 1
[yaffs-website] / web / core / modules / field_ui / tests / src / Functional / FieldUIRouteTest.php
1 <?php
2
3 namespace Drupal\Tests\field_ui\Functional;
4
5 use Drupal\Core\Entity\Entity\EntityFormMode;
6 use Drupal\Core\Entity\Entity\EntityViewMode;
7 use Drupal\Tests\BrowserTestBase;
8
9 /**
10  * Tests the functionality of the Field UI route subscriber.
11  *
12  * @group field_ui
13  */
14 class FieldUIRouteTest extends BrowserTestBase {
15
16   /**
17    * Modules to install.
18    *
19    * @var string[]
20    */
21   public static $modules = ['block', 'entity_test', 'field_ui'];
22
23   /**
24    * {@inheritdoc}
25    */
26   protected function setUp() {
27     parent::setUp();
28
29     $this->drupalLogin($this->rootUser);
30     $this->drupalPlaceBlock('local_tasks_block');
31   }
32
33   /**
34    * Ensures that entity types with bundles do not break following entity types.
35    */
36   public function testFieldUIRoutes() {
37     $this->drupalGet('entity_test_no_id/structure/entity_test/fields');
38     $this->assertText('No fields are present yet.');
39
40     $this->drupalGet('admin/config/people/accounts/fields');
41     $this->assertTitle('Manage fields | Drupal');
42     $this->assertLocalTasks();
43
44     // Test manage display tabs and titles.
45     $this->drupalGet('admin/config/people/accounts/display/compact');
46     $this->assertResponse(403);
47
48     $this->drupalGet('admin/config/people/accounts/display');
49     $this->assertTitle('Manage display | Drupal');
50     $this->assertLocalTasks();
51
52     $edit = ['display_modes_custom[compact]' => TRUE];
53     $this->drupalPostForm(NULL, $edit, t('Save'));
54     $this->drupalGet('admin/config/people/accounts/display/compact');
55     $this->assertTitle('Manage display | Drupal');
56     $this->assertLocalTasks();
57
58     // Test manage form display tabs and titles.
59     $this->drupalGet('admin/config/people/accounts/form-display/register');
60     $this->assertResponse(403);
61
62     $this->drupalGet('admin/config/people/accounts/form-display');
63     $this->assertTitle('Manage form display | Drupal');
64     $this->assertLocalTasks();
65
66     $edit = ['display_modes_custom[register]' => TRUE];
67     $this->drupalPostForm(NULL, $edit, t('Save'));
68     $this->assertResponse(200);
69     $this->drupalGet('admin/config/people/accounts/form-display/register');
70     $this->assertTitle('Manage form display | Drupal');
71     $this->assertLocalTasks();
72     $this->assert(count($this->xpath('//ul/li[1]/a[contains(text(), :text)]', [':text' => 'Default'])) == 1, 'Default secondary tab is in first position.');
73
74     // Create new view mode and verify it's available on the Manage Display
75     // screen after enabling it.
76     EntityViewMode::create([
77       'id' => 'user.test',
78       'label' => 'Test',
79       'targetEntityType' => 'user',
80     ])->save();
81     $this->container->get('router.builder')->rebuildIfNeeded();
82
83     $edit = ['display_modes_custom[test]' => TRUE];
84     $this->drupalPostForm('admin/config/people/accounts/display', $edit, t('Save'));
85     $this->assertLink('Test');
86
87     // Create new form mode and verify it's available on the Manage Form
88     // Display screen after enabling it.
89     EntityFormMode::create([
90       'id' => 'user.test',
91       'label' => 'Test',
92       'targetEntityType' => 'user',
93     ])->save();
94     $this->container->get('router.builder')->rebuildIfNeeded();
95
96     $edit = ['display_modes_custom[test]' => TRUE];
97     $this->drupalPostForm('admin/config/people/accounts/form-display', $edit, t('Save'));
98     $this->assertLink('Test');
99   }
100
101   /**
102    * Asserts that local tasks exists.
103    */
104   public function assertLocalTasks() {
105     $this->assertLink('Settings');
106     $this->assertLink('Manage fields');
107     $this->assertLink('Manage display');
108     $this->assertLink('Manage form display');
109   }
110
111   /**
112    * Asserts that admin routes are correctly marked as such.
113    */
114   public function testAdminRoute() {
115     $route = \Drupal::service('router.route_provider')->getRouteByName('entity.entity_test.field_ui_fields');
116     $is_admin = \Drupal::service('router.admin_context')->isAdminRoute($route);
117     $this->assertTrue($is_admin, 'Admin route correctly marked for "Manage fields" page.');
118   }
119
120 }