diff --git a/Model/Behavior/OriginalKeyBehavior.php b/Model/Behavior/OriginalKeyBehavior.php index f4b7547b..807eca7e 100644 --- a/Model/Behavior/OriginalKeyBehavior.php +++ b/Model/Behavior/OriginalKeyBehavior.php @@ -29,6 +29,13 @@ class OriginalKeyBehavior extends ModelBehavior { 'priority' => 8 ); +/** + * PHPUnitで使用するキー配列 + * + * @var mixed + */ + public static $isUnitRandomKey = false; + /** * beforeSave is called before a model is saved. Returning false from a beforeSave callback * will abort the save operation. @@ -87,7 +94,7 @@ public function afterSave(Model $model, $created, $options = array()) { * @return string Hash key */ public static function generateKey($plugin, $dataSource) { - if ($dataSource !== 'test') { + if ($dataSource !== 'test' || self::$isUnitRandomKey) { return Security::hash($plugin . mt_rand() . microtime(), 'md5'); } else { return Security::hash($plugin, 'md5'); diff --git a/TestSuite/NetCommonsCakeTestCase.php b/TestSuite/NetCommonsCakeTestCase.php index aff19820..f81da42c 100644 --- a/TestSuite/NetCommonsCakeTestCase.php +++ b/TestSuite/NetCommonsCakeTestCase.php @@ -15,6 +15,7 @@ App::uses('Current', 'NetCommons.Utility'); App::uses('NetCommonsTestSuite', 'NetCommons.TestSuite'); App::uses('SiteSettingUtil', 'SiteManager.Utility'); +App::uses('OriginalKeyBehavior', 'NetCommons.Model/Behavior'); /** * NetCommonsCakeTestCase class @@ -151,6 +152,8 @@ public function tearDown() { Current::$current = array(); Current::$permission = array(); + OriginalKeyBehavior::$isUnitRandomKey = false; + parent::tearDown(); } diff --git a/TestSuite/NetCommonsControllerBaseTestCase.php b/TestSuite/NetCommonsControllerBaseTestCase.php index b6073e99..159d8bb1 100644 --- a/TestSuite/NetCommonsControllerBaseTestCase.php +++ b/TestSuite/NetCommonsControllerBaseTestCase.php @@ -20,6 +20,7 @@ App::uses('NetCommonsCakeTestCase', 'NetCommons.TestSuite'); App::uses('Role', 'Roles.Model'); App::uses('SiteSettingUtil', 'SiteManager.Utility'); +App::uses('OriginalKeyBehavior', 'NetCommons.Model/Behavior'); /** * NetCommonsControllerTestCase @@ -160,6 +161,8 @@ public function tearDown() { Current::$current = array(); Current::$permission = array(); + OriginalKeyBehavior::$isUnitRandomKey = false; + SiteSettingUtil::reset(); parent::tearDown(); }