3 namespace Drupal\Tests\token\Kernel;
5 use Drupal\node\Entity\Node;
9 * Test the book tokens.
13 class BookTest extends KernelTestBase {
20 public static $modules = ['user', 'field', 'filter', 'text', 'node', 'book'];
25 protected function setUp() {
28 $this->installEntitySchema('user');
29 $this->installEntitySchema('node');
30 $this->installSchema('book', ['book']);
31 $this->installSchema('node', ['node_access']);
32 $this->installConfig(['node', 'book', 'field']);
35 function testBookTokens() {
36 $book = Node::create([
38 'title' => 'Book Main Page',
39 'book' => ['bid' => 'new'],
43 $page1 = Node::create([
45 'title' => '1st Page',
46 'book' => ['bid' => $book->id(), 'pid' => $book->id()],
50 $page2 = Node::create([
52 'title' => '2nd Page',
53 'book' => ['bid' => $book->id(), 'pid' => $page1->id()],
57 $book_title = $book->getTitle();
61 'title' => $book_title,
62 'book:title' => $book_title,
63 'book:root' => $book_title,
64 'book:root:nid' => $book->id(),
65 'book:root:title' => $book_title,
66 'book:root:url' => Url::fromRoute('entity.node.canonical', ['node' => $book->id()], ['absolute' => TRUE])->toString(),
67 'book:root:content-type' => 'Book page',
68 'book:parent' => null,
69 'book:parents' => null,
71 $this->assertTokens('node', ['node' => $book], $tokens);
74 'nid' => $page1->id(),
75 'title' => $page1->getTitle(),
76 'book:title' => $book_title,
77 'book:root' => $book_title,
78 'book:root:nid' => $book->id(),
79 'book:root:title' => $book_title,
80 'book:root:url' => Url::fromRoute('entity.node.canonical', ['node' => $book->id()], ['absolute' => TRUE])->toString(),
81 'book:root:content-type' => 'Book page',
82 'book:parent:nid' => $book->id(),
83 'book:parent:title' => $book_title,
84 'book:parent:url' => Url::fromRoute('entity.node.canonical', ['node' => $book->id()], ['absolute' => TRUE])->toString(),
85 'book:parents:count' => 1,
86 'book:parents:join:/' => $book_title,
88 $this->assertTokens('node', ['node' => $page1], $tokens);
91 'nid' => $page2->id(),
92 'title' => $page2->getTitle(),
93 'book:title' => $book_title,
94 'book:root' => $book_title,
95 'book:root:nid' => $book->id(),
96 'book:root:title' => $book_title,
97 'book:root:url' => Url::fromRoute('entity.node.canonical', ['node' => $book->id()], ['absolute' => TRUE])->toString(),
98 'book:root:content-type' => 'Book page',
99 'book:parent:nid' => $page1->id(),
100 'book:parent:title' => $page1->getTitle(),
101 'book:parent:url' => Url::fromRoute('entity.node.canonical', ['node' => $page1->id()], ['absolute' => TRUE])->toString(),
102 'book:parents:count' => 2,
103 'book:parents:join:/' => $book_title . '/' . $page1->getTitle(),
105 $this->assertTokens('node', ['node' => $page2], $tokens);