public function FormModeManagerRouteTest::testEditFormModeManagerRoutes in Form mode manager 8
Same name and namespace in other branches
- 8.2 tests/src/Functional/FormModeManagerRouteTest.php \Drupal\Tests\form_mode_manager\Functional\FormModeManagerRouteTest::testEditFormModeManagerRoutes()
Asserts Edit Form Mode Manager routes exists.
File
- tests/src/ Functional/ FormModeManagerRouteTest.php, line 119 
Class
- FormModeManagerRouteTest
- Tests the routes generated by form_mode_manager.
Namespace
Drupal\Tests\form_mode_manager\FunctionalCode
public function testEditFormModeManagerRoutes() {
  $this
    ->drupalLogin($this->adminUser);
  $node_form_mode_id = $this->formModeManager
    ->getFormModeMachineName($this->nodeFormMode
    ->id());
  $this->node1 = $this
    ->drupalCreateNode([
    'title' => 'Form Mode Manager content test',
    'type' => $this->nodeTypeFmm1
      ->id(),
  ]);
  $this
    ->drupalGet("node/{$this->node1->id()}/edit/{$node_form_mode_id}");
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  // Test not found form mode edit.
  $node_form_mode_id = $this->formModeManager
    ->getFormModeMachineName($this->nodeFormMode
    ->id());
  $this
    ->drupalGet("node/{$this->node1->id()}/edit/not-valid-fm");
  $this
    ->assertSession()
    ->statusCodeEquals(404);
  // Test with just permission create xxx content.
  Role::load($this->testUser
    ->getRoles()[1])
    ->grantPermission("create {$this->nodeTypeFmm1->id()} content")
    ->save();
  $this
    ->drupalLogin($this->testUser);
  $this
    ->drupalGet("node/{$this->node1->id()}/edit/{$node_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("edit any {$this->nodeTypeFmm1->id()} content")
    ->grantPermission("use {$this->nodeFormMode->id()} form mode")
    ->save();
  $this
    ->drupalLogin($this->testUser);
  $this
    ->drupalGet("node/{$this->node1->id()}/edit/{$node_form_mode_id}");
  $this
    ->assertSession()
    ->statusCodeEquals(200);
}