2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* ClassRegistryTest file
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* Long description for file
|
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
|
|
|
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
|
2009-11-06 04:34:28 +00:00
|
|
|
* Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* Licensed under The Open Group Test Suite License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2009-11-06 04:34:28 +00:00
|
|
|
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
2008-10-30 17:30:26 +00:00
|
|
|
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
|
2009-03-19 21:10:13 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs
|
|
|
|
* @since CakePHP(tm) v 1.2.0.5432
|
|
|
|
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
App::import('Core', 'ClassRegistry');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* ClassRegisterModel class
|
2008-08-25 22:33:36 +00:00
|
|
|
*
|
2009-03-19 21:10:13 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class ClassRegisterModel extends CakeTestModel {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* useTable property
|
2008-08-25 22:33:36 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var bool false
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $useTable = false;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* RegisterArticle class
|
2008-08-25 22:33:36 +00:00
|
|
|
*
|
2009-03-19 21:10:13 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class RegisterArticle extends ClassRegisterModel {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* name property
|
2008-08-25 22:33:36 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'RegisterArticle'
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $name = 'RegisterArticle';
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* RegisterArticleFeatured class
|
2008-08-25 22:33:36 +00:00
|
|
|
*
|
2009-03-19 21:10:13 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class RegisterArticleFeatured extends ClassRegisterModel {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* name property
|
2008-08-25 22:33:36 +00:00
|
|
|
*
|
2008-09-27 02:38:15 +00:00
|
|
|
* @var string 'RegisterArticleFeatured'
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
2008-09-27 02:38:15 +00:00
|
|
|
var $name = 'RegisterArticleFeatured';
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* RegisterArticleTag class
|
2008-08-25 22:33:36 +00:00
|
|
|
*
|
2009-03-19 21:10:13 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class RegisterArticleTag extends ClassRegisterModel {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* name property
|
2008-08-25 22:33:36 +00:00
|
|
|
*
|
2008-09-27 02:38:15 +00:00
|
|
|
* @var string 'RegisterArticleTag'
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
2008-09-27 02:38:15 +00:00
|
|
|
var $name = 'RegisterArticleTag';
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* RegistryPluginAppModel class
|
2008-08-25 22:33:36 +00:00
|
|
|
*
|
2009-03-19 21:10:13 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class RegistryPluginAppModel extends ClassRegisterModel {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* tablePrefix property
|
2008-08-25 22:33:36 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'something_'
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $tablePrefix = 'something_';
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* TestRegistryPluginModel class
|
2008-08-25 22:33:36 +00:00
|
|
|
*
|
2009-03-19 21:10:13 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class TestRegistryPluginModel extends RegistryPluginAppModel {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* name property
|
2008-08-25 22:33:36 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'TestRegistryPluginModel'
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $name = 'TestRegistryPluginModel';
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-09-27 02:38:15 +00:00
|
|
|
/**
|
|
|
|
* RegisterCategory class
|
|
|
|
*
|
2009-03-19 21:10:13 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs
|
2008-09-27 02:38:15 +00:00
|
|
|
*/
|
|
|
|
class RegisterCategory extends ClassRegisterModel {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-09-27 02:38:15 +00:00
|
|
|
/**
|
|
|
|
* name property
|
|
|
|
*
|
|
|
|
* @var string 'RegisterCategory'
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
var $name = 'RegisterCategory';
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* ClassRegistryTest class
|
2008-08-25 22:33:36 +00:00
|
|
|
*
|
2009-03-19 21:10:13 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-07-21 02:40:58 +00:00
|
|
|
class ClassRegistryTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testAddModel method
|
2008-08-25 22:33:36 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testAddModel() {
|
|
|
|
if (PHP5) {
|
|
|
|
$Tag = ClassRegistry::init('RegisterArticleTag');
|
|
|
|
} else {
|
|
|
|
$Tag =& ClassRegistry::init('RegisterArticleTag');
|
|
|
|
}
|
|
|
|
$this->assertTrue(is_a($Tag, 'RegisterArticleTag'));
|
|
|
|
|
|
|
|
$TagCopy = ClassRegistry::isKeySet('RegisterArticleTag');
|
|
|
|
$this->assertTrue($TagCopy);
|
|
|
|
|
|
|
|
$Tag->name = 'SomeNewName';
|
|
|
|
|
|
|
|
if (PHP5) {
|
|
|
|
$TagCopy = ClassRegistry::getObject('RegisterArticleTag');
|
|
|
|
} else {
|
|
|
|
$TagCopy =& ClassRegistry::getObject('RegisterArticleTag');
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertTrue(is_a($TagCopy, 'RegisterArticleTag'));
|
|
|
|
$this->assertIdentical($Tag, $TagCopy);
|
|
|
|
|
2008-09-24 02:00:57 +00:00
|
|
|
if (PHP5) {
|
|
|
|
$NewTag = ClassRegistry::init(array('class' => 'RegisterArticleTag', 'alias' => 'NewTag'));
|
|
|
|
} else {
|
|
|
|
$NewTag =& ClassRegistry::init(array('class' => 'RegisterArticleTag', 'alias' => 'NewTag'));
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue(is_a($Tag, 'RegisterArticleTag'));
|
|
|
|
|
2008-09-24 02:00:57 +00:00
|
|
|
if (PHP5) {
|
|
|
|
$NewTagCopy = ClassRegistry::init(array('class' => 'RegisterArticleTag', 'alias' => 'NewTag'));
|
|
|
|
} else {
|
|
|
|
$NewTagCopy =& ClassRegistry::init(array('class' => 'RegisterArticleTag', 'alias' => 'NewTag'));
|
|
|
|
}
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertNotIdentical($Tag, $NewTag);
|
2008-09-24 02:00:57 +00:00
|
|
|
$this->assertIdentical($NewTag, $NewTagCopy);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$NewTag->name = 'SomeOtherName';
|
|
|
|
$this->assertNotIdentical($Tag, $NewTag);
|
2008-09-24 02:00:57 +00:00
|
|
|
$this->assertIdentical($NewTag, $NewTagCopy);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$Tag->name = 'SomeOtherName';
|
|
|
|
$this->assertNotIdentical($Tag, $NewTag);
|
|
|
|
|
|
|
|
$this->assertTrue($TagCopy->name === 'SomeOtherName');
|
2008-09-24 02:00:57 +00:00
|
|
|
|
|
|
|
if (PHP5) {
|
|
|
|
$User = ClassRegistry::init(array('class' => 'RegisterUser', 'alias' => 'User', 'table' => false));
|
|
|
|
} else {
|
|
|
|
$User =& ClassRegistry::init(array('class' => 'RegisterUser', 'alias' => 'User', 'table' => false));
|
|
|
|
}
|
|
|
|
$this->assertTrue(is_a($User, 'AppModel'));
|
|
|
|
|
|
|
|
if (PHP5) {
|
|
|
|
$UserCopy = ClassRegistry::init(array('class' => 'RegisterUser', 'alias' => 'User', 'table' => false));
|
|
|
|
} else {
|
|
|
|
$UserCopy =& ClassRegistry::init(array('class' => 'RegisterUser', 'alias' => 'User', 'table' => false));
|
|
|
|
}
|
|
|
|
$this->assertTrue(is_a($UserCopy, 'AppModel'));
|
|
|
|
$this->assertIdentical($User, $UserCopy);
|
2008-09-27 02:38:15 +00:00
|
|
|
|
|
|
|
if (PHP5) {
|
|
|
|
$Category = ClassRegistry::init(array('class' => 'RegisterCategory'));
|
|
|
|
} else {
|
|
|
|
$Category =& ClassRegistry::init(array('class' => 'RegisterCategory'));
|
|
|
|
}
|
|
|
|
$this->assertTrue(is_a($Category, 'RegisterCategory'));
|
|
|
|
|
|
|
|
if (PHP5) {
|
|
|
|
$ParentCategory = ClassRegistry::init(array('class' => 'RegisterCategory', 'alias' => 'ParentCategory'));
|
|
|
|
} else {
|
|
|
|
$ParentCategory =& ClassRegistry::init(array('class' => 'RegisterCategory', 'alias' => 'ParentCategory'));
|
|
|
|
}
|
|
|
|
$this->assertTrue(is_a($ParentCategory, 'RegisterCategory'));
|
|
|
|
$this->assertNotIdentical($Category, $ParentCategory);
|
|
|
|
|
|
|
|
$this->assertNotEqual($Category->alias, $ParentCategory->alias);
|
|
|
|
$this->assertEqual('RegisterCategory', $Category->alias);
|
|
|
|
$this->assertEqual('ParentCategory', $ParentCategory->alias);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testClassRegistryFlush method
|
2008-08-25 22:33:36 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-08-28 12:08:36 +00:00
|
|
|
function testClassRegistryFlush() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$ArticleTag = ClassRegistry::getObject('RegisterArticleTag');
|
|
|
|
$this->assertTrue(is_a($ArticleTag, 'RegisterArticleTag'));
|
|
|
|
ClassRegistry::flush();
|
|
|
|
|
|
|
|
$NoArticleTag = ClassRegistry::isKeySet('RegisterArticleTag');
|
|
|
|
$this->assertFalse($NoArticleTag);
|
|
|
|
$this->assertTrue(is_a($ArticleTag, 'RegisterArticleTag'));
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
2008-08-28 12:08:36 +00:00
|
|
|
* testAddMultipleModels method
|
2008-08-25 22:33:36 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-08-28 12:08:36 +00:00
|
|
|
function testAddMultipleModels() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$Article = ClassRegistry::isKeySet('Article');
|
|
|
|
$this->assertFalse($Article);
|
|
|
|
|
|
|
|
$Featured = ClassRegistry::isKeySet('Featured');
|
|
|
|
$this->assertFalse($Featured);
|
|
|
|
|
|
|
|
$Tag = ClassRegistry::isKeySet('Tag');
|
|
|
|
$this->assertFalse($Tag);
|
|
|
|
|
|
|
|
$models = array(array('class' => 'RegisterArticle', 'alias' => 'Article'),
|
|
|
|
array('class' => 'RegisterArticleFeatured', 'alias' => 'Featured'),
|
|
|
|
array('class' => 'RegisterArticleTag', 'alias' => 'Tag'));
|
|
|
|
|
|
|
|
$added = ClassRegistry::init($models);
|
|
|
|
$this->assertTrue($added);
|
|
|
|
|
|
|
|
$Article = ClassRegistry::isKeySet('Article');
|
|
|
|
$this->assertTrue($Article);
|
|
|
|
|
|
|
|
$Featured = ClassRegistry::isKeySet('Featured');
|
|
|
|
$this->assertTrue($Featured);
|
|
|
|
|
|
|
|
$Tag = ClassRegistry::isKeySet('Tag');
|
|
|
|
$this->assertTrue($Tag);
|
|
|
|
|
|
|
|
$Article = ClassRegistry::getObject('Article');
|
|
|
|
$this->assertTrue(is_a($Article, 'RegisterArticle'));
|
|
|
|
|
|
|
|
$Featured = ClassRegistry::getObject('Featured');
|
|
|
|
$this->assertTrue(is_a($Featured, 'RegisterArticleFeatured'));
|
|
|
|
|
|
|
|
$Tag = ClassRegistry::getObject('Tag');
|
|
|
|
$this->assertTrue(is_a($Tag, 'RegisterArticleTag'));
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testPluginAppModel method
|
2008-08-25 22:33:36 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testPluginAppModel() {
|
|
|
|
$TestRegistryPluginModel = ClassRegistry::isKeySet('TestRegistryPluginModel');
|
|
|
|
$this->assertFalse($TestRegistryPluginModel);
|
|
|
|
|
|
|
|
$TestRegistryPluginModel = ClassRegistry::init('RegistryPlugin.TestRegistryPluginModel');
|
|
|
|
$this->assertTrue(is_a($TestRegistryPluginModel, 'TestRegistryPluginModel'));
|
|
|
|
|
|
|
|
$this->assertEqual($TestRegistryPluginModel->tablePrefix, 'something_');
|
2008-09-24 02:00:57 +00:00
|
|
|
|
|
|
|
if (PHP5) {
|
|
|
|
$PluginUser = ClassRegistry::init(array('class' => 'RegistryPlugin.RegisterUser', 'alias' => 'RegistryPluginUser', 'table' => false));
|
|
|
|
} else {
|
|
|
|
$PluginUser =& ClassRegistry::init(array('class' => 'RegistryPlugin.RegisterUser', 'alias' => 'RegistryPluginUser', 'table' => false));
|
|
|
|
}
|
|
|
|
$this->assertTrue(is_a($PluginUser, 'RegistryPluginAppModel'));
|
|
|
|
|
|
|
|
if (PHP5) {
|
|
|
|
$PluginUserCopy = ClassRegistry::getObject('RegistryPluginUser');
|
|
|
|
} else {
|
|
|
|
$PluginUserCopy =& ClassRegistry::getObject('RegistryPluginUser');
|
|
|
|
}
|
|
|
|
$this->assertTrue(is_a($PluginUserCopy, 'RegistryPluginAppModel'));
|
|
|
|
$this->assertIdentical($PluginUser, $PluginUserCopy);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
2008-06-27 08:17:02 +00:00
|
|
|
?>
|