3 namespace Drupal\Tests\field_ui\Functional;
5 use Drupal\Core\Entity\Entity\EntityFormMode;
6 use Drupal\Core\Entity\Entity\EntityViewMode;
7 use Drupal\Tests\BrowserTestBase;
10 * Tests the functionality of the Field UI route subscriber.
14 class FieldUIRouteTest extends BrowserTestBase {
21 public static $modules = ['block', 'entity_test', 'field_ui'];
26 protected function setUp() {
29 $this->drupalLogin($this->rootUser);
30 $this->drupalPlaceBlock('local_tasks_block');
34 * Ensures that entity types with bundles do not break following entity types.
36 public function testFieldUIRoutes() {
37 $this->drupalGet('entity_test_no_id/structure/entity_test/fields');
38 $this->assertText('No fields are present yet.');
40 $this->drupalGet('admin/config/people/accounts/fields');
41 $this->assertTitle('Manage fields | Drupal');
42 $this->assertLocalTasks();
44 // Test manage display tabs and titles.
45 $this->drupalGet('admin/config/people/accounts/display/compact');
46 $this->assertResponse(403);
48 $this->drupalGet('admin/config/people/accounts/display');
49 $this->assertTitle('Manage display | Drupal');
50 $this->assertLocalTasks();
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();
58 // Test manage form display tabs and titles.
59 $this->drupalGet('admin/config/people/accounts/form-display/register');
60 $this->assertResponse(403);
62 $this->drupalGet('admin/config/people/accounts/form-display');
63 $this->assertTitle('Manage form display | Drupal');
64 $this->assertLocalTasks();
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.');
74 // Create new view mode and verify it's available on the Manage Display
75 // screen after enabling it.
76 EntityViewMode::create([
79 'targetEntityType' => 'user',
81 $this->container->get('router.builder')->rebuildIfNeeded();
83 $edit = ['display_modes_custom[test]' => TRUE];
84 $this->drupalPostForm('admin/config/people/accounts/display', $edit, t('Save'));
85 $this->assertLink('Test');
87 // Create new form mode and verify it's available on the Manage Form
88 // Display screen after enabling it.
89 EntityFormMode::create([
92 'targetEntityType' => 'user',
94 $this->container->get('router.builder')->rebuildIfNeeded();
96 $edit = ['display_modes_custom[test]' => TRUE];
97 $this->drupalPostForm('admin/config/people/accounts/form-display', $edit, t('Save'));
98 $this->assertLink('Test');
102 * Asserts that local tasks exists.
104 public function assertLocalTasks() {
105 $this->assertLink('Settings');
106 $this->assertLink('Manage fields');
107 $this->assertLink('Manage display');
108 $this->assertLink('Manage form display');
112 * Asserts that admin routes are correctly marked as such.
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.');