function FieldUIRouteTest::testFieldUIRoutes

Same name in other branches
  1. 9 core/modules/field_ui/tests/src/Functional/FieldUIRouteTest.php \Drupal\Tests\field_ui\Functional\FieldUIRouteTest::testFieldUIRoutes()
  2. 8.9.x core/modules/field_ui/tests/src/Functional/FieldUIRouteTest.php \Drupal\Tests\field_ui\Functional\FieldUIRouteTest::testFieldUIRoutes()
  3. 11.x core/modules/field_ui/tests/src/Functional/FieldUIRouteTest.php \Drupal\Tests\field_ui\Functional\FieldUIRouteTest::testFieldUIRoutes()

Ensures that entity types with bundles do not break following entity types.

File

core/modules/field_ui/tests/src/Functional/FieldUIRouteTest.php, line 40

Class

FieldUIRouteTest
Tests the functionality of the Field UI route subscriber.

Namespace

Drupal\Tests\field_ui\Functional

Code

public function testFieldUIRoutes() : void {
    $route = \Drupal::service('router.route_provider')->getRouteByName('entity.entity_test.field_ui_fields');
    $is_admin = \Drupal::service('router.admin_context')->isAdminRoute($route);
    // Asserts that admin routes are correctly marked as such.
    $this->assertTrue($is_admin, 'Admin route correctly marked for "Manage fields" page.');
    $this->drupalLogin($this->drupalCreateUser([
        'administer account settings',
        'administer entity_test_no_id fields',
        'administer user fields',
        'administer user form display',
        'administer user display',
    ]));
    $this->drupalGet('entity_test_no_id/structure/entity_test/fields');
    $this->assertSession()
        ->pageTextContains('No fields are present yet.');
    $this->drupalGet('admin/config/people/accounts/fields');
    $this->assertSession()
        ->titleEquals('Manage fields | Drupal');
    $this->assertLocalTasks();
    // Test manage display tabs and titles.
    $this->drupalGet('admin/config/people/accounts/display/compact');
    $this->assertSession()
        ->statusCodeEquals(403);
    $this->drupalGet('admin/config/people/accounts/display');
    $this->assertSession()
        ->titleEquals('Manage display | Drupal');
    $this->assertLocalTasks();
    $edit = [
        'display_modes_custom[compact]' => TRUE,
    ];
    $this->submitForm($edit, 'Save');
    $this->drupalGet('admin/config/people/accounts/display/compact');
    $this->assertSession()
        ->titleEquals('Manage display | Drupal');
    $this->assertLocalTasks();
    // Test manage form display tabs and titles.
    $this->drupalGet('admin/config/people/accounts/form-display/register');
    $this->assertSession()
        ->statusCodeEquals(403);
    $this->drupalGet('admin/config/people/accounts/form-display');
    $this->assertSession()
        ->titleEquals('Manage form display | Drupal');
    $this->assertLocalTasks();
    $edit = [
        'display_modes_custom[register]' => TRUE,
    ];
    $this->submitForm($edit, 'Save');
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->drupalGet('admin/config/people/accounts/form-display/register');
    $this->assertSession()
        ->titleEquals('Manage form display | Drupal');
    $this->assertLocalTasks();
    // Test that default secondary tab is in first position.
    $this->assertSession()
        ->elementsCount('xpath', "//ul/li[1]/a[contains(text(), 'Default')]", 1);
    // Create new view mode and verify it's available on the Manage Display
    // screen after enabling it.
    EntityViewMode::create([
        'id' => 'user.test',
        'label' => 'Test',
        'targetEntityType' => 'user',
    ])->save();
    $this->container
        ->get('router.builder')
        ->rebuildIfNeeded();
    $edit = [
        'display_modes_custom[test]' => TRUE,
    ];
    $this->drupalGet('admin/config/people/accounts/display');
    $this->submitForm($edit, 'Save');
    $this->assertSession()
        ->linkExists('Test');
    // Create new form mode and verify it's available on the Manage Form
    // Display screen after enabling it.
    EntityFormMode::create([
        'id' => 'user.test',
        'label' => 'Test',
        'targetEntityType' => 'user',
    ])->save();
    $this->container
        ->get('router.builder')
        ->rebuildIfNeeded();
    $edit = [
        'display_modes_custom[test]' => TRUE,
    ];
    $this->drupalGet('admin/config/people/accounts/form-display');
    $this->submitForm($edit, 'Save');
    $this->assertSession()
        ->linkExists('Test');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.