You are here

public function DevelRouteInfoTest::testRouteDetail in Devel 4.x

Same name and namespace in other branches
  1. 8.3 tests/src/Functional/DevelRouteInfoTest.php \Drupal\Tests\devel\Functional\DevelRouteInfoTest::testRouteDetail()
  2. 8 tests/src/Functional/DevelRouteInfoTest.php \Drupal\Tests\devel\Functional\DevelRouteInfoTest::testRouteDetail()
  3. 8.2 tests/src/Functional/DevelRouteInfoTest.php \Drupal\Tests\devel\Functional\DevelRouteInfoTest::testRouteDetail()

Tests route detail page.

File

tests/src/Functional/DevelRouteInfoTest.php, line 118

Class

DevelRouteInfoTest
Tests routes info pages and links.

Namespace

Drupal\Tests\devel\Functional

Code

public function testRouteDetail() {
  $expected_title = 'Route detail';
  $xpath_warning_messages = '//div[@aria-label="Warning message"]';

  // Ensures that devel route detail link in the menu works properly.
  $url = $this->develUser
    ->toUrl();
  $path = '/' . $url
    ->getInternalPath();
  $this
    ->drupalGet($url);
  $this
    ->clickLink('Current route info');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->pageTextContains($expected_title);
  $expected_url = Url::fromRoute('devel.route_info.item', [], [
    'query' => [
      'path' => $path,
    ],
  ]);
  $this
    ->assertSession()
    ->addressEquals($expected_url);
  $this
    ->assertSession()
    ->elementNotExists('xpath', $xpath_warning_messages);

  // Ensures that devel route detail works properly even when dynamic cache
  // is enabled.
  $url = Url::fromRoute('devel.simple_page');
  $path = '/' . $url
    ->getInternalPath();
  $this
    ->drupalGet($url);
  $this
    ->clickLink('Current route info');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->pageTextContains($expected_title);
  $expected_url = Url::fromRoute('devel.route_info.item', [], [
    'query' => [
      'path' => $path,
    ],
  ]);
  $this
    ->assertSession()
    ->addressEquals($expected_url);
  $this
    ->assertSession()
    ->elementNotExists('xpath', $xpath_warning_messages);

  // Ensures that if a non existent path is passed as input, a warning
  // message is shown.
  $this
    ->drupalGet('devel/routes/item', [
    'query' => [
      'path' => '/undefined',
    ],
  ]);
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->pageTextContains($expected_title);
  $this
    ->assertSession()
    ->elementExists('xpath', $xpath_warning_messages);

  // Ensures that the route detail page works properly when a valid route
  // name input is passed.
  $this
    ->drupalGet('devel/routes/item', [
    'query' => [
      'route_name' => 'devel.simple_page',
    ],
  ]);
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->pageTextContains($expected_title);
  $this
    ->assertSession()
    ->elementNotExists('xpath', $xpath_warning_messages);

  // Ensures that if a non existent route name is passed as input a warning
  // message is shown.
  $this
    ->drupalGet('devel/routes/item', [
    'query' => [
      'route_name' => 'not.exists',
    ],
  ]);
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->pageTextContains($expected_title);
  $this
    ->assertSession()
    ->elementExists('xpath', $xpath_warning_messages);

  // Ensures that if no 'path' nor 'name' query string is passed as input,
  // devel route detail page does not return errors.
  $this
    ->drupalGet('devel/routes/item');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->pageTextContains($expected_title);

  // Ensures that the page is accessible ony to the users with the adequate
  // permissions.
  $this
    ->drupalLogout();
  $this
    ->drupalGet('devel/routes/item');
  $this
    ->assertSession()
    ->statusCodeEquals(403);
}