Skip to content

Commit 7d99037

Browse files
committed
Add behat tests for creating issues with custom fields
1 parent 472027f commit 7d99037

File tree

3 files changed

+121
-10
lines changed

3 files changed

+121
-10
lines changed

tests/Behat/Bootstrap/CustomFieldContextTrait.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,42 @@
88

99
trait CustomFieldContextTrait
1010
{
11+
/**
12+
* @Given I create a custom field for issues with the name :customFieldName
13+
*/
14+
public function iCreateACustomFieldForIssuesWithTheName($customFieldName)
15+
{
16+
// support for creating custom fields via REST API is missing
17+
$this->redmine->excecuteDatabaseQuery(
18+
'INSERT INTO custom_fields(type, name, field_format, is_required, is_for_all, position) VALUES(:type, :name, :field_format, :is_required, :is_for_all, :position);',
19+
[],
20+
[
21+
':type' => 'IssueCustomField',
22+
':name' => $customFieldName,
23+
':field_format' => 'string',
24+
':is_required' => 0,
25+
':is_for_all' => 1,
26+
':position' => 1,
27+
],
28+
);
29+
}
30+
31+
/**
32+
* @Given I enable the tracker with ID :trackerId for custom field with ID :customFieldId
33+
*/
34+
public function iEnableTheTrackerWithIdForCustomFieldWithId($trackerId, $customFieldId)
35+
{
36+
// support for enabling custom fields for trackers via REST API is missing
37+
$this->redmine->excecuteDatabaseQuery(
38+
'INSERT INTO custom_fields_trackers(custom_field_id, tracker_id) VALUES(:custom_field_id, :tracker_id);',
39+
[],
40+
[
41+
':custom_field_id' => $customFieldId,
42+
':tracker_id' => $trackerId,
43+
],
44+
);
45+
}
46+
1147
/**
1248
* @When I list all custom fields
1349
*/

tests/Behat/Bootstrap/IssueContextTrait.php

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ trait IssueContextTrait
1515
*/
1616
public function iCreateAnIssueWithTheFollowingData(TableNode $table)
1717
{
18-
$data = [];
19-
20-
foreach ($table as $row) {
21-
$data[$row['property']] = $row['value'];
22-
}
18+
$data = $this->prepareIssueData($table);
2319

2420
/** @var Issue */
2521
$api = $this->getNativeCurlClient()->getApi('issue');
@@ -35,11 +31,7 @@ public function iCreateAnIssueWithTheFollowingData(TableNode $table)
3531
*/
3632
public function iUpdateTheIssueWithIdAndTheFollowingData($issueId, TableNode $table)
3733
{
38-
$data = [];
39-
40-
foreach ($table as $row) {
41-
$data[$row['property']] = $row['value'];
42-
}
34+
$data = $this->prepareIssueData($table);
4335

4436
/** @var Issue */
4537
$api = $this->getNativeCurlClient()->getApi('issue');
@@ -105,4 +97,23 @@ public function iRemoveTheIssueWithId($issueId)
10597
$api->getLastResponse(),
10698
);
10799
}
100+
101+
private function prepareIssueData(TableNode $table): array
102+
{
103+
$data = [];
104+
105+
foreach ($table as $row) {
106+
$key = $row['property'];
107+
$value = $row['value'];
108+
109+
// Support for json in custom_fields
110+
if ($key === 'custom_fields') {
111+
$value = json_decode($value, true);
112+
}
113+
114+
$data[$key] = $value;
115+
}
116+
117+
return $data;
118+
}
108119
}

tests/Behat/features/issue.feature

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,70 @@ Feature: Interacting with the REST API for issues
122122
| id | 1 |
123123
| name | Redmine Admin |
124124

125+
@custom_field
126+
Scenario: Creating an issue with custom field
127+
Given I have a "NativeCurlClient" client
128+
And I have an issue status with the name "New"
129+
And I have an issue priority with the name "Normal"
130+
And I have a tracker with the name "Defect" and default status id "1"
131+
And I create a project with name "Test Project" and identifier "test-project"
132+
And I create a custom field for issues with the name "Note"
133+
And I enable the tracker with ID "1" for custom field with ID "1"
134+
When I create an issue with the following data
135+
| property | value |
136+
| subject | issue subject |
137+
| project | Test Project |
138+
| tracker | Defect |
139+
| priority | Normal |
140+
| status | New |
141+
| custom_fields | [{"id":1,"value":"Note for custom field"}] |
142+
Then the response has the status code "201"
143+
And the response has the content type "application/xml"
144+
And the returned data is an instance of "SimpleXMLElement"
145+
And the returned data has only the following properties
146+
"""
147+
id
148+
project
149+
tracker
150+
status
151+
priority
152+
author
153+
subject
154+
description
155+
start_date
156+
due_date
157+
done_ratio
158+
is_private
159+
estimated_hours
160+
total_estimated_hours
161+
custom_fields
162+
created_on
163+
updated_on
164+
closed_on
165+
"""
166+
And the returned data has proterties with the following data
167+
| property | value |
168+
| id | 1 |
169+
| subject | issue subject |
170+
| description | [] |
171+
| due_date | [] |
172+
| done_ratio | 0 |
173+
| is_private | false |
174+
| estimated_hours | [] |
175+
| total_estimated_hours | [] |
176+
And the returned data "custom_fields.custom_field" property has only the following properties
177+
"""
178+
@attributes
179+
value
180+
"""
181+
And the returned data "custom_fields.custom_field.@attributes" property contains the following data
182+
| property | value |
183+
| id | 1 |
184+
| name | Note |
185+
And the returned data "custom_fields.custom_field" property contains the following data
186+
| property | value |
187+
| value | Note for custom field |
188+
125189
Scenario: Updating an issue
126190
Given I have a "NativeCurlClient" client
127191
And I have an issue status with the name "New"

0 commit comments

Comments
 (0)