Skip to content

Commit 40be3df

Browse files
committed
Added tests for App::classname
1 parent b1937c4 commit 40be3df

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

lib/Cake/Test/TestCase/Core/AppTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
namespace Cake\Test\TestCase\Core;
2020
use Cake\Core\App;
21+
use Cake\Core\Configure;
2122
use Cake\Core\Plugin;
2223
use Cake\TestSuite\TestCase;
2324

@@ -38,6 +39,49 @@ public function tearDown() {
3839
Plugin::unload();
3940
}
4041

42+
/**
43+
* testClassname method
44+
*
45+
* @return void
46+
*/
47+
public function testClassname() {
48+
$currentApp = Configure::read('App.namespace');
49+
Configure::write('App.namespace', 'TestApp');
50+
51+
// Test core
52+
$this->assertEquals('Cake\Core\App', App::classname('App', 'Core'));
53+
$this->assertFalse(App::classname('App', 'Core', 'Suffix'));
54+
55+
// Assert prefix
56+
$this->assertFalse(App::classname('Auth', 'Controller/Component'));
57+
$this->assertEquals('Cake\Controller\Component\AuthComponent', App::classname('Auth', 'Controller/Component', 'Component'));
58+
59+
// Test app
60+
$this->assertEquals('TestApp\Controller\PagesController', App::classname('Pages', 'Controller', 'Controller'));
61+
$this->assertFalse(App::classname('Unknown', 'Controller', 'Controller'));
62+
63+
// Test plugin
64+
App::build(array(
65+
'Plugin' => array(CAKE . 'Test' . DS . 'TestApp' . DS . 'Plugin' . DS)
66+
), App::RESET);
67+
Plugin::load('TestPlugin');
68+
$this->assertEquals('TestPlugin\Utility\TestPluginEngine', App::classname('TestPlugin.TestPlugin', 'Utility', 'Engine'));
69+
$this->assertFalse(App::classname('TestPlugin.Unknown', 'Utility'));
70+
71+
Plugin::unload('TestPlugin');
72+
Configure::write('App.namespace', $currentApp);
73+
}
74+
75+
/**
76+
* testClassnameUnknownPlugin method
77+
*
78+
* @expectedException Cake\Error\MissingPluginException
79+
* @return void
80+
*/
81+
public function testClassnameUnknownPlugin() {
82+
App::classname('UnknownPlugin.Classname', 'Utility');
83+
}
84+
4185
/**
4286
* testBuild method
4387
*

0 commit comments

Comments
 (0)