You are here

function VoteUpDownTestCase::castVote in Vote Up/Down 6

Execute a (non-AJAX) vote from the current node.

Parameters

$up: If TRUE vote-up, otherwise vote-down.

TODO: support multi-node pages, using xpath? TODO: better error messages.

3 calls to VoteUpDownTestCase::castVote()
VoteUpDownTestCase::testBasicOperation in tests/vote_up_down.test
Ensure that the optional fields are truly optional.
VoteUpDownTestCase::testVoteDown in tests/vote_up_down.test
Check the permissions for voting only down
VoteUpDownTestCase::testVoteUp in tests/vote_up_down.test
Check the permissions for voting only up

File

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

Class

VoteUpDownTestCase

Code

function castVote($up) {

  // The non-AJAX version uses a hyperlink with no inner text, so we can't
  // just use clickLink().  We find the domain-relative URL using xpath, then
  // prepend $base_root to get an absolute URL.
  if ($up) {
    $inact_urls = $this
      ->xpath('//a[@class="vote-up-inact"]');
    $act_urls = $this
      ->xpath('//a[@class="vote-up-act"]');
  }
  else {
    $inact_urls = $this
      ->xpath('//a[@class="vote-down-inact"]');
    $act_urls = $this
      ->xpath('//a[@class="vote-down-act"]');
  }
  $this
    ->assertEqual(count($inact_urls), 1, 'One inactive vote widget found');
  if (count($inact_urls) != 1) {

    // If we couldn't find the inactive widget we need to click on, try
    // looking for the active version. This would normally mean that we've
    // already voted (in this direction) on this node.
    $this
      ->assertEqual(count($act_urls), 0, 'No active vote widget found');
    return;

    // no point in continuing
  }
  $this
    ->assertTrue(strpos($inact_urls[0]['href'], base_path()) === 0, 'Vote Up URL starts with base_path()');

  // We can't use drupalGet() because it messes up the URL. This is copied
  // from that method, with just the URL parameter changed. We don't explictly
  // handle redirects here, because curl did it for us.
  global $base_root;
  $out = $this
    ->curlExec(array(
    CURLOPT_HTTPGET => TRUE,
    CURLOPT_URL => $base_root . $inact_urls[0]['href'],
  ));
  $this
    ->refreshVariables();
}