mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
fixes #6209, persistModel and undefined $Behaviors
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8117 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
3c3b852099
commit
5c53fcfcb9
2 changed files with 141 additions and 6 deletions
|
@ -248,7 +248,11 @@ class Object {
|
|||
$objectArray = array(&$object);
|
||||
$data = str_replace('\\', '\\\\', serialize($objectArray));
|
||||
$data = '<?php $' . $name . ' = \'' . str_replace('\'', '\\\'', $data) . '\' ?>';
|
||||
cache($file, $data, '+1 day');
|
||||
$duration = '+999 days';
|
||||
if (Configure::read() >= 1) {
|
||||
$duration = '+10 seconds';
|
||||
}
|
||||
cache($file, $data, $duration);
|
||||
}
|
||||
/**
|
||||
* Open the persistent class file for reading
|
||||
|
@ -267,14 +271,16 @@ class Object {
|
|||
case 'registry':
|
||||
$vars = unserialize(${$name});
|
||||
foreach ($vars['0'] as $key => $value) {
|
||||
App::import('Model', Inflector::classify($key));
|
||||
if (strpos($key, '_behavior') !== false) {
|
||||
App::import('Behavior', Inflector::classify(substr($key, 0, -9)));
|
||||
} else {
|
||||
App::import('Model', Inflector::classify($key));
|
||||
}
|
||||
unset ($value);
|
||||
}
|
||||
unset($vars);
|
||||
$vars = unserialize(${$name});
|
||||
foreach ($vars['0'] as $key => $value) {
|
||||
foreach ($vars['0'][$key]->Behaviors->_attached as $behavior) {
|
||||
App::import('Behavior', $behavior);
|
||||
}
|
||||
ClassRegistry::addObject($key, $value);
|
||||
unset ($value);
|
||||
}
|
||||
|
|
|
@ -117,6 +117,37 @@ class RequestActionController extends Controller {
|
|||
return $this->params;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* RequestActionPersistentController class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs
|
||||
*/
|
||||
class RequestActionPersistentController extends Controller {
|
||||
/**
|
||||
* uses property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $uses = array('PersisterOne');
|
||||
|
||||
/**
|
||||
* persistModel property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $persistModel = true;
|
||||
/**
|
||||
* post pass, testing post passing
|
||||
*
|
||||
* @return array
|
||||
**/
|
||||
function index() {
|
||||
return 'This is a test';
|
||||
}
|
||||
}
|
||||
/**
|
||||
* TestObject class
|
||||
*
|
||||
|
@ -271,7 +302,7 @@ class ObjectTest extends CakeTestCase {
|
|||
*
|
||||
* @var string
|
||||
**/
|
||||
var $fixtures = array('core.post');
|
||||
var $fixtures = array('core.post', 'core.comment');
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
|
@ -382,6 +413,104 @@ class ObjectTest extends CakeTestCase {
|
|||
Configure::write('Cache.disable', $cacheDisable);
|
||||
}
|
||||
/**
|
||||
* testPersistWithRequestAction method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testPersistWithBehavior() {
|
||||
ClassRegistry::flush();
|
||||
|
||||
$cacheDisable = Configure::read('Cache.disable');
|
||||
Configure::write('Cache.disable', false);
|
||||
|
||||
Configure::write('modelPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models'. DS));
|
||||
Configure::write('behaviorPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models'. DS . 'behaviors' . DS));
|
||||
|
||||
$this->assertFalse(class_exists('PersisterOneBehaviorBehavior'));
|
||||
$this->assertFalse(class_exists('PersisterTwoBehaviorBehavior'));
|
||||
|
||||
$Controller = new RequestActionPersistentController();
|
||||
$Controller->persistModel = true;
|
||||
$Controller->constructClasses();
|
||||
|
||||
$this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'persisterone.php'));
|
||||
$this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'persisteroneregistry.php'));
|
||||
|
||||
$contents = str_replace('"PersisterOne"', '"PersisterTwo"', file_get_contents(CACHE . 'persistent' . DS . 'persisteroneregistry.php'));
|
||||
$contents = str_replace('persister_one_', 'persister_two_', file_get_contents(CACHE . 'persistent' . DS . 'persisteroneregistry.php'));
|
||||
|
||||
$result = file_put_contents(CACHE . 'persistent' . DS . 'persisteroneregistry.php', $contents);
|
||||
|
||||
$this->assertTrue(class_exists('PersisterOneBehaviorBehavior'));
|
||||
$this->assertFalse(class_exists('PersisterTwoBehaviorBehavior'));
|
||||
|
||||
$Controller = new RequestActionPersistentController();
|
||||
$Controller->persistModel = true;
|
||||
$Controller->constructClasses();
|
||||
|
||||
$this->assertTrue(class_exists('PersisterOneBehaviorBehavior'));
|
||||
$this->assertTrue(class_exists('PersisterTwoBehaviorBehavior'));
|
||||
|
||||
@unlink(CACHE . 'persistent' . DS . 'persisterone.php');
|
||||
@unlink(CACHE . 'persistent' . DS . 'persisteroneregistry.php');
|
||||
}
|
||||
/**
|
||||
* testPersistWithBehaviorAndRequestAction method
|
||||
*
|
||||
* @see testPersistWithBehavior
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testPersistWithBehaviorAndRequestAction() {
|
||||
ClassRegistry::flush();
|
||||
|
||||
$cacheDisable = Configure::read('Cache.disable');
|
||||
Configure::write('Cache.disable', false);
|
||||
|
||||
$this->assertFalse(class_exists('ContainableBehavior'));
|
||||
|
||||
Configure::write('modelPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models'. DS));
|
||||
Configure::write('behaviorPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models'. DS . 'behaviors' . DS));
|
||||
|
||||
$this->assertFalse(class_exists('PersistOneBehaviorBehavior'));
|
||||
$this->assertFalse(class_exists('PersistTwoBehaviorBehavior'));
|
||||
|
||||
$Controller = new RequestActionPersistentController();
|
||||
$Controller->persistModel = true;
|
||||
$Controller->constructClasses();
|
||||
|
||||
$this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'persisterone.php'));
|
||||
$this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'persisteroneregistry.php'));
|
||||
|
||||
$keys = ClassRegistry::keys();
|
||||
$this->assertEqual($keys, array('persister_one', 'comment', 'persister_one_behavior_behavior'));
|
||||
|
||||
ob_start();
|
||||
$Controller->set('content_for_layout', 'cool');
|
||||
$Controller->render('index', 'ajax', '/layouts/ajax');
|
||||
$result = ob_get_clean();
|
||||
|
||||
$keys = ClassRegistry::keys();
|
||||
$this->assertEqual($keys, array('persister_one', 'comment', 'persister_one_behavior_behavior', 'view'));
|
||||
|
||||
$result = $this->object->requestAction('/request_action_persistent/index');
|
||||
$expected = 'This is a test';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
@unlink(CACHE . 'persistent' . DS . 'persisterone.php');
|
||||
@unlink(CACHE . 'persistent' . DS . 'persisteroneregistry.php');
|
||||
|
||||
$Controller = new RequestActionPersistentController();
|
||||
$Controller->persistModel = true;
|
||||
$Controller->constructClasses();
|
||||
|
||||
@unlink(CACHE . 'persistent' . DS . 'persisterone.php');
|
||||
@unlink(CACHE . 'persistent' . DS . 'persisteroneregistry.php');
|
||||
|
||||
Configure::write('Cache.disable', $cacheDisable);
|
||||
}
|
||||
/**
|
||||
* testToString method
|
||||
*
|
||||
* @access public
|
||||
|
|
Loading…
Add table
Reference in a new issue