You are here

public function BlockUiTest::testRouteProtection in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/block/tests/src/Functional/BlockUiTest.php \Drupal\Tests\block\Functional\BlockUiTest::testRouteProtection()

Tests that the enable/disable routes are protected from CSRF.

File

core/modules/block/tests/src/Functional/BlockUiTest.php, line 376

Class

BlockUiTest
Tests that the block configuration UI exists and stores data correctly.

Namespace

Drupal\Tests\block\Functional

Code

public function testRouteProtection() {

  // Get the first block generated in our setUp method.

  /** @var \Drupal\block\BlockInterface $block */
  $block = reset($this->blocks);

  // Ensure that the enable and disable routes are protected.
  $this
    ->drupalGet('admin/structure/block/manage/' . $block
    ->id() . '/disable');
  $this
    ->assertSession()
    ->statusCodeEquals(403);
  $this
    ->drupalGet('admin/structure/block/manage/' . $block
    ->id() . '/enable');
  $this
    ->assertSession()
    ->statusCodeEquals(403);
}