DevelMenuLinksTest.php in Devel 4.x
File
tests/src/Functional/DevelMenuLinksTest.php
View source
<?php
namespace Drupal\Tests\devel\Functional;
use Drupal\Core\Url;
class DevelMenuLinksTest extends DevelBrowserTestBase {
protected function setUp() {
parent::setUp();
$this
->drupalPlaceBlock('system_menu_block:devel');
$this
->drupalPlaceBlock('page_title_block');
$this
->drupalLogin($this->adminUser);
}
public function testCsrfProtectedLinks() {
$this
->drupalGet('devel/run-cron');
$this
->assertSession()
->statusCodeEquals(403);
$this
->drupalGet('devel/cache/clear');
$this
->assertSession()
->statusCodeEquals(403);
$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.');
$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.');
}
public function testRedirectDestinationLinks() {
$url = Url::fromRoute('devel.simple_page');
$destination = Url::fromRoute('devel.simple_page', [], [
'absolute' => FALSE,
]);
$this
->drupalGet($url);
$this
->assertSession()
->linkExists('Reinstall Modules');
$this
->clickLink('Reinstall Modules');
$this
->assertSession()
->addressEquals('devel/reinstall', [
'query' => [
'destination' => $destination
->toString(),
],
]);
$this
->drupalGet($url);
$this
->assertSession()
->linkExists('Rebuild Menu');
$this
->clickLink('Rebuild Menu');
$this
->assertSession()
->addressEquals('devel/menu/reset', [
'query' => [
'destination' => $destination
->toString(),
],
]);
$this
->drupalGet($url);
$this
->assertSession()
->linkExists('Cache clear');
$this
->clickLink('Cache clear');
$this
->assertSession()
->pageTextContains('Cache cleared.');
$this
->assertSession()
->addressEquals($url);
$this
->drupalGet($url);
$this
->assertSession()
->linkExists('Run cron');
$this
->clickLink('Run cron');
$this
->assertSession()
->pageTextContains('Cron ran successfully.');
$this
->assertSession()
->addressEquals($url);
}
}