forked from marvil07/vote_up_down
/
vud.test
105 lines (93 loc) · 3.11 KB
/
vud.test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?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();
}
}