You are here

function TokenMenuTestCase::testMenuTokens in Token 6

Same name and namespace in other branches
  1. 7 token.test \TokenMenuTestCase::testMenuTokens()

File

./token.test, line 494
Tests for the token module.

Class

TokenMenuTestCase

Code

function testMenuTokens() {
  $root_link = array(
    'link_path' => 'root',
    'link_title' => 'Root link',
    'menu_name' => 'primary-links',
  );
  menu_link_save($root_link);

  // Add another link with the root link as the parent
  $parent_link = array(
    'link_path' => 'root/parent',
    'link_title' => 'Parent link',
    'menu_name' => 'primary-links',
    'plid' => $root_link['mlid'],
  );
  menu_link_save($parent_link);
  $node_link = array(
    'enabled' => TRUE,
    'link_title' => 'Node link',
    'plid' => $parent_link['mlid'],
    'customized' => 0,
  );
  $node = $this
    ->drupalCreateNode(array(
    'menu' => $node_link,
  ));

  // Test [node:menu] tokens.
  $tokens = array(
    'menu' => 'Primary links',
    'menu-raw' => 'Primary links',
    'menupath' => 'Root link/Parent link/Node link',
    'menupath-raw' => 'Root link/Parent link/Node link',
    'menu-link-title' => 'Node link',
    'menu-link-title-raw' => 'Node link',
    'menu-link-mlid' => $node->menu['mlid'],
    'menu-link-plid' => $node->menu['plid'],
    'menu-link-plid' => $parent_link['mlid'],
    'menu-link-parent-path' => 'root/parent',
    'menu-link-parent-path-raw' => 'root/parent',
  );
  $this
    ->assertTokens('node', $node, $tokens);

  // Reload the node which will not have $node->menu defined and re-test.
  $loaded_node = node_load($node->nid);

  // We have to reset the token static cache because tokens are cached by
  // node ID only and not if the node object has changed.
  $this
    ->assertTokens('node', $loaded_node, $tokens, array(
    'reset' => TRUE,
  ));

  // Regression test for http://drupal.org/node/1317926 to ensure the
  // original node object is not changed when calling menu_node_prepare().
  $this
    ->assertTrue(!isset($loaded_node->menu), t('The $node->menu property was not modified during token replacement.'), 'Regression');
}