function DevelMenuLinksTest::testCsrfProtectedLinks

Same name in other branches
  1. 5.x tests/src/Functional/DevelMenuLinksTest.php \Drupal\Tests\devel\Functional\DevelMenuLinksTest::testCsrfProtectedLinks()

Tests CSFR protected links.

File

tests/src/Functional/DevelMenuLinksTest.php, line 30

Class

DevelMenuLinksTest
Tests devel menu links.

Namespace

Drupal\Tests\devel\Functional

Code

public function testCsrfProtectedLinks() {
    // Ensure CSRF link are not accessible directly.
    $this->drupalGet('devel/run-cron');
    $this->assertSession()
        ->statusCodeEquals(403);
    $this->drupalGet('devel/cache/clear');
    $this->assertSession()
        ->statusCodeEquals(403);
    // Ensure clear cache link works properly.
    $this->assertSession()
        ->linkExists('Cache clear');
    $this->clickLink('Cache clear');
    $this->assertSession()
        ->pageTextContains('Cache cleared.');
    // Ensure run cron link works properly.
    $this->assertSession()
        ->linkExists('Run cron');
    $this->clickLink('Run cron');
    $this->assertSession()
        ->pageTextContains('Cron ran successfully.');
    // Ensure CSRF protected links work properly after change session.
    $this->drupalLogout();
    $this->drupalLogin($this->adminUser);
    $this->assertSession()
        ->linkExists('Cache clear');
    $this->clickLink('Cache clear');
    $this->assertSession()
        ->pageTextContains('Cache cleared.');
    $this->assertSession()
        ->linkExists('Run cron');
    $this->clickLink('Run cron');
    $this->assertSession()
        ->pageTextContains('Cron ran successfully.');
}