You are here

public function FormModeManagerRouteTest::testAnonymousSpecificFormModeManagerRoutes in Form mode manager 8.2

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

Asserts that anon had access to a specific form mode, create and edit node.

Throws

\Behat\Mink\Exception\ExpectationException

File

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

Class

FormModeManagerRouteTest
Tests the routes generated by form_mode_manager.

Namespace

Drupal\Tests\form_mode_manager\Functional

Code

public function testAnonymousSpecificFormModeManagerRoutes() {
  $node_form_mode_id = $this->formModeManager
    ->getFormModeMachineName($this->nodeFormMode
    ->id());
  $node_type_test_page = $this
    ->drupalCreateContentType([
    'type' => 'test_page',
    'name' => 'Test Page',
  ]);
  $this
    ->setUpFormMode("admin/structure/types/manage/test_page/form-display", $this->nodeFormMode
    ->id());
  $this
    ->drupalLogin($this->anonymousUser);
  Role::load($this->anonymousUser
    ->getRoles()[1])
    ->grantPermission("use {$this->nodeFormMode->id()} form mode")
    ->grantPermission("create {$this->nodeTypeFmm1->id()} content")
    ->grantPermission("edit own {$this->nodeTypeFmm1->id()} content")
    ->save();

  // Add a node with custum form mode.
  $this
    ->drupalGet("node/add/{$this->nodeTypeFmm1->id()}/{$node_form_mode_id}");
  $this
    ->assertSession()
    ->statusCodeEquals(200);

  // Add a node with default form mode not available.
  $this
    ->drupalGet("node/add/{$this->nodeTypeFmm1->id()}");
  $this
    ->assertSession()
    ->statusCodeEquals(403);

  // Add a node with custum form mode.
  $this->node1 = $this
    ->drupalCreateNode([
    'title' => 'Test node',
    'type' => $this->nodeTypeFmm1
      ->id(),
  ]);

  // Edit node  with custum form mode.
  $this
    ->drupalGet("node/{$this->node1->id()}/edit/{$node_form_mode_id}");
  $this
    ->assertSession()
    ->statusCodeEquals(200);

  // Edit a node with default form mode not available.
  $this
    ->drupalGet("node/{$this->node1->id()}/edit");
  $this
    ->assertSession()
    ->statusCodeEquals(403);

  // Make sure we can't add test_page content as this "anonymous" user.
  $this
    ->drupalGet("node/add/test_page");
  $this
    ->assertSession()
    ->statusCodeEquals(403);

  // Even if using a specific form mode.
  $this
    ->drupalGet("node/add/test_page/{$node_form_mode_id}");
  $this
    ->assertSession()
    ->statusCodeEquals(403);
  $this
    ->drupalLogin($this->rootUser);
  $this
    ->drupalGet("node/add/test_page");
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->drupalGet("node/add/test_page/{$node_form_mode_id}");
  $this
    ->assertSession()
    ->statusCodeEquals(200);
}