Skip to content

Commit

Permalink
Merge pull request #90 from akagane99/master
Browse files Browse the repository at this point in the history
getBlockSettingValue() 追加 - Model/BlockSetting
  • Loading branch information
akagane99 committed Jul 30, 2016
2 parents 659a5d9 + 3d935cd commit 6c09162
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Model/BlockSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,36 @@ public function beforeValidate($options = array()) {
return parent::beforeValidate($options);
}

/**
* 単一の設定値 ゲット
*
* @param string $fieldName 項目名
* @param Model $pluginKey プラグインキー
* @param Model $blockKey ブロックキー
* @return string 設定値
* @see BlockSettingBehavior::FIELD_USE_WORKFLOW 承認を使う
* @see BlockSettingBehavior::FIELD_USE_COMMENT_APPROVAL コメント承認を使う
*/
public function getBlockSettingValue($fieldName, $pluginKey = null, $blockKey = null) {
if (is_null($pluginKey)) {
$pluginKey = Current::read('Plugin.key');
}
if (is_null($blockKey)) {
$blockKey = Current::read('Block.key');
}

$blockSetting = $this->find('first', array(
'recursive' => -1,
'conditions' => array(
'BlockSetting.plugin_key' => $pluginKey,
'BlockSetting.block_key' => $blockKey,
'BlockSetting.field_name' => $fieldName,
),
));
if (!$blockSetting) {
return null;
}
return $blockSetting['BlockSetting']['value'];
}

}
95 changes: 95 additions & 0 deletions Test/Case/Model/BlockSetting/GetBlockSettingValueTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php
/**
* BlockSetting::getBlockSettingValue()のテスト
*
* @author Mitsuru Mutaguchi <mutaguchi@opensource-workshop.jp>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @copyright Copyright 2014, NetCommons Project
*/

App::uses('NetCommonsGetTest', 'NetCommons.TestSuite');

/**
* BlockSetting::getBlockSettingValue()のテスト
*
* @author Mitsuru Mutaguchi <mutaguchi@opensource-workshop.jp>
* @package NetCommons\Blocks\Test\Case\Model\BlockSetting
*/
class BlockSettingGetBlockSettingValueTest extends NetCommonsGetTest {

/**
* Fixtures
*
* @var array
*/
public $fixtures = array(
'plugin.blocks.block_setting',
);

/**
* Plugin name
*
* @var string
*/
public $plugin = 'blocks';

/**
* Model name
*
* @var string
*/
protected $_modelName = 'BlockSetting';

/**
* Method name
*
* @var string
*/
protected $_methodName = 'getBlockSettingValue';

/**
* testGetBlockSettingValue()のテスト
*
* @return void
* @see BlockSetting::getBlockSettingValue
*/
public function testGetBlockSettingValue() {
//データ生成
$model = $this->_modelName;
$methodName = $this->_methodName;
Current::write('Plugin.key', 'dummy');
Current::write('Block.key', 'block_1');
$fieldName = 'use_workflow';

//テスト実施
$result = $this->$model->$methodName($fieldName);

//チェック
//debug($result);
$this->assertEquals('0', $result);
}

/**
* testGetBlockSettingValue()のテスト - 空
*
* @return void
* @see BlockSetting::getBlockSettingValue
*/
public function testGetBlockSettingValueEmpty() {
//データ生成
$model = $this->_modelName;
$methodName = $this->_methodName;
Current::write('Plugin.key', 'dummy');
Current::write('Block.key', 'block_xxx'); //データなし条件
$fieldName = 'use_workflow';

//テスト実施
$result = $this->$model->$methodName($fieldName);

//チェック
//debug($result);
$this->assertEquals(null, $result);
}

}

0 comments on commit 6c09162

Please sign in to comment.