From 40be3df93c2ab39fb1a643e9d40f990dfe5b9f13 Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Sun, 24 Jun 2012 16:35:18 -0400 Subject: [PATCH] Added tests for App::classname --- lib/Cake/Test/TestCase/Core/AppTest.php | 44 +++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/lib/Cake/Test/TestCase/Core/AppTest.php b/lib/Cake/Test/TestCase/Core/AppTest.php index 5593ba1accf..959fc6deab7 100644 --- a/lib/Cake/Test/TestCase/Core/AppTest.php +++ b/lib/Cake/Test/TestCase/Core/AppTest.php @@ -18,6 +18,7 @@ */ namespace Cake\Test\TestCase\Core; use Cake\Core\App; +use Cake\Core\Configure; use Cake\Core\Plugin; use Cake\TestSuite\TestCase; @@ -38,6 +39,49 @@ public function tearDown() { Plugin::unload(); } +/** + * testClassname method + * + * @return void + */ + public function testClassname() { + $currentApp = Configure::read('App.namespace'); + Configure::write('App.namespace', 'TestApp'); + + // Test core + $this->assertEquals('Cake\Core\App', App::classname('App', 'Core')); + $this->assertFalse(App::classname('App', 'Core', 'Suffix')); + + // Assert prefix + $this->assertFalse(App::classname('Auth', 'Controller/Component')); + $this->assertEquals('Cake\Controller\Component\AuthComponent', App::classname('Auth', 'Controller/Component', 'Component')); + + // Test app + $this->assertEquals('TestApp\Controller\PagesController', App::classname('Pages', 'Controller', 'Controller')); + $this->assertFalse(App::classname('Unknown', 'Controller', 'Controller')); + + // Test plugin + App::build(array( + 'Plugin' => array(CAKE . 'Test' . DS . 'TestApp' . DS . 'Plugin' . DS) + ), App::RESET); + Plugin::load('TestPlugin'); + $this->assertEquals('TestPlugin\Utility\TestPluginEngine', App::classname('TestPlugin.TestPlugin', 'Utility', 'Engine')); + $this->assertFalse(App::classname('TestPlugin.Unknown', 'Utility')); + + Plugin::unload('TestPlugin'); + Configure::write('App.namespace', $currentApp); + } + +/** + * testClassnameUnknownPlugin method + * + * @expectedException Cake\Error\MissingPluginException + * @return void + */ + public function testClassnameUnknownPlugin() { + App::classname('UnknownPlugin.Classname', 'Utility'); + } + /** * testBuild method *