Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MailFieldsTable::copy #4053

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plugins/bc-mail/src/Model/Table/MailFieldsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ public function sourceMailField(string $value, array $context)
* @return EntityInterface|false
* @checked
* @noTodo
* @unitTest
*/
public function copy(?int $id, MailField $data = null, array $options = [])
{
Expand Down
79 changes: 33 additions & 46 deletions plugins/bc-mail/tests/TestCase/Model/Table/MailFieldsTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,54 +244,41 @@ public static function sourceMailFieldDataProvider()

/**
* フィールドデータをコピーする
*
* @param int $id
* @param array $data
* @param array $sortUpdateOff
* @param array $expected 期待値
* @dataProvider copyDataProvider
*/
public function testCopy($id, $data, $sortUpdateOff)
{
$this->markTestIncomplete('こちらのテストはまだ未確認です');
$options = ['sortUpdateOff' => $sortUpdateOff];
$result = $this->MailField->copy($id, $data, $options);

if ($id) {
$this->assertEquals('姓漢字_copy', $result['MailField']['name'], '$idからコピーができません');
if (!$sortUpdateOff) {
$this->assertEquals(19, $result['MailField']['sort'], 'sortを正しく設定できません');
} else {
$this->assertEquals(1, $result['MailField']['sort'], 'sortを正しく設定できません');
}
} else {
$this->assertEquals('hogeName_copy', $result['MailField']['name'], '$dataからコピーができません');
if (!$sortUpdateOff) {
$this->assertEquals(19, $result['MailField']['sort'], 'sortを正しく設定できません');
} else {
$this->assertEquals(999, $result['MailField']['sort'], 'sortを正しく設定できません');
}
}
}

public static function copyDataProvider()
public function testCopy()
{
return [
[1, [], false],
[false, ['MailField' => [
'mail_content_id' => 1,
'field_name' => 'name_1',
'name' => 'hogeName',
'sort' => 999,
]], false],
[1, [], true],
[false, ['MailField' => [
'mail_content_id' => 1,
'field_name' => 'name_1',
'name' => 'hogeName',
'sort' => 999,
]], true],
];
//準備
MailFieldsFactory::make([
'id' => 1,
'mail_content_id' => 1,
'no' => 1,
'name' => '性',
'field_name' => 'name_1',
'type' => 'text',
'head' => 'お名前',
'attention' => '',
'before_attachment' => '',
'after_attachment' => '',
'source' => '資料請求|問い合わせ|その他',
'size' => 1,
'text_rows' => 1,
'maxlength' => 1,
'options' => '',
'class' => '',
'default_value' => '',
'description' => '',
'group_field' => '',
'group_valid' => '',
'valid' => ''
])->persist();

$options = ['sortUpdateOff' => false];
$result = $this->MailFieldsTable->copy(1, null, $options);
$this->assertEquals('性_copy', $result['name']);

$data = MailFieldsFactory::make(['mail_content_id' => 2, 'field_name' => 'name_2', 'name' => 'hogeName', 'sort' => 999])->getEntity();
$result = $this->MailFieldsTable->copy(false, $data, $options);
$this->assertEquals('hogeName', $result['name']);
}

/**
Expand Down