1+ <?php
2+
3+ namespace tests \Feature \API ;
4+
5+
6+
7+ use tests \Feature \TestCase \TestCaseTemporaryProject ;
8+
9+ class CustomFieldListTest extends TestCaseTemporaryProject {
10+ protected $ sample_cf =null ;
11+ protected $ sample_issue_type_id ;
12+ protected $ sample_priority_id ;
13+
14+ protected function setUp (): void {
15+ parent ::setUp ();
16+ $ this ->create_custom_field ();
17+ $ this ->issue_type_id ();
18+ $ this ->priority_id ();
19+ }
20+
21+ protected function tearDown (): void {
22+ $ this ->delete_custom_field ();
23+ parent ::tearDown ();
24+ }
25+ protected function delete_custom_field (){
26+ if ($ this ->sample_cf ){
27+ $ api = $ this ->api_client ();
28+ $ api ->deleteCustomField ($ this ->project_id ,$ this ->sample_cf ->id );
29+ }
30+ }
31+ protected function create_custom_field (){
32+ $ api = $ this ->api_client ();
33+ $ ret = $ api ->addCustomField ($ this ->project_id ,[
34+ 'typeId ' =>6 ,
35+ 'name ' =>'sample-for-api ' ,
36+ 'description ' =>'APIテスト用 ' ,
37+ 'required ' =>false ,
38+ 'items ' =>['項目A ' ,'項目B ' ,'項目C ' ],
39+ 'allowInput ' =>true ,
40+ 'allowAddItem ' =>true
41+ ]);
42+ $ this ->sample_cf =$ ret ;
43+ return $ ret ;
44+ }
45+ protected function issue_type_id (){
46+ $ api = $ this ->api_client ();
47+ $ ret =$ api ->getIssueTypeList ($ this ->project_id );
48+ $ this ->sample_issue_type_id = $ ret [0 ]->id ;
49+ }
50+ protected function priority_id (){
51+ $ api = $ this ->api_client ();
52+ $ ret =$ api ->getPriorityList ();
53+ $ this ->sample_priority_id = $ ret [0 ]->id ;
54+ }
55+
56+
57+ public function test_create_issue_with_custom_field_of_multiple_list (){
58+ $ api = $ this ->api_client ();
59+ $ cf_id =$ this ->sample_cf ->id ;
60+ $ data = [
61+ 'projectId ' =>$ this ->project_id ,
62+ 'summary ' =>'追加テスト ' ,
63+ 'issueTypeId ' =>$ this ->sample_issue_type_id ,
64+ 'priorityId ' =>$ this ->sample_priority_id ,
65+ ] ;
66+ $ data ['customField_ ' .$ cf_id ] = [1 ,2 ];
67+ $ ret = $ api ->addIssue ($ data );
68+ $ api ->deleteIssue ($ ret ->id );
69+ $ posted_cf = array_values (array_filter ($ ret ->customFields ,fn ($ e )=>$ e ->id ==$ cf_id ));
70+ $ this ->assertNotEmpty ($ posted_cf );
71+ $ posted_cf = $ posted_cf [0 ]->value ;
72+ $ this ->assertEquals (2 ,sizeof ($ posted_cf ) );
73+
74+
75+
76+ }
77+
78+ }
0 commit comments