You are here

function FlagAccessFormTestCase::testFlagAccessGlobalNone in Flag 7.3

Test scenarios with no access to a global flag.

File

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

Class

FlagAccessFormTestCase
Access to flags using the entity forms.

Code

function testFlagAccessGlobalNone() {

  // Create a global flag on article nodes.
  $flag_data = array(
    'entity_type' => 'node',
    'name' => 'global_flag',
    'title' => 'Global Flag',
    'global' => 1,
    '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 test user who can't us this flag, but can create nodes.
  $no_flag_user = $this
    ->drupalCreateUser(array(
    'create article content',
  ));
  $this
    ->drupalLogin($no_flag_user);
  $this
    ->drupalGet('node/add/article');

  // Check that the flag form element cannot be seen.
  $this
    ->assertNoText('Flag this item', t('Flag form element was not found.'));

  // Have the user create a node.
  $edit = array(
    'title' => 'node 1',
  );
  $this
    ->drupalPost('node/add/article', $edit, t('Save'));
  $node = $this
    ->drupalGetNodeByTitle($edit["title"]);

  // Check the new node has not been flagged.
  $this
    ->assertFalse($flag
    ->is_flagged($node->nid), t('New node is not flagged.'));

  // Now set the variable so that the flag is set by default on new nodes.
  variable_set('flag_' . $flag->name . '_default_' . 'article', 1);

  // Create another new node.
  $edit = array(
    'title' => 'node 2',
  );
  $this
    ->drupalPost('node/add/article', $edit, t('Save'));
  $node = $this
    ->drupalGetNodeByTitle($edit["title"]);

  // Check the new node has been flagged, despite the user not having access
  // to the flag.
  $this
    ->assertTrue($flag
    ->is_flagged($node->nid), t('New node is flagged.'));
}