-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathformfilterapi.test
More file actions
229 lines (187 loc) · 5.72 KB
/
formfilterapi.test
File metadata and controls
229 lines (187 loc) · 5.72 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<?php
/**
* @file
* Tests for formfilterapi module.
*/
/**
* Testing the module functions.
*/
class FormfilterapiTestCase extends DrupalWebTestCase {
/**
* A user with permission the access example page.
*
* @var object
*/
protected $web_user;
public static function getInfo() {
return array(
'name' => 'Testing the functional module',
'description' => 'Testing the module module-based example.',
'group' => 'Formfilterapi',
);
}
public function setUp() {
parent::setUp(array('formfilterapi', 'formfilterapi_example'));
$this->web_user = $this->drupalCreateUser(array('access content'));
$this->drupalLogin($this->web_user);
}
/**
* Filtering results when there is no node.
*/
public function testNoResults() {
$edit = array();
$edit['status[type]'] = 'page';
$this->drupalPost('formfilterapi_example', $edit, t('Filter'));
$filter_result = $this->xpath('//div[@id="node-1"]');
$this->assertEqual(0, count($filter_result));
}
/**
* Filter by type of material.
*/
public function testFilterType() {
$edit = array();
$edit['status[type]'] = 'page';
// Create node with type "page".
$this->drupalCreateNode();
$this->drupalPost('formfilterapi_example', $edit, t('Filter'));
$filter_result = $this->xpath('//div[@id="node-1"]');
$this->assertEqual(1, count($filter_result));
// Create the second node.
$this->drupalCreateNode();
$this->drupalPost('formfilterapi_example', $edit, t('Refine'));
$filter_result = $this->xpath('//div[starts-with(@class, "node ")]');
$this->assertEqual(2, count($filter_result));
}
/**
* Type filtering creator node.
*/
public function testFilterUser() {
$edit = array();
$edit['status[uid]'] = $this->web_user->uid;
// Create a node on behalf of the user.
$this->drupalCreateNode(array(
'uid' => $this->web_user->uid,
));
$this->drupalPost('formfilterapi_example', $edit, t('Filter'));
$filter_result = $this->xpath('//div[@id="node-1"]');
$this->assertEqual(1, count($filter_result));
}
/**
* The use of all filters.
*/
public function testFilters() {
$node = $this->drupalCreateNode(array(
'uid' => $this->web_user->uid,
));
$edit = array();
$edit['status[title]'] = $node->title;
$edit['status[type]'] = 'page';
$edit['status[uid]'] = $this->web_user->uid;
$this->drupalPost('formfilterapi_example', $edit, t('Filter'));
$filter_result = $this->xpath('//div[@id="node-1"]');
$this->assertEqual(1, count($filter_result));
}
}
/**
* Testing form filter api queries.
*/
class FormfilterapiQueryTestCase extends DrupalWebTestCase {
/**
* A user with permission the access example page.
*
* @var object
*/
protected $web_user;
public static function getInfo() {
return array(
'name' => 'Testing form filter api queries',
'description' => 'Testing options for filtering.',
'group' => 'Formfilterapi',
);
}
public function setUp() {
parent::setUp(array('formfilterapi', 'formfilterapi_example'));
$this->web_user = $this->drupalCreateUser(array('access content'));
$this->drupalLogin($this->web_user);
}
/**
* Testing the "LIKE" query.
*/
public function testLikeQuery() {
$node = $this->drupalCreateNode();
// Verifying LIKE.
$title = substr($node->title, 1, strlen($node->title) - 2);
$edit = array();
$edit['status[title]'] = $title;
$this->drupalPost('formfilterapi_example', $edit, t('Filter'));
$filter_result = $this->xpath('//div[@id="node-1"]');
$this->assertEqual(1, count($filter_result));
}
/**
* Testing the "Operation" query.
*/
public function testOperationQuery() {
$this->drupalCreateNode();
$this->drupalCreateNode(array(
'status' => 0,
));
$edit = array();
$edit['status[status]'] = '> 0';
$this->drupalPost('formfilterapi_example', $edit, t('Filter'));
$filter_result = $this->xpath('//div[@id="node-1"]');
$this->assertEqual(1, count($filter_result));
}
/**
* Testing the "Expression" query.
*/
public function testExpressionQuery() {
$this->drupalCreateNode();
$this->drupalCreateNode(array(
'status' => 1,
'promote' => 1,
));
$this->drupalCreateNode(array(
'status' => 1,
'promote' => 1,
));
$edit = array();
$edit['status[status]'] = '> 0';
$edit['status[promote]'] = 1;
$this->drupalPost('formfilterapi_example', $edit, t('Filter'));
$filter_result = $this->xpath('//div[contains(@class, "node")]');
$this->assertEqual(2, count($filter_result));
}
/**
* Testing the join.
*/
public function testJoin() {
$account = $this->drupalCreateUser(array('administer nodes'));
// Create thee nodes.
$this->drupalCreateNode();
$this->drupalCreateNode(array(
'uid' => $account->uid,
'status' => 0,
));
$this->drupalCreateNode(array(
'uid' => $account->uid,
'status' => 1,
));
$this->drupalPost('formfilterapi_example', array(), t('Filter'));
$filter_result = $this->xpath('//div[contains(@class, "node")]');
$this->assertEqual(3, count($filter_result));
$edit = array();
$edit['status[uid]'] = $account->uid;
$this->drupalPost('formfilterapi_example', $edit, t('Filter'));
$filter_result = $this->xpath('//div[contains(@class, "node")]');
$this->assertEqual(2, count($filter_result));
}
/**
* Testing the _alter.
*/
public function testAlter() {
$this->drupalCreateNode();
$this->drupalPost('formfilterapi_example', array(), t('Filter'));
$filter_result = $this->xpath('//select[@name="status[sticky]"]');
$this->assertEqual(1, count($filter_result));
}
}