Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Model/Behavior/OriginalKeyBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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');
Expand Down
3 changes: 3 additions & 0 deletions TestSuite/NetCommonsCakeTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -151,6 +152,8 @@ public function tearDown() {
Current::$current = array();
Current::$permission = array();

OriginalKeyBehavior::$isUnitRandomKey = false;

parent::tearDown();
}

Expand Down
3 changes: 3 additions & 0 deletions TestSuite/NetCommonsControllerBaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -160,6 +161,8 @@ public function tearDown() {
Current::$current = array();
Current::$permission = array();

OriginalKeyBehavior::$isUnitRandomKey = false;

SiteSettingUtil::reset();
parent::tearDown();
}
Expand Down