Skip to content

Commit

Permalink
Merge branch 'pr/3808' into 5.1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuring committed Sep 18, 2024
2 parents 91192c9 + e8c8e04 commit 2368466
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions plugins/bc-mail/src/View/Helper/MailformHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ public function getGroupValidErrors(ResultSetInterface $mailFields, string $grou
* @return bool
* @checked
* @noTodo
* @unitTest
*/
public function isGroupLastField(ResultSet $mailFields, MailField $currentMailField)
{
Expand Down
37 changes: 37 additions & 0 deletions plugins/bc-mail/tests/TestCase/View/Helper/MailformHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -21,6 +25,7 @@ class MailformHelperTest extends BcTestCase
public function setUp(): void
{
parent::setUp();
$this->MailformHelper = new MailformHelper(new View());
}

/**
Expand Down Expand Up @@ -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],
];
}
}

0 comments on commit 2368466

Please sign in to comment.