DevelMenuLinksTest.php in Devel 8.2
File
tests/src/Functional/DevelMenuLinksTest.php
View source
<?php
namespace Drupal\Tests\devel\Functional;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
class DevelMenuLinksTest extends BrowserTestBase {
public static $modules = [
'devel',
'block',
'devel_test',
];
protected $develUser;
protected function setUp() {
parent::setUp();
$this
->drupalPlaceBlock('system_menu_block:devel');
$this
->drupalPlaceBlock('page_title_block');
$this->develUser = $this
->drupalCreateUser([
'access devel information',
'administer site configuration',
]);
$this
->drupalLogin($this->develUser);
}
public function testCsrfProtectedLinks() {
$this
->drupalGet('devel/run-cron');
$this
->assertResponse(403);
$this
->drupalGet('devel/cache/clear');
$this
->assertResponse(403);
$this
->assertLink('Cache clear');
$this
->clickLink('Cache clear');
$this
->assertText('Cache cleared.');
$this
->assertLink('Run cron');
$this
->clickLink('Run cron');
$this
->assertText('Cron ran successfully.');
$this
->drupalLogout();
$this
->drupalLogin($this->develUser);
$this
->assertLink('Cache clear');
$this
->clickLink('Cache clear');
$this
->assertText('Cache cleared.');
$this
->assertLink('Run cron');
$this
->clickLink('Run cron');
$this
->assertText('Cron ran successfully.');
}
public function testRedirectDestinationLinks() {
$url = Url::fromRoute('devel.simple_page');
$destination = Url::fromRoute('devel.simple_page', [], [
'absolute' => FALSE,
]);
$this
->drupalGet($url);
$this
->assertLink(t('Reinstall Modules'));
$this
->clickLink(t('Reinstall Modules'));
$this
->assertUrl('devel/reinstall', [
'query' => [
'destination' => $destination
->toString(),
],
]);
$this
->drupalGet($url);
$this
->assertLink(t('Rebuild Menu'));
$this
->clickLink(t('Rebuild Menu'));
$this
->assertUrl('devel/menu/reset', [
'query' => [
'destination' => $destination
->toString(),
],
]);
$this
->drupalGet($url);
$this
->assertLink(t('Cache clear'));
$this
->clickLink(t('Cache clear'));
$this
->assertText('Cache cleared.');
$this
->assertUrl($url);
$this
->drupalGet($url);
$this
->assertLink(t('Run cron'));
$this
->clickLink(t('Run cron'));
$this
->assertText(t('Cron ran successfully.'));
$this
->assertUrl($url);
}
}