You are here

public function FormModeManagerRouteTest::testAddFormModeManagerRoutes 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::testAddFormModeManagerRoutes()

Asserts Add Form Mode Manager routes exists.

File

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

Class

FormModeManagerRouteTest
Tests the routes generated by form_mode_manager.

Namespace

Drupal\Tests\form_mode_manager\Functional

Code

public function testAddFormModeManagerRoutes() {
  $node_form_mode_id = $this->formModeManager
    ->getFormModeMachineName($this->nodeFormMode
    ->id());
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalGet("node/add/{$this->nodeTypeFmm1->id()}/{$node_form_mode_id}");
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->drupalLogin($this->anonymousUser);
  $this
    ->drupalGet("node/add/{$this->nodeTypeFmm1->id()}/{$node_form_mode_id}");
  $this
    ->assertSession()
    ->statusCodeEquals(403);

  // Test not found form mode add.
  $this
    ->drupalLogin($this->anonymousUser);
  $this
    ->drupalGet("node/add/{$this->nodeTypeFmm1->id()}/not-valid-fm");
  $this
    ->assertSession()
    ->statusCodeEquals(404);

  // Test add with juste permission create xxx content.
  Role::load($this->testUser
    ->getRoles()[1])
    ->grantPermission("create {$this->nodeTypeFmm1->id()} content")
    ->grantPermission("use node.default form mode")
    ->save();
  $this
    ->drupalLogin($this->testUser);
  $this
    ->drupalGet("node/add/{$this->nodeTypeFmm1->id()}");
  $this
    ->assertSession()
    ->statusCodeEquals(200);

  // Test add content with form mode without permission use xxx form mode.
  $this
    ->drupalGet("node/add/{$this->nodeTypeFmm1->id()}/{$node_form_mode_id}");
  $this
    ->assertSession()
    ->statusCodeEquals(403);

  // Test add content with form mode with permission use xxx form mode.
  Role::load($this->testUser
    ->getRoles()[1])
    ->grantPermission("use {$this->nodeFormMode->id()} form mode")
    ->save();
  $this
    ->drupalGet("node/add/{$this->nodeTypeFmm1->id()}/{$node_form_mode_id}");
  $this
    ->assertSession()
    ->statusCodeEquals(200);
}