AutocompleteTest.php in Token 8
File
tests/src/Functional/Tree/AutocompleteTest.php
View source
<?php
namespace Drupal\Tests\token\Functional\Tree;
use Drupal\Component\Serialization\Json;
use Drupal\Tests\token\Functional\TokenTestBase;
class AutocompleteTest extends TokenTestBase {
public static $modules = [
'node',
];
public function testNodeAutocomplete() {
$url_prefix = "token/autocomplete/node/";
$url = $url_prefix . 'Title of [nod';
$response = Json::decode($this
->drupalGet($url, [
'query' => [
'_format' => 'json',
],
]));
$this
->assertArrayHasKey('[node:nid]', $response);
$this
->assertArrayHasKey('[node:author]', $response);
$this
->assertArrayHasKey('[node:url]', $response);
$this
->assertArrayHasKey('[node:url:', $response);
$url = $url_prefix . 'Title of [node:url:';
$response = Json::decode($this
->drupalGet($url, [
'query' => [
'_format' => 'json',
],
]));
$this
->assertArrayHasKey('[node:url:path]', $response);
$this
->assertArrayHasKey('[node:url:absolute]', $response);
}
public function testUserAutocomplete() {
$url_prefix = "token/autocomplete/user/";
$url = $url_prefix . 'Name of the [us';
$response = Json::decode($this
->drupalGet($url, [
'query' => [
'_format' => 'json',
],
]));
$this
->assertArrayHasKey('[user:uid]', $response);
$this
->assertArrayHasKey('[user:original]', $response);
$this
->assertArrayHasKey('[user:url]', $response);
$this
->assertArrayHasKey('[user:url:', $response);
$url = $url_prefix . 'Title of [user:original:';
$response = Json::decode($this
->drupalGet($url, [
'query' => [
'_format' => 'json',
],
]));
$this
->assertArrayHasKey('[user:original:uid]', $response);
}
}