From e8c8e048f2066af29721af8de1efd905095b032b Mon Sep 17 00:00:00 2001 From: thangnn Date: Thu, 12 Sep 2024 21:13:15 +0700 Subject: [PATCH] Add unitTest_MailFormHelper_isGroupLastField --- .../src/View/Helper/MailformHelper.php | 1 + .../View/Helper/MailformHelperTest.php | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/plugins/bc-mail/src/View/Helper/MailformHelper.php b/plugins/bc-mail/src/View/Helper/MailformHelper.php index 85b2c8f11c..f5dba87e79 100755 --- a/plugins/bc-mail/src/View/Helper/MailformHelper.php +++ b/plugins/bc-mail/src/View/Helper/MailformHelper.php @@ -344,6 +344,7 @@ public function getGroupValidErrors(ResultSetInterface $mailFields, string $grou * @return bool * @checked * @noTodo + * @unitTest */ public function isGroupLastField(ResultSet $mailFields, MailField $currentMailField) { diff --git a/plugins/bc-mail/tests/TestCase/View/Helper/MailformHelperTest.php b/plugins/bc-mail/tests/TestCase/View/Helper/MailformHelperTest.php index 85ab85c5a8..27dd75067d 100644 --- a/plugins/bc-mail/tests/TestCase/View/Helper/MailformHelperTest.php +++ b/plugins/bc-mail/tests/TestCase/View/Helper/MailformHelperTest.php @@ -11,6 +11,10 @@ namespace BcMail\Test\TestCase\View\Helper; use BaserCore\TestSuite\BcTestCase; +use BcMail\Model\Entity\MailField; +use BcMail\View\Helper\MailformHelper; +use Cake\ORM\ResultSet; +use Cake\View\View; class MailformHelperTest extends BcTestCase { @@ -21,6 +25,7 @@ class MailformHelperTest extends BcTestCase public function setUp(): void { parent::setUp(); + $this->MailformHelper = new MailformHelper(new View()); } /** @@ -55,4 +60,36 @@ public function testAuthCaptcha() { $this->markTestIncomplete('このテストは、まだ実装されていません。'); } + + /** + * test isGroupLastField + * @param array $mailFieldsData + * @param int $currentFieldIndex + * @param bool $expected + * @dataProvider isGroupLastFieldProvider + */ + public function testIsGroupLastField($mailFieldsData, $currentFieldIndex, $expected) + { + //create ResultSet + $mailFields = new ResultSet(array_map(function ($item) { + return new MailField($item); + }, $mailFieldsData)); + + //get current mail field + $currentMailField = $mailFields->toArray()[$currentFieldIndex]; + + $result = $this->MailformHelper->isGroupLastField($mailFields, $currentMailField); + $this->assertEquals($expected, $result); + } + + public static function isGroupLastFieldProvider() + { + return [ + [[['group_field' => 'group1'], ['group_field' => 'group1'], ['group_field' => 'group2']], 1, true], + [[['group_field' => 'group1'], ['group_field' => 'group1'], ['group_field' => 'group1']], 1, false], + [[['group_field' => 'group1'], ['group_field' => 'group1'], ['group_field' => 'group1']], 2, true], + [[['group_field' => ''], ['group_field' => 'group1']], 0, false], + [[['group_field' => 'group1'], ['group_field' => 'group2']], 0, true], + ]; + } }