From 66363e6bea97cfa052e5c9653c8402c5c480f0b0 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 19 Nov 2016 10:02:09 -0400 Subject: [PATCH] Add tests for #9766 I'm not able to reproduce incorrect aliases coming out of ClassRegistry. As reported. --- .../Test/Case/Utility/ClassRegistryTest.php | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Utility/ClassRegistryTest.php b/lib/Cake/Test/Case/Utility/ClassRegistryTest.php index 09e54959f..d6d70774f 100644 --- a/lib/Cake/Test/Case/Utility/ClassRegistryTest.php +++ b/lib/Cake/Test/Case/Utility/ClassRegistryTest.php @@ -147,7 +147,7 @@ class ClassRegistryTest extends CakeTestCase { $this->assertSame($Tag, $TagCopy); $NewTag = ClassRegistry::init(array('class' => 'RegisterArticleTag', 'alias' => 'NewTag')); - $this->assertInstanceOf('RegisterArticleTag', $Tag); + $this->assertInstanceOf('RegisterArticleTag', $NewTag); $NewTagCopy = ClassRegistry::init(array('class' => 'RegisterArticleTag', 'alias' => 'NewTag')); @@ -182,6 +182,24 @@ class ClassRegistryTest extends CakeTestCase { $this->assertEquals('ParentCategory', $ParentCategory->alias); } +/** + * Test that init() can make models with alias set properly + * + * @return void + */ + public function testAddModelWithAlias() + { + $tag = ClassRegistry::init(array('class' => 'RegisterArticleTag', 'alias' => 'NewTag')); + $this->assertInstanceOf('RegisterArticleTag', $tag); + $this->assertSame('NewTag', $tag->alias); + $this->assertSame('RegisterArticleTag', $tag->name); + + $newTag = ClassRegistry::init(array('class' => 'RegisterArticleTag', 'alias' => 'OtherTag')); + $this->assertInstanceOf('RegisterArticleTag', $tag); + $this->assertSame('OtherTag', $newTag->alias); + $this->assertSame('RegisterArticleTag', $newTag->name); + } + /** * testClassRegistryFlush method *