Skip to content

Commit

Permalink
Merge pull request #75 from akagane99/master
Browse files Browse the repository at this point in the history
BlockSettingBehavior修正
  • Loading branch information
akagane99 committed Jul 19, 2016
2 parents 700a8b3 + b764370 commit af5166e
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 22 deletions.
14 changes: 10 additions & 4 deletions Model/Behavior/BlockSettingBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,11 @@ protected function _createBlockSetting(Model $model) {
*
* @param Model $model モデル
* @param string $blockKey ブロックキー
* @param bool $isRow 縦持ちデータ取得するか
* @return array
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function getBlockSetting(Model $model, $blockKey = null) {
public function getBlockSetting(Model $model, $blockKey = null, $isRow = false) {
$model->BlockSetting = ClassRegistry::init('Blocks.BlockSetting', true);
if (is_null($blockKey)) {
$blockKey = Current::read('Block.key');
Expand Down Expand Up @@ -207,6 +209,10 @@ public function getBlockSetting(Model $model, $blockKey = null) {
'{n}.{s}.field_name',
'{n}.{s}.value');

if (!$isRow) {
return $result;
}

// [BlockSetting] 縦持ちでindexをfield_nameに変更
$result['BlockSetting'] = Hash::combine($blockSettings, '{n}.{s}.field_name', '{n}.{s}');
return $result;
Expand Down Expand Up @@ -262,7 +268,6 @@ protected function _getDefaultApproval(Model $model, $blockSettings, $fieldName,
}

// ルーム承認しない
// TODOO ルーム承認なしにしても、デフォルト承認しない?
$defaultBlockSetting['BlockSetting']['value'] = '0';
$blockSettings[] = $defaultBlockSetting;
return $blockSettings;
Expand Down Expand Up @@ -338,7 +343,7 @@ public function saveBlockSetting(Model $model) {

// 横の入力データを、検索した縦データにセット & 新規登録用にブロックキーをセット
$blockKey = Current::read('Block.key');
$blockSetting = $this->getBlockSetting($model, $blockKey);
$blockSetting = $this->getBlockSetting($model, $blockKey, true);
$inputData = $model->data[$model->alias];
$saveData = null;

Expand Down Expand Up @@ -368,7 +373,8 @@ public function saveBlockSetting(Model $model) {
public function validateBlockSetting(Model $model) {
$inputData = $model->data[$model->alias];
$blockKey = Current::read('Block.key');
$blockSetting = $this->getBlockSetting($model, $blockKey);
// 縦データ取得
$blockSetting = $this->getBlockSetting($model, $blockKey, true);

// セッティングしたフィールドを基に、入力したフィールドのみvalidateする
foreach ($this->settings[$model->alias] as $field) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,29 @@ public function testCreateBlockSetting() {
/** @see BlockSettingBehavior::_createBlockSetting() */
$result = $this->TestModel->getBlockSetting();

//チェック
//debug($result);
//デフォルト値は承認する
$this->assertEquals('1', $result[$this->TestModel->alias]['use_workflow']);
$this->assertEquals('1', $result[$this->TestModel->alias]['use_comment_approval']);
}

/**
* createBlockSetting()のテスト 縦持ちデータ
*
* @return void
*/
public function testCreateBlockSettingRow() {
Current::write('Plugin.key', 'dummy');
Current::write('Room.id', 2);
Current::write('Room.need_approval', 1); //ルーム承認する
Current::write('Block.key', 'block_1');

//テスト実施
/** @see BlockSettingBehavior::getBlockSetting() */
/** @see BlockSettingBehavior::_createBlockSetting() */
$result = $this->TestModel->getBlockSetting(null, 1);

//チェック
//debug($result);
$this->assertArrayHasKey('field_name', $result['BlockSetting']['use_comment']);
Expand Down Expand Up @@ -101,11 +124,9 @@ public function testCreateBlockSettingNoApproval() {

//チェック
//debug($result);
$this->assertArrayHasKey('field_name', $result['BlockSetting']['use_comment']);
$this->assertArrayHasKey('value', $result['BlockSetting']['use_comment']);
//デフォルト値は承認しない
$this->assertEquals('0', $result['BlockSetting']['use_workflow']['value']);
$this->assertEquals('0', $result['BlockSetting']['use_comment_approval']['value']);
$this->assertEquals('0', $result[$this->TestModel->alias]['use_workflow']);
$this->assertEquals('0', $result[$this->TestModel->alias]['use_comment_approval']);
}

}
4 changes: 2 additions & 2 deletions Test/Case/Model/Behavior/BlockSettingBehavior/FindTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public function testFind() {

//チェック
//debug($result);
// BlockSettingが取得できた
$this->assertArrayHasKey('BlockSetting', $result);
// BlockSettingの横データが取得できた
$this->assertArrayHasKey('use_like', $result[$this->TestModel->alias]);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,11 @@ public function testGetBlockSetting() {

//チェック
//debug($result);
// データあり(縦持ち)
$this->assertArrayHasKey('use_like', $result['BlockSetting']);
// 承認系データあり
$this->assertEquals('0', $result['BlockSetting']['use_workflow']['value']);
$this->assertEquals('1', $result['BlockSetting']['use_comment_approval']['value']);
// データあり(横持ち)
$this->assertArrayHasKey('use_like', $result[$this->TestModel->alias]);
// 承認系データあり
$this->assertEquals('0', $result[$this->TestModel->alias]['use_workflow']);
$this->assertEquals('1', $result[$this->TestModel->alias]['use_comment_approval']);
}

/**
Expand All @@ -89,13 +87,11 @@ public function testGetBlockSettingNoUseWorkFlowData() {

//チェック
//debug($result);
// データあり(縦持ち)
$this->assertArrayHasKey('use_like', $result['BlockSetting']);
// 承認系データあり
$this->assertEquals('0', $result['BlockSetting']['use_workflow']['value']);
$this->assertEquals('0', $result['BlockSetting']['use_comment_approval']['value']);
// データあり(横持ち)
$this->assertArrayHasKey('use_like', $result[$this->TestModel->alias]);
// 承認系データあり
$this->assertEquals('0', $result[$this->TestModel->alias]['use_workflow']);
$this->assertEquals('0', $result[$this->TestModel->alias]['use_comment_approval']);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function testSaveBlockSetting() {
//チェック
$this->assertTrue($result);

$result = $this->TestModel->getBlockSetting($blockKey);
$result = $this->TestModel->getBlockSetting($blockKey, 1);
$checks = array(
'use_comment',
'use_like',
Expand All @@ -83,7 +83,10 @@ public function testSaveBlockSetting() {
);
//debug($result);
foreach ($checks as $check) {
// 更新した値チェック
// 更新した値チェック 横データ
$this->assertEquals($data[$this->TestModel->alies][$check],
$result[$this->TestModel->alies][$check]);
// 縦データ
$this->assertEquals($data[$this->TestModel->alies][$check],
$result['BlockSetting'][$check]['value']);
// 更新日時セットされてるよねチェック
Expand Down

0 comments on commit af5166e

Please sign in to comment.