Skip to content

Commit

Permalink
CustomEntriesTable::autoConvert のユニットテスト (#3256)
Browse files Browse the repository at this point in the history
Co-authored-by: Đỗ Văn Hùng <[email protected]>
  • Loading branch information
HungDV2022 and dovanhung authored Mar 25, 2024
1 parent aa039f5 commit 74775bf
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ public function setValidateDatetime(Validator $validator, CustomLink $link, arra
* @return Validator
* @checked
* @noTodo
* @unitTest
* @unitTest
*/
public function validationDefault(Validator $validator): Validator
{
Expand Down Expand Up @@ -554,6 +554,7 @@ public function beforeMarshal(EventInterface $event, ArrayObject $content, Array
* @return ArrayObject
* @checked
* @noTodo
* @unitTest
*/
public function autoConvert(ArrayObject $content)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use BcCustomContent\Test\Factory\CustomLinkFactory;
use BcCustomContent\Test\Scenario\CustomContentsScenario;
use BcCustomContent\Service\CustomEntriesService;
use Cake\Core\Configure;
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait;

/**
Expand Down Expand Up @@ -570,14 +571,58 @@ public function test_beforeMarshal()
*/
public function test_autoConvert()
{
$this->markTestIncomplete('このテストは未実装です。');
//準備

//正常系実行

//異常系実行
Configure::write('BcCustomContent.fieldTypes.BcCcFile.controlType', 'file');
//データ生成
CustomFieldFactory::make([
'id' => 1,
'type' => 'BcCcRelated'
])->persist();
CustomLinkFactory::make([
'id' => 1,
'custom_table_id' => 1,
'custom_field_id' => 1
])->persist();
CustomFieldFactory::make([
'id' => 2,
'type' => 'BcCcFile'
])->persist();
CustomLinkFactory::make([
'id' => 2,
'custom_table_id' => 2,
'custom_field_id' => 2
])->persist();

//ArrayObject
$arrayObject = new \ArrayObject([
'name' => 'プログラマー',
'meta' => [
'__loop-src__' => 'aaa',
'BcCcCheckbox' => ['label' => '']
],
]);

//$controlType === 'file'
$this->CustomEntriesTable->setLinks(2);
$rs = $this->CustomEntriesTable->autoConvert($arrayObject);
//戻り値を確認
$this->assertEquals('プログラマー', $rs['name']);
//配列場合、
//__loop-src__がunsetされないか確認すること
//配列はjson_encodeを交換しないか確認すること
$this->assertEquals([
'__loop-src__' => 'aaa',
'BcCcCheckbox' => ['label' => '']
], $rs['meta']);

//$controlType !== 'file'
$this->CustomEntriesTable->setLinks(1);
$rs = $this->CustomEntriesTable->autoConvert($arrayObject);
//戻り値を確認
$this->assertEquals('プログラマー', $rs['name']);
//配列場合、
//__loop-src__がunsetされたか確認すること
//json_encodeができるか確認すること
$this->assertEquals('{"BcCcCheckbox":{"label":""}}', $rs['meta']);
}

/**
Expand Down

0 comments on commit 74775bf

Please sign in to comment.