You are here

function VudWebTestCase::castVote in Vote Up/Down 7

Same name and namespace in other branches
  1. 6.3 vud.test \VudWebTestCase::castVote()
  2. 6.2 vud.test \VudWebTestCase::castVote()
  3. 7.2 vud.test \VudWebTestCase::castVote()

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

Parameters

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

File

./vud.test, line 74
Test file for Vote Up/Down.

Class

VudWebTestCase
TODO test casting vote TODO test changing voting api tag after casting votes, and see if votes change TODO test vote reset

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();
}