Skip to content

Commit f7db10b

Browse files
committed
カスタムフィールドをコピーできるようにするう。
1 parent 1df7d70 commit f7db10b

File tree

2 files changed

+103
-6
lines changed

2 files changed

+103
-6
lines changed

src/lib/Backup/Copy/Traits/CopyIssue.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,25 @@ public function remapCustomFieldKeys($issue,$idMap){
5353
$custom_fields = array_filter($custom_fields,fn($c)=>!empty($c->value));
5454
$data = [];
5555
foreach ( $custom_fields as $idx => $cf ) {
56-
dump($map);
57-
dump($cf);
5856
$data[$idx] = [];
5957
$data[$idx]['id'] = $map[$cf->id];
60-
//$data[$idx]['value'] =match ($cf->fieldTypeId){
61-
// 1,2,3,4 => ,
62-
//};
58+
$data[$idx]['value'] =match ($cf->fieldTypeId){
59+
1,2,3,4,8 => $cf->value,
60+
6,7 => array_column($cf->value,'id'),
61+
};
6362
if (!empty($cf->other_value)){
6463
$data[$idx]['other_value'] = $cf->value;
6564
}
6665

6766
}
68-
foreach ( $data as $id=>$entry ) {
67+
68+
foreach ( $data as $idx=>$entry ) {
6969
$id = $entry['id'];
7070
$data["customField_{$id}"]=$entry['value'];
7171
if (!empty($entry['other_value'])){
7272
$data["customField_{$id}_otherValue"]=$entry['other_value'];
7373
}
74+
unset($data[$idx]);
7475
}
7576

7677
return $data;
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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

Comments
 (0)