-
Notifications
You must be signed in to change notification settings - Fork 0
/
project_issue.test
377 lines (331 loc) · 11.9 KB
/
project_issue.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
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
<?php
// $Id: project_issue.test,v 1.4 2010/04/24 01:58:18 dww Exp $
include_once drupal_get_path('module', 'project') . '/project.test';
class ProjectIssueWebTestCase extends ProjectWebTestCase {
function setUp() {
// Setup the required modules for all tests.
$modules = func_get_args();
$modules = array_merge(array('project_issue', 'views', 'comment', 'comment_upload', 'upload'), $modules);
// We can't call parent::setUp() with a single array argument, so we need
// this ugly call_user_func_array().
call_user_func_array(array($this, 'parent::setUp'), $modules);
variable_set('comment_preview_project_issue', FALSE);
}
/**
* Create an Issue node.
*
* @param stdClass $project
* A project node.
* @param array $edit
* An array of form values, passed to drupalPost. Optional
* @return
* An issue node.
*/
function createIssue($project, $edit = array()) {
// If people are lazy and don't want to specify any of these, provide a
// default.
$edit += array(
'title' => $this->randomName(8),
'body' => $this->randomName(64),
'component' => 'Code',
'category' => 'bug',
);
$this->drupalPost('node/add/project-issue/' . $project->project['uri'], $edit, t('Save'));
$this->assertRaw(t('!post %title has been created.', array('!post' => 'Issue', '%title' => $edit["title"])), t('Issue created.'));
return $this->drupalGetNodeByTitle($edit['title']);
}
function createIssueComment($issue, $edit = array()) {
$edit += array('comment' => $this->randomName(64));
$this->drupalPost('comment/reply/' . $issue->nid, $edit, t('Save'));
return $edit;
}
/**
* Make sure issue metadata matches up to what it's intended to be.
*
* @param array $metadata
* Associative array of expected issue metadata field names and values.
* @param $nid
* Optional integer node ID of the issue to check metadata fields for.
*/
function assertIssueMetadata($metadata, $nid = NULL, $message = NULL) {
$pass = TRUE;
if ($nid) {
$this->drupalGet('node/' . $nid);
}
if (!$message) {
$message = t('Issue metadata matches');
}
foreach ($this->xpath("//div[@id='project-issue-summary-table']/table//tr") as $row) {
$key = strtolower(trim((string)$row->td[0], ':'));
if (isset($metadata[$key])) {
if (strtolower($metadata[$key]) != strtolower((string)$row->td[1])) {
$pass = FALSE;
}
}
}
if ($pass) {
$this->pass($message);
}
else {
$this->fail($message);
}
}
}
class ProjectIssueCreationTestCase extends ProjectIssueWebTestCase {
protected $maintain_user;
public static function getInfo() {
return array(
'name' => 'Project issue creation',
'description' => 'Test creating an issue.',
'group' => 'Project Issue',
);
}
function setUp() {
parent::setUp();
$this->maintain_user = $this->drupalCreateUser(array('maintain projects', 'create project issues', 'access project issues', 'access projects'));
$this->drupalLogin($this->maintain_user);
}
/**
* Test the creation of project issues and the display of issue properties.
*/
function testProjectIssueCreation() {
$project = $this->createProject();
// Test project issue node form fields.
$this->drupalGet('node/add/project-issue/' . $project->project['uri']);
$this->assertText(t('Create Issue'));
$issue = $this->createIssue($project, array(
'component' => 'Miscellaneous',
'category' => 'feature',
'priority' => 1,
'assigned' => $this->maintain_user->uid,
));
$this->assertText($issue->title, t('Title found'));
$this->assertText($issue->body, t('Body found'));
$issue = $this->createIssue($project, array(
'component' => 'Miscellaneous',
'category' => 'feature',
'priority' => 1,
'assigned' => $this->maintain_user->uid,
));
$this->assertIssueMetadata(array(
'component' => 'Miscellaneous',
'category' => 'feature request',
'priority' => 'critical',
'assigned' => $this->maintain_user->name,
));
}
}
class ProjectIssueCommentTestCase extends ProjectIssueWebTestCase {
public static function getInfo() {
return array(
'name' => 'Project issue comment',
'description' => 'Test commenting on an issue.',
'group' => 'Project Issue',
);
}
function setUp() {
parent::setUp();
$maintain_user = $this->drupalCreateUser(array('maintain projects', 'create project issues', 'access project issues', 'access projects'));
$this->drupalLogin($maintain_user);
}
/**
* Test the creation of issue metadata.
*/
function testProjectIssueMetadata() {
$project = $this->createProject();
// Test project issue node form fields.
$issue = $this->createIssue($project);
$html = $this->drupalGet('comment/reply/' . $issue->nid);
$this->parse();
// Let's iterate over all the forms.
$forms = $this->xpath('//form');
$form = $forms[0];
// We try to set the fields of this form as specified in $edit.
$post = $upload = $edit = array();
$this->handleForm($post, $edit, $upload, NULL, $form);
$map = array(
'priority' => 'priority',
'category' => 'category',
'component' => 'project_info[component]',
'assigned' => 'project_info[assigned]',
'pid' => 'project_info[pid]',
);
foreach ($map as $issue_key => $post_key) {
$this->assertEqual($issue->project_issue[$issue_key], $post[$post_key], t('Making sure comment form is correct.'));
}
}
/**
* Test the creation of issue comments.
*/
function testProjectIssueComment() {
$project = $this->createProject();
// Test project issue node form fields.
$issue = $this->createIssue($project);
$comment = $this->createIssueComment($issue);
$this->assertText($comment['comment'], t('Body found'));
}
}
class ProjectIssuePriorityTestCase extends ProjectIssueWebTestCase {
/**
* A user who can maintain project issue administrative settings, projects, and create issues.
*/
protected $maintain_user;
public static function getInfo() {
return array(
'name' => 'Project issue priority',
'description' => 'Test issue priority settings and functionality.',
'group' => 'Project Issue',
);
}
function setUp() {
parent::setUp();
$this->maintain_user = $this->drupalCreateUser(array('administer projects', 'maintain projects', 'create project issues', 'access project issues', 'access projects'));
$this->drupalLogin($this->maintain_user);
}
/**
* Assert that the priorities are stored and displayed correctly.
*
* This function will take an array of priorities keyed by their priority ID,
* with each item being an array with they keys 'name' and 'weight'.
*/
function assertAdminPrioritiesForm($values) {
$pass = TRUE;
$this->drupalGet('admin/project/project-issue-priority');
$forms = $this->xpath('//form');
$form = $forms[0];
$post = $edit = $upload = array();
$this->handleForm($post, $edit, $upload, NULL, $form);
foreach ($values as $key => $priority) {
$result = $this->assertEqual($post["priority[$key][name]"], $priority['name'], t('The name for the priority is correct.'));
$result = $this->assertEqual($post["priority[$key][weight]"], $priority['weight'], t('The weight for the priority is correct.'));
}
}
/**
* Test the project issue priority admin form.
*/
function testProjectIssuePrioritySettings() {
// This matches the defaults setup in project_issue_install().
$default_priority_order = array(
1 => array(
'name' => 'critical',
'weight' => 1,
),
2 => array(
'name' => 'normal',
'weight' => 2,
),
3 => array(
'name' => 'minor',
'weight' => 3,
),
);
$this->assertAdminPrioritiesForm($default_priority_order);
// Test reordering ability
$edit = array();
$edit['priority[1][weight]'] = -2;
$edit['priority[2][weight]'] = -3;
$edit['priority[3][weight]'] = -1;
$this->drupalPost('admin/project/project-issue-priority', $edit, t('Save'));
// Check new values
$priorities = array(
1 => array(
'name' => 'critical',
'weight' => 1,
),
2 => array(
'name' => 'normal',
'weight' => 0,
),
3 => array(
'name' => 'minor',
'weight' => 2,
),
);
$this->assertAdminPrioritiesForm($priorities);
// Add a new priority, and check the form results
$edit = array();
$edit['priority[0][name]'] = $this->randomName(8);
$this->drupalPost('admin/project/project-issue-priority', $edit, t('Save'));
// Check new values
$priorities = array(
1 => array(
'name' => 'critical',
'weight' => 1,
),
2 => array(
'name' => 'normal',
'weight' => 0,
),
3 => array(
'name' => 'minor',
'weight' => 2,
),
4 => array(
'name' => $edit['priority[0][name]'],
'weight' => 3,
),
);
$this->assertAdminPrioritiesForm($priorities);
// Test deleting a priority without any issues.
$this->drupalGet('admin/project/project-issue-priority/delete/4');
$this->assertNoText('Reassign priority', t('Issue confirm form is displayed properly.'));
$this->drupalPost('admin/project/project-issue-priority/delete/4', array(), t('Delete'));
$this->assertText('Project issue priority '. $edit['priority[0][name]'] .' deleted.', t('Project issue priority has been deleted.'));
// Test that a custom priority can be assinged to an issue and is displayed correctly.
$edit = array();
$edit['priority[0][name]'] = $priority_name = $this->randomName(8);
$this->drupalPost('admin/project/project-issue-priority', $edit, t('Save'));
$project = $this->createProject();
$edit = array();
$edit['priority'] = '5';
$issue = $this->createIssue($project, $edit);
// Check that the issue priority is displayed correctly.
$this->assertIssueMetadata(array('priority' => $priority_name), $issue->nid, t('Custom issue priority is displyed correctly'));
// Delete the priority
$this->drupalGet('admin/project/project-issue-priority/delete/5');
$this->assertText('Reassign priority', t('Issue confirm form is displayed properly.'));
$edit = array();
$edit['new_pid'] = 2;
$this->drupalPost(NULL, $edit, t('Delete'));
$this->assertText('Project issue priority '. $priority_name .' deleted.', t('Issue priority was deleted'));
$this->assertIssueMetadata(array('priority' => 'normal'), $issue->nid);
$edit = array();
$edit['priority[1][weight]'] = -3;
$edit['priority[2][weight]'] = -2;
$edit['priority[3][weight]'] = -1;
$this->drupalPost('admin/project/project-issue-priority', $edit, t('Save'));
$priorities = array(
1 => array(
'name' => 'critical',
'weight' => 0,
),
2 => array(
'name' => 'normal',
'weight' => 1,
),
3 => array(
'name' => 'minor',
'weight' => 2,
),
);
$this->assertAdminPrioritiesForm($priorities);
$edit = array();
$edit['priority'] = 1;
$edit['title'] = $critical_title = $this->randomName(8);
$critical_issue = $this->createIssue($project, $edit);
$edit = array();
$edit['priority'] = 3;
$edit['title'] = $minor_title = $this->randomName(8);
$minor_issue = $this->createIssue($project, $edit);
$this->drupalGet('project/issues/'. $project->project['uri']);
$this->clickLink(t('Priority'));
// Check that views handler
// @TODO This code is not working yet but is quite important
// $rows = $this->xpath("//table[@class='project-issue']/tr");
// debug((string)$rows[0]->td[0]);
//
// $this->assertEqual((string)$rows[0], $minor_issue->title);
// $this->assertEqual((string)$rows[1], $issue->title);
// $this->assertEqual((string)$rows[2], $critical_issue->title);
}
}