Skip to content

Commit

Permalink
Merge pull request #4053 from thangnnmd/unitTest_MailFieldsTable_copy
Browse files Browse the repository at this point in the history
MailFieldsTable::copy
  • Loading branch information
HungDV2022 authored Dec 2, 2024
2 parents a70ba13 + 5c3d710 commit 0cf6452
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 46 deletions.
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

0 comments on commit 0cf6452

Please sign in to comment.