vud.test in Vote Up/Down 7
Same filename and directory in other branches
Test file for Vote Up/Down.
File
vud.testView source
<?php
/**
* @file
* Test file for Vote Up/Down.
*/
/**
* TODO test casting vote
* TODO test changing voting api tag after casting votes, and see if votes change
* TODO test vote reset
*/
class VudWebTestCase extends DrupalWebTestCase {
/**
* Implementation of getInfo().
*/
public static function getInfo() {
return array(
'name' => t('Vote Up/Down'),
'description' => t('Functional tests for Vote Up/Down'),
'group' => t('Vote Up/down'),
);
}
/**
* Implementation of setUp().
*/
function setUp() {
parent::setUp('votingapi', 'ctools', 'vud');
// Create a vud admin user
$this->admin_user = $this
->drupalCreateUser(array(
// vud
'access vote up/down statistics',
'administer vote up/down',
'reset vote up/down votes',
'use vote up/down',
));
// Create a vud simple user
$this->simple_user = $this
->drupalCreateUser(array(
// vud
'access vote up/down statistics',
'use vote up/down',
'reset vote up/down votes',
));
//TODO more users with less privileges
// Create a vud restricted user (can not interact with vud)
$this->restricted_user = $this
->drupalCreateUser();
}
/**
* Test votes tab at account page.
*/
function testVotesTab() {
$this
->drupalLogin($this->simple_user);
// Check empty user account votes
$this
->clickLink(t('My account'));
$this
->clickLink(t('Votes'));
$this
->assertNoRaw('<td>', t('No votes found.'));
}
/**
* Execute a (non-AJAX) vote from the current node.
* @param $up
* If TRUE vote-up, otherwise vote-down.
*/
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();
}
}
Classes
Name | Description |
---|---|
VudWebTestCase | TODO test casting vote TODO test changing voting api tag after casting votes, and see if votes change TODO test vote reset |