X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Ftoken%2Ftests%2Fsrc%2FKernel%2FBookTest.php;fp=web%2Fmodules%2Fcontrib%2Ftoken%2Ftests%2Fsrc%2FKernel%2FBookTest.php;h=67a13eecd65f9dd83fdebbbcefbcce88c71964fd;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/modules/contrib/token/tests/src/Kernel/BookTest.php b/web/modules/contrib/token/tests/src/Kernel/BookTest.php new file mode 100644 index 000000000..67a13eecd --- /dev/null +++ b/web/modules/contrib/token/tests/src/Kernel/BookTest.php @@ -0,0 +1,107 @@ +installEntitySchema('user'); + $this->installEntitySchema('node'); + $this->installSchema('book', array('book')); + $this->installSchema('node', array('node_access')); + $this->installConfig(array('node', 'book', 'field')); + } + + function testBookTokens() { + $book = Node::create([ + 'type' => 'book', + 'title' => 'Book Main Page', + 'book' => ['bid' => 'new'], + ]); + $book->save(); + + $page1 = Node::create([ + 'type' => 'book', + 'title' => '1st Page', + 'book' => ['bid' => $book->id(), 'pid' => $book->id()], + ]); + $page1->save(); + + $page2 = Node::create([ + 'type' => 'book', + 'title' => '2nd Page', + 'book' => ['bid' => $book->id(), 'pid' => $page1->id()], + ]); + $page2->save(); + + $book_title = $book->getTitle(); + + $tokens = [ + 'nid' => $book->id(), + 'title' => $book_title, + 'book:title' => $book_title, + 'book:root' => $book_title, + 'book:root:nid' => $book->id(), + 'book:root:title' => $book_title, + 'book:root:url' => Url::fromRoute('entity.node.canonical', ['node' => $book->id()], array('absolute' => TRUE))->toString(), + 'book:root:content-type' => 'Book page', + 'book:parent' => null, + 'book:parents' => null, + ]; + $this->assertTokens('node', array('node' => $book), $tokens); + + $tokens = [ + 'nid' => $page1->id(), + 'title' => $page1->getTitle(), + 'book:title' => $book_title, + 'book:root' => $book_title, + 'book:root:nid' => $book->id(), + 'book:root:title' => $book_title, + 'book:root:url' => Url::fromRoute('entity.node.canonical', ['node' => $book->id()], array('absolute' => TRUE))->toString(), + 'book:root:content-type' => 'Book page', + 'book:parent:nid' => $book->id(), + 'book:parent:title' => $book_title, + 'book:parent:url' => Url::fromRoute('entity.node.canonical', ['node' => $book->id()], array('absolute' => TRUE))->toString(), + 'book:parents:count' => 1, + 'book:parents:join:/' => $book_title, + ]; + $this->assertTokens('node', array('node' => $page1), $tokens); + + $tokens = [ + 'nid' => $page2->id(), + 'title' => $page2->getTitle(), + 'book:title' => $book_title, + 'book:root' => $book_title, + 'book:root:nid' => $book->id(), + 'book:root:title' => $book_title, + 'book:root:url' => Url::fromRoute('entity.node.canonical', ['node' => $book->id()], array('absolute' => TRUE))->toString(), + 'book:root:content-type' => 'Book page', + 'book:parent:nid' => $page1->id(), + 'book:parent:title' => $page1->getTitle(), + 'book:parent:url' => Url::fromRoute('entity.node.canonical', ['node' => $page1->id()], array('absolute' => TRUE))->toString(), + 'book:parents:count' => 2, + 'book:parents:join:/' => $book_title . '/' . $page1->getTitle(), + ]; + $this->assertTokens('node', array('node' => $page2), $tokens); + } +}