You are here

public function FormModeManagerRouteTest::testUserEditFormModeManagerRoutes in Form mode manager 8

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/FormModeManagerRouteTest.php \Drupal\Tests\form_mode_manager\Functional\FormModeManagerRouteTest::testUserEditFormModeManagerRoutes()

Asserts User Edit Form Mode Manager routes exists.

File

tests/src/Functional/FormModeManagerRouteTest.php, line 155

Class

FormModeManagerRouteTest
Tests the routes generated by form_mode_manager.

Namespace

Drupal\Tests\form_mode_manager\Functional

Code

public function testUserEditFormModeManagerRoutes() {
  $this
    ->drupalLogin($this->adminUser);
  $user_form_mode_id = $this->formModeManager
    ->getFormModeMachineName($this->userFormMode
    ->id());
  $this
    ->drupalGet("user/{$this->rootUser->id()}/edit/{$user_form_mode_id}");
  $this
    ->assertSession()
    ->statusCodeEquals(200);

  // Test not found form mode edit.
  $user_form_mode_id = $this->formModeManager
    ->getFormModeMachineName($this->userFormMode
    ->id());
  $this
    ->drupalGet("user/{$this->adminUser->id()}/edit/not-valid-fm");
  $this
    ->assertSession()
    ->statusCodeEquals(404);

  // Test with just permission create xxx content.
  Role::load($this->testUser
    ->getRoles()[1])
    ->grantPermission("administer users")
    ->save();
  $this
    ->drupalLogin($this->testUser);
  $this
    ->drupalGet("user/{$this->testUser->id()}/edit/{$user_form_mode_id}");
  $this
    ->assertSession()
    ->statusCodeEquals(403);

  // Test with permission edit any xxx content and use xxx form mode.
  Role::load($this->testUser
    ->getRoles()[1])
    ->grantPermission("use {$this->userFormMode->id()} form mode")
    ->save();
  $this
    ->drupalLogin($this->testUser);
  $this
    ->drupalGet("user/{$this->adminUser->id()}/edit/{$user_form_mode_id}");
  $this
    ->assertSession()
    ->statusCodeEquals(200);
}