Version 1
[yaffs-website] / web / modules / contrib / devel / src / Tests / DevelMenuLinksTest.php
1 <?php
2
3 namespace Drupal\devel\Tests;
4
5 use Drupal\Core\Url;
6 use Drupal\simpletest\WebTestBase;
7
8 /**
9  * Tests devel menu links.
10  *
11  * @group devel
12  */
13 class DevelMenuLinksTest extends WebTestBase {
14
15   /**
16    * Modules to enable.
17    *
18    * @var array
19    */
20   public static $modules = ['devel', 'block', 'devel_test'];
21
22   /**
23    * The user for tests.
24    *
25    * @var \Drupal\user\UserInterface
26    */
27   protected $develUser;
28
29   /**
30    * {@inheritdoc}
31    */
32   protected function setUp() {
33     parent::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
36     // properly.
37     $this->drupalPlaceBlock('system_menu_block:devel');
38     $this->drupalPlaceBlock('page_title_block');
39
40     $this->develUser = $this->drupalCreateUser(['access devel information', 'administer site configuration']);
41     $this->drupalLogin($this->develUser);
42   }
43
44   /**
45    * Tests CSFR protected links.
46    */
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);
53
54     // Ensure clear cache link works properly.
55     $this->assertLink('Cache clear');
56     $this->clickLink('Cache clear');
57     $this->assertText('Cache cleared.');
58
59     // Ensure run cron link works properly.
60     $this->assertLink('Run cron');
61     $this->clickLink('Run cron');
62     $this->assertText('Cron ran successfully.');
63
64     // Ensure CSRF protected links work properly after change session.
65     $this->drupalLogout();
66     $this->drupalLogin($this->develUser);
67
68     $this->assertLink('Cache clear');
69     $this->clickLink('Cache clear');
70     $this->assertText('Cache cleared.');
71
72     $this->assertLink('Run cron');
73     $this->clickLink('Run cron');
74     $this->assertText('Cron ran successfully.');
75   }
76
77   /**
78    * Tests redirect destination links.
79    */
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]);
85
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()]]);
90
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()]]);
95
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);
101
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);
107   }
108
109 }