You are here

protected function TreeTest::getTokenTreeUrl in Token 8

Get the URL for the token tree based on the specified options.

The token tree route's URL requires CSRF and cannot be generated in the test code. The CSRF token generated using the test runner's session is different from the session inside the test environment. This is why the link has to be generated inside the environment.

This function calls a page in token_module_test module which generates the link and the token. This then replaces the options query parameter with the specified options.

The page also uses a title callback to set title to a render array, which allows us to test if [current-page:title] works properly.

Parameters

array $options: The options for the token tree browser.

Return value

string The complete URL of the token tree browser with the CSRF token.

4 calls to TreeTest::getTokenTreeUrl()
TreeTest::testAllTokens in tests/src/Functional/Tree/TreeTest.php
Test various tokens that are possible on the site.
TreeTest::testGlobalTokens in tests/src/Functional/Tree/TreeTest.php
Test various tokens that are possible on the site.
TreeTest::testNodeTokens in tests/src/Functional/Tree/TreeTest.php
Tests if the token browser displays the node tokens.
TreeTest::testUserTokens in tests/src/Functional/Tree/TreeTest.php
Tests if the token browser displays the user tokens.

File

tests/src/Functional/Tree/TreeTest.php, line 137

Class

TreeTest
Tests token tree page.

Namespace

Drupal\Tests\token\Functional\Tree

Code

protected function getTokenTreeUrl($options = []) {
  $this
    ->drupalGet('token_module_test/browse');
  $this
    ->assertSession()
    ->titleEquals('Available Tokens | Drupal');
  $links = $this
    ->xpath('//a[contains(@href, :href)]/@href', [
    ':href' => 'token/tree',
  ]);
  $link = $this
    ->getAbsoluteUrl(current($links)
    ->getText());
  if (!empty($options)) {
    $options = Json::encode($options);
    $link = str_replace('options=%5B%5D', 'options=' . urlencode($options), $link);
  }
  return $link;
}