function TokenBookTestCase::testBookTokens in Token 6
File
- ./
token.test, line 568 - Tests for the token module.
Class
Code
function testBookTokens() {
// Add a non-book node.
$non_book_node = $this
->drupalCreateNode(array(
'type' => 'book',
));
$tokens = array(
'book' => '',
'book-raw' => '',
'book_id' => '',
'bookpath' => '',
'bookpath-raw' => '',
);
$this
->assertTokens('node', $non_book_node, $tokens);
// Add a root book page.
$parent_node = $this
->drupalCreateNode(array(
'type' => 'book',
'title' => 'Root',
'book' => array(
'bid' => 'new',
) + _book_link_defaults('new'),
));
$tokens = array(
'book' => 'Root',
'book-raw' => 'Root',
'book_id' => $parent_node->book['bid'],
'bookpath' => '',
'bookpath-raw' => '',
// Check that even those book menu links have been created for this node,
// that the menu links still return nothing.
'menu' => '',
'menupath' => '',
'menu-link-title' => '',
'menu-link-title-raw' => '',
'menu-link-mlid' => '',
'menu-link-plid' => '',
'menu-link-parent-path' => '',
);
$this
->assertTokens('node', $parent_node, $tokens);
// Add a first child page.
$child_node1 = $this
->drupalCreateNode(array(
'type' => 'book',
'title' => 'Sub page1',
'book' => array(
'bid' => $parent_node->book['bid'],
'plid' => $parent_node->book['mlid'],
) + _book_link_defaults('new'),
));
$tokens = array(
'book' => 'Root',
'book-raw' => 'Root',
'book_id' => $parent_node->book['bid'],
'bookpath' => 'Root',
'bookpath-raw' => 'Root',
);
$this
->assertTokens('node', $child_node1, $tokens);
// Add a second child page.
$child_node2 = $this
->drupalCreateNode(array(
'type' => 'book',
'title' => 'Sub page2',
'book' => array(
'bid' => $parent_node->book['bid'],
'plid' => $parent_node->book['mlid'],
) + _book_link_defaults('new'),
));
$tokens = array(
'book' => 'Root',
'book-raw' => 'Root',
'book_id' => $parent_node->book['bid'],
'bookpath' => 'Root',
'bookpath-raw' => 'Root',
);
$this
->assertTokens('node', $child_node2, $tokens);
// Add a child page on an existing child page.
$sub_child_node1 = $this
->drupalCreateNode(array(
'type' => 'page',
'title' => 'Sub-sub Page1',
'book' => array(
'bid' => $parent_node->book['bid'],
'plid' => $child_node1->book['mlid'],
) + _book_link_defaults('new'),
));
$tokens = array(
'book' => 'Root',
'book-raw' => 'Root',
'book_id' => $parent_node->book['bid'],
'bookpath' => 'Root/Sub page1',
'bookpath-raw' => 'Root/Sub page1',
);
$this
->assertTokens('node', $sub_child_node1, $tokens);
}