You are here

function VoteUpDownTestCase::testVoteUp in Vote Up/Down 6

Check the permissions for voting only up

File

tests/vote_up_down.test, line 254
Test file for Vote Up/Down.

Class

VoteUpDownTestCase

Code

function testVoteUp() {

  // Enable Vote Up/Down for Story node types. Everything else should be
  // default settings.
  $this
    ->drupalLogin($this->admin_user);
  $edit = array(
    'vote_up_down_node_types[story]' => TRUE,
  );
  $this
    ->drupalPost('admin/settings/voteupdown', $edit, 'Save configuration');
  $this
    ->assertText('The configuration options have been saved.');
  $this
    ->assertText('Vote Up/Down');

  // Create another user to test the vote up only permission
  $this->voteup_user = $this
    ->drupalCreateUser(array(
    'access vote up/down statistics',
    'use vote up',
    'view up/down votes',
    'create story content',
  ));

  // Login
  $this
    ->drupalLogin($this->voteup_user);

  //Create another story
  $node = array(
    'title' => $this
      ->randomName(20, 'NODE_'),
    'body' => $this
      ->randomName(20, 'BODY_'),
  );
  $this
    ->drupalPost('node/add/story', $node, 'Save');
  $this
    ->assertText("Story {$node['title']} has been created.");

  // Check the presence of the widget
  $this
    ->assertText('0 points');
  $this
    ->assertRaw('<div class="vote-up-down-widget">');
  $node_url = $this
    ->getUrl();
  $this
    ->assertText('Voting details', 'Voting details tab is on node pages');

  // Use the url to find the NID, and then check for the <span> tag that the
  // JavaScript uses to update the points.
  preg_match('#node/([0-9]*)$#', $node_url, $matches);
  $nid = $matches[1];
  $this
    ->assertRaw('<span id="vote_points_' . $nid . '" class="vote-points">', 'Labeled SPAN tag found');

  // Check empty Voting details about this node.
  $this
    ->clickLink('Voting details');

  // Bug #360139
  $this
    ->assertNoRaw('<td>', 'Voting Details Records found on new Story node');

  // Back to the node page and check that the user can only vote up and cannot vote down
  $this
    ->drupalGet($node_url);
  $this
    ->assertNoRaw('<span title="You have no privileges to vote up." class="up-inact" id="vote_up_1"/>', t('Make sure the vote up is not disabled.'));
  $this
    ->assertRaw('<span id="vote_down_1" class="down-inact" title="You have no privileges to vote down."></span>', t('Make sure the vote down is disabled.'));

  // Cast a vote, and make sure the score was updated.
  $this
    ->drupalGet($node_url);
  $this
    ->castVote(TRUE);
  $this
    ->assertText('1 point');
  $this
    ->clickLink('Voting details');
  $this
    ->assertText($this->voteup_user->name);
  $this
    ->assertRaw('<td>1</td>');
}