FieldUIRouteTest.php in Drupal 10
File
core/modules/field_ui/tests/src/Functional/FieldUIRouteTest.php
View source
<?php
namespace Drupal\Tests\field_ui\Functional;
use Drupal\Core\Entity\Entity\EntityFormMode;
use Drupal\Core\Entity\Entity\EntityViewMode;
use Drupal\Tests\BrowserTestBase;
class FieldUIRouteTest extends BrowserTestBase {
protected static $modules = [
'block',
'entity_test',
'field_ui',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$this
->drupalLogin($this->rootUser);
$this
->drupalPlaceBlock('local_tasks_block');
}
public function testFieldUIRoutes() {
$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();
$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();
$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();
$this
->assertSession()
->elementsCount('xpath', "//ul/li[1]/a[contains(text(), 'Default')]", 1);
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');
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');
}
public function assertLocalTasks() : void {
$this
->assertSession()
->linkExists('Settings');
$this
->assertSession()
->linkExists('Manage fields');
$this
->assertSession()
->linkExists('Manage display');
$this
->assertSession()
->linkExists('Manage form display');
}
public function testAdminRoute() {
$route = \Drupal::service('router.route_provider')
->getRouteByName('entity.entity_test.field_ui_fields');
$is_admin = \Drupal::service('router.admin_context')
->isAdminRoute($route);
$this
->assertTrue($is_admin, 'Admin route correctly marked for "Manage fields" page.');
}
}