1+ <?php
2+
3+ namespace tests \Feature \Copy ;
4+
5+ use tests \Feature \TestCase \TestCaseTemporaryProject ;
6+ use Takuya \BacklogApiClient \Backup \Copy \BacklogCopy ;
7+
8+ class CopyIssueHasCustomFieldTest extends TestCaseTemporaryProject {
9+ protected $ sample_issue_type_id ;
10+ protected $ sample_priority_id ;
11+ protected object $ sample_cf_list ;
12+ protected object $ sample_issue ;
13+ protected object $ sample_cf_string ;
14+
15+ public function test_format_copy_issue_data_has_custom_field_multiple_list () {
16+ $ worker = new BacklogCopy ( $ this ->api );
17+ $ rf = new \ReflectionClass ( $ worker );
18+ $ m = $ rf ->getMethod ( 'remapCustomFieldKeys ' );
19+ $ m ->setAccessible ( true );
20+ $ idMap = [$ this ->sample_cf_list ->id => 999999 , $ this ->sample_cf_string ->id => 123456 ];
21+ $ ret = $ m ->invokeArgs ( $ worker , [$ this ->sample_issue , $ idMap ] );
22+ $ this ->assertArrayHasKey ( 'customField_999999 ' , $ ret );
23+ $ this ->assertArrayHasKey ( 'customField_123456 ' , $ ret );
24+ $ this ->assertEquals ( [1 , 2 ], $ ret ['customField_999999 ' ] );
25+ $ this ->assertEquals ( "入力サンプル-AAAA " , $ ret ['customField_123456 ' ] );
26+ }
27+
28+ protected function setUp (): void {
29+ parent ::setUp (); // TODO: Change the autogenerated stub
30+ $ this ->api ->enableLogging ();
31+ $ this ->create_custom_field_multiple_list ();
32+ $ this ->create_custom_field_string ();
33+ $ this ->issue_type_id ();
34+ $ this ->priority_id ();
35+ $ this ->create_issue_with_custom_field ();
36+ }
37+
38+ protected function create_custom_field_string () {
39+ $ api = $ this ->api_client ();
40+ $ ret = $ api ->addCustomField ( $ this ->project_id , [
41+ 'typeId ' => 1 ,
42+ 'name ' => 'sample-for-api-string ' ,
43+ 'description ' => 'APIテスト用(文字列) ' ,
44+ 'required ' => false ,
45+ ] );
46+ $ this ->sample_cf_string = $ ret ;
47+ return $ ret ;
48+ }
49+
50+ protected function create_custom_field_multiple_list () {
51+ $ api = $ this ->api_client ();
52+ $ ret = $ api ->addCustomField ( $ this ->project_id , [
53+ 'typeId ' => 6 ,
54+ 'name ' => 'sample-for-api-multi ' ,
55+ 'description ' => 'APIテスト用(複数選択) ' ,
56+ 'required ' => false ,
57+ 'items ' => ['項目A ' , '項目B ' , '項目C ' ],
58+ 'allowInput ' => true ,
59+ 'allowAddItem ' => true ,
60+ ] );
61+ $ this ->sample_cf_list = $ ret ;
62+ return $ ret ;
63+ }
64+
65+ protected function issue_type_id () {
66+ $ api = $ this ->api_client ();
67+ $ ret = $ api ->getIssueTypeList ( $ this ->project_id );
68+ $ this ->sample_issue_type_id = $ ret [0 ]->id ;
69+ }
70+
71+ protected function priority_id () {
72+ $ api = $ this ->api_client ();
73+ $ ret = $ api ->getPriorityList ();
74+ $ this ->sample_priority_id = $ ret [0 ]->id ;
75+ }
76+
77+ public function create_issue_with_custom_field () {
78+ $ api = $ this ->api_client ();
79+ $ data = [
80+ 'projectId ' => $ this ->project_id ,
81+ 'summary ' => '追加テスト ' ,
82+ 'issueTypeId ' => $ this ->sample_issue_type_id ,
83+ 'priorityId ' => $ this ->sample_priority_id ,
84+ ];
85+ $ data ['customField_ ' .$ this ->sample_cf_list ->id ] = [1 , 2 ];
86+ $ data ['customField_ ' .$ this ->sample_cf_string ->id ] = '入力サンプル-AAAA ' ;
87+
88+ $ this ->sample_issue = $ api ->addIssue ( $ data );
89+ }
90+
91+ protected function tearDown (): void {
92+ $ this ->api ->disableLogging ();
93+ parent ::tearDown (); // TODO: Change the autogenerated stub
94+ }
95+
96+ }
0 commit comments