You are here

function FlagEntityTokensTestCase::testNodeFlagToken in Flag 7.3

Test tokens on nodes.

File

tests/flag.test, line 513
Tests for the Flag module.

Class

FlagEntityTokensTestCase
Tokens we provide on generic entities.

Code

function testNodeFlagToken() {

  // Create a flag on article nodes.
  $flag_data = array(
    'entity_type' => 'node',
    'name' => 'node_flag',
    'title' => 'Node Flag',
    'global' => 0,
    'types' => array(
      0 => 'article',
    ),
    'flag_short' => 'Flag this item',
    'flag_long' => '',
    'flag_message' => '',
    'unflag_short' => 'Unflag this item',
    'unflag_long' => '',
    'unflag_message' => '',
    'unflag_denied_text' => 'You may not unflag this item',
    'link_type' => 'normal',
    'weight' => 0,
    // Show the flag on the form.
    'show_on_form' => 1,
    'access_author' => '',
    'show_contextual_link' => 0,
    'show_in_links' => array(
      'full' => 1,
      'teaser' => 1,
    ),
    'i18n' => 0,
    'api_version' => 3,
  );
  $flag = $this
    ->createFlag($flag_data);

  // Create a node to flag.
  $node = (object) array(
    'type' => 'article',
    'title' => $this
      ->randomName(),
  );
  node_save($node);

  // Flag it by several users.
  $flag_user_1 = $this
    ->drupalCreateUser(array(
    'flag node_flag',
  ));

  // Flag the node as the user.
  $flag = flag_get_flag('node_flag');
  $flag
    ->flag('flag', $node->nid, $flag_user_1);
  $flag_user_2 = $this
    ->drupalCreateUser(array(
    'flag node_flag',
  ));

  // Flag the node as the user.
  $flag
    ->flag('flag', $node->nid, $flag_user_2);
  $text = '[node:flag-node-flag-count]';
  $replaced_text = token_replace($text, array(
    'node' => $node,
  ));
  $this
    ->assertEqual($replaced_text, 2, "The flag count token for the node is correct.");
}