function BlockUiTest::testRouteProtection

Same name and namespace in other branches
  1. 9 core/modules/block/tests/src/Functional/BlockUiTest.php \Drupal\Tests\block\Functional\BlockUiTest::testRouteProtection()
  2. 8.9.x core/modules/block/tests/src/Functional/BlockUiTest.php \Drupal\Tests\block\Functional\BlockUiTest::testRouteProtection()
  3. 10 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 372

Class

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

Namespace

Drupal\Tests\block\Functional

Code

public function testRouteProtection() : void {
    // 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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.