From 0e908e8145ca674f424c4415116999994910bf88 Mon Sep 17 00:00:00 2001 From: thangnn Date: Thu, 28 Nov 2024 22:39:18 +0700 Subject: [PATCH] Add unitTest_MailFieldsTable_copy --- .../src/Model/Table/MailFieldsTable.php | 1 + .../Model/Table/MailFieldsTableTest.php | 79 ++++++++----------- 2 files changed, 34 insertions(+), 46 deletions(-) diff --git a/plugins/bc-mail/src/Model/Table/MailFieldsTable.php b/plugins/bc-mail/src/Model/Table/MailFieldsTable.php index 228f6cff6d..42cbe88326 100755 --- a/plugins/bc-mail/src/Model/Table/MailFieldsTable.php +++ b/plugins/bc-mail/src/Model/Table/MailFieldsTable.php @@ -273,6 +273,7 @@ public function sourceMailField(string $value, array $context) * @return EntityInterface|false * @checked * @noTodo + * @unitTest */ public function copy(?int $id, MailField $data = null, array $options = []) { diff --git a/plugins/bc-mail/tests/TestCase/Model/Table/MailFieldsTableTest.php b/plugins/bc-mail/tests/TestCase/Model/Table/MailFieldsTableTest.php index 4aa429f809..d347e5e880 100755 --- a/plugins/bc-mail/tests/TestCase/Model/Table/MailFieldsTableTest.php +++ b/plugins/bc-mail/tests/TestCase/Model/Table/MailFieldsTableTest.php @@ -235,54 +235,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']); } /**