3 namespace Drupal\Tests\devel\Functional;
6 use Drupal\Tests\BrowserTestBase;
9 * Tests routes info pages and links.
13 class DevelRouteInfoTest extends BrowserTestBase {
18 public static $modules = ['devel', 'devel_test', 'block'];
21 * The user for the test.
23 * @var \Drupal\user\UserInterface
30 protected function setUp() {
33 $this->drupalPlaceBlock('system_menu_block:devel');
34 $this->drupalPlaceBlock('page_title_block');
36 $this->develUser = $this->drupalCreateUser(['access devel information']);
37 $this->drupalLogin($this->develUser);
43 public function testRouteList() {
44 // Ensures that the routes info link is present on the devel menu and that
45 // it points to the correct page.
47 $this->clickLink('Routes Info');
48 $this->assertSession()->statusCodeEquals(200);
49 $this->assertSession()->addressEquals('/devel/routes');
50 $this->assertSession()->pageTextContains('Routes');
52 $page = $this->getSession()->getPage();
54 // Ensures that the expected table headers are found.
55 /** @var $headers \Behat\Mink\Element\NodeElement[] */
56 $headers = $page->findAll('css', 'table.devel-route-list thead th');
57 $this->assertEquals(4, count($headers));
59 $expected_items = ['Route Name', 'Path', 'Allowed Methods', 'Operations'];
60 foreach ($headers as $key => $element) {
61 $this->assertSame($element->getText(), $expected_items[$key]);
64 // Ensures that all the routes are listed in the table.
65 $routes = \Drupal::service('router.route_provider')->getAllRoutes();
66 $rows = $page->findAll('css', 'table.devel-route-list tbody tr');
67 $this->assertEquals(count($routes), count($rows));
69 // Tests the presence of some (arbitrarily chosen) routes in the table.
72 'path' => '/<current>',
73 'methods' => ['GET', 'POST'],
77 'path' => '/user/login',
78 'methods' => ['GET', 'POST'],
81 'entity.user.canonical' => [
82 'path' => '/user/{user}',
83 'methods' => ['GET', 'POST'],
86 'entity.user.devel_load' => [
87 'path' => '/devel/user/{user}',
93 foreach ($expected_routes as $route_name => $expected) {
94 $row = $page->find('css', sprintf('table.devel-route-list tbody tr:contains("%s")', $route_name));
95 $this->assertNotNull($row);
97 /** @var $cells \Behat\Mink\Element\NodeElement[] */
98 $cells = $row->findAll('css', 'td');
99 $this->assertEquals(4, count($cells));
101 $cell_route_name = $cells[0];
102 $this->assertEquals($route_name, $cell_route_name->getText());
103 $this->assertTrue($cell_route_name->hasClass('table-filter-text-source'));
105 $cell_path = $cells[1];
106 $this->assertEquals($expected['path'], $cell_path->getText());
107 $this->assertTrue($cell_path->hasClass('table-filter-text-source'));
109 $cell_methods = $cells[2];
110 $this->assertEquals(implode('', $expected['methods']), $cell_methods->getText());
112 $cell_operations = $cells[3];
113 $actual_href = $cell_operations->findLink('Devel')->getAttribute('href');
114 if ($expected['dynamic']) {
115 $parameters = ['query' => ['route_name' => $route_name]];
118 $parameters = ['query' => ['path' => $expected['path']]];
120 $expected_href = Url::fromRoute('devel.route_info.item', [], $parameters)->toString();
121 $this->assertEquals($expected_href, $actual_href);
124 // Ensures that the page is accessible only to the users with the adequate
126 $this->drupalLogout();
127 $this->drupalGet('devel/routes');
128 $this->assertSession()->statusCodeEquals(403);
132 * Tests route detail page.
134 public function testRouteDetail() {
135 $expected_title = 'Route detail';
136 $xpath_warning_messages = '//div[contains(@class, "messages--warning")]';
138 // Ensures that devel route detail link in the menu works properly.
139 $url = $this->develUser->toUrl();
140 $path = '/' . $url->getInternalPath();
142 $this->drupalGet($url);
143 $this->clickLink('Current route info');
144 $this->assertSession()->statusCodeEquals(200);
145 $this->assertSession()->pageTextContains($expected_title);
146 $expected_url = Url::fromRoute('devel.route_info.item', [], ['query' => ['path' => $path]]);
147 $this->assertSession()->addressEquals($expected_url);
148 $this->assertSession()->elementNotExists('xpath', $xpath_warning_messages);
150 // Ensures that devel route detail works properly even when dynamic cache
152 $url = Url::fromRoute('devel.simple_page');
153 $path = '/' . $url->getInternalPath();
155 $this->drupalGet($url);
156 $this->clickLink('Current route info');
157 $this->assertSession()->statusCodeEquals(200);
158 $this->assertSession()->pageTextContains($expected_title);
159 $expected_url = Url::fromRoute('devel.route_info.item', [], ['query' => ['path' => $path]]);
160 $this->assertSession()->addressEquals($expected_url);
161 $this->assertSession()->elementNotExists('xpath', $xpath_warning_messages);
163 // Ensures that if a non existent path is passed as input, a warning
165 $this->drupalGet('devel/routes/item', ['query' => ['path' => '/undefined']]);
166 $this->assertSession()->statusCodeEquals(200);
167 $this->assertSession()->pageTextContains($expected_title);
168 $this->assertSession()->elementExists('xpath', $xpath_warning_messages);
170 // Ensures that the route detail page works properly when a valid route
171 // name input is passed.
172 $this->drupalGet('devel/routes/item', ['query' => ['route_name' => 'devel.simple_page']]);
173 $this->assertSession()->statusCodeEquals(200);
174 $this->assertSession()->pageTextContains($expected_title);
175 $this->assertSession()->elementNotExists('xpath', $xpath_warning_messages);
177 // Ensures that if a non existent route name is passed as input a warning
179 $this->drupalGet('devel/routes/item', ['query' => ['route_name' => 'not.exists']]);
180 $this->assertSession()->statusCodeEquals(200);
181 $this->assertSession()->pageTextContains($expected_title);
182 $this->assertSession()->elementExists('xpath', $xpath_warning_messages);
184 // Ensures that if no 'path' nor 'name' query string is passed as input,
185 // devel route detail page does not return errors.
186 $this->drupalGet('devel/routes/item');
187 $this->assertSession()->statusCodeEquals(200);
188 $this->assertSession()->pageTextContains($expected_title);
190 // Ensures that the page is accessible ony to the users with the adequate
192 $this->drupalLogout();
193 $this->drupalGet('devel/routes/item');
194 $this->assertSession()->statusCodeEquals(403);