You are here

public function DevelMenuLinksTest::testCsrfProtectedLinks in Devel 8.3

Same name and namespace in other branches
  1. 8 tests/src/Functional/DevelMenuLinksTest.php \Drupal\Tests\devel\Functional\DevelMenuLinksTest::testCsrfProtectedLinks()
  2. 8.2 tests/src/Functional/DevelMenuLinksTest.php \Drupal\Tests\devel\Functional\DevelMenuLinksTest::testCsrfProtectedLinks()
  3. 4.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.');
}