3 namespace Drupal\devel\Tests;
6 use Drupal\simpletest\WebTestBase;
9 * Tests devel menu links.
13 class DevelMenuLinksTest extends WebTestBase {
20 public static $modules = ['devel', 'block', 'devel_test'];
25 * @var \Drupal\user\UserInterface
32 protected function setUp() {
34 // Devel links currently appears only in the devel menu.
35 // Place the devel menu block so we can ensure that these link works
37 $this->drupalPlaceBlock('system_menu_block:devel');
38 $this->drupalPlaceBlock('page_title_block');
40 $this->develUser = $this->drupalCreateUser(['access devel information', 'administer site configuration']);
41 $this->drupalLogin($this->develUser);
45 * Tests CSFR protected links.
47 public function testCsrfProtectedLinks() {
48 // Ensure CSRF link are not accessible directly.
49 $this->drupalGet('devel/run-cron');
50 $this->assertResponse(403);
51 $this->drupalGet('devel/cache/clear');
52 $this->assertResponse(403);
54 // Ensure clear cache link works properly.
55 $this->assertLink('Cache clear');
56 $this->clickLink('Cache clear');
57 $this->assertText('Cache cleared.');
59 // Ensure run cron link works properly.
60 $this->assertLink('Run cron');
61 $this->clickLink('Run cron');
62 $this->assertText('Cron ran successfully.');
64 // Ensure CSRF protected links work properly after change session.
65 $this->drupalLogout();
66 $this->drupalLogin($this->develUser);
68 $this->assertLink('Cache clear');
69 $this->clickLink('Cache clear');
70 $this->assertText('Cache cleared.');
72 $this->assertLink('Run cron');
73 $this->clickLink('Run cron');
74 $this->assertText('Cron ran successfully.');
78 * Tests redirect destination links.
80 public function testRedirectDestinationLinks() {
81 // By default, in the testing profile, front page is the user canonical URI.
82 // For better testing do not use the default frontpage.
83 $url = Url::fromRoute('devel.simple_page');
84 $destination = Url::fromRoute('devel.simple_page', [], ['absolute' => FALSE]);
86 $this->drupalGet($url);
87 $this->assertLink(t('Reinstall Modules'));
88 $this->clickLink(t('Reinstall Modules'));
89 $this->assertUrl('devel/reinstall', ['query' => ['destination' => $destination->toString()]]);
91 $this->drupalGet($url);
92 $this->assertLink(t('Rebuild Menu'));
93 $this->clickLink(t('Rebuild Menu'));
94 $this->assertUrl('devel/menu/reset', ['query' => ['destination' => $destination->toString()]]);
96 $this->drupalGet($url);
97 $this->assertLink(t('Cache clear'));
98 $this->clickLink(t('Cache clear'));
99 $this->assertText('Cache cleared.');
100 $this->assertUrl($url);
102 $this->drupalGet($url);
103 $this->assertLink(t('Run cron'));
104 $this->clickLink(t('Run cron'));
105 $this->assertText(t('Cron ran successfully.'));
106 $this->assertUrl($url);