Cleaning up

- Adding docblock
- Adding visibility keyword
- Update assertion methods.
- Split up tests into smaller methods.
This commit is contained in:
Ceeram 2011-11-13 04:31:34 +01:00 committed by Mark Story
parent 210f8c9e2c
commit d8cbe8a1f7
2 changed files with 57 additions and 28 deletions

View file

@ -297,7 +297,7 @@ class ViewTest extends CakeTestCase {
* *
* @return void * @return void
*/ */
public function testGetTemplate() { public function testGetViewFileNames() {
$this->Controller->plugin = null; $this->Controller->plugin = null;
$this->Controller->name = 'Pages'; $this->Controller->name = 'Pages';
$this->Controller->viewPath = 'Pages'; $this->Controller->viewPath = 'Pages';
@ -318,27 +318,37 @@ class ViewTest extends CakeTestCase {
$result = $View->getViewFileName('../Posts/index'); $result = $View->getViewFileName('../Posts/index');
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Layouts' . DS .'default.ctp'; $expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS .'Pages' . DS .'page.home.ctp';
$result = $View->getLayoutFileName(); $result = $View->getViewFileName('page.home');
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result, 'Should not ruin files with dots.');
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS .'Pages' . DS .'home.ctp';
$result = $View->getViewFileName('TestPlugin.home');
$this->assertEqual($expected, $result);
CakePlugin::load('TestPlugin'); CakePlugin::load('TestPlugin');
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS .'Pages' . DS .'home.ctp'; $expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS .'Pages' . DS .'home.ctp';
$result = $View->getViewFileName('TestPlugin.home'); $result = $View->getViewFileName('TestPlugin.home');
$this->assertEqual($expected, $result); $this->assertEquals($expected, $result, 'Plugin is missing the view, cascade to app.');
$View->viewPath = 'Tests'; $View->viewPath = 'Tests';
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'TestPlugin' . DS . 'View' . DS .'Tests' . DS .'index.ctp'; $expected = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'TestPlugin' . DS . 'View' . DS .'Tests' . DS .'index.ctp';
$result = $View->getViewFileName('TestPlugin.index'); $result = $View->getViewFileName('TestPlugin.index');
$this->assertEqual($expected, $result); $this->assertEquals($expected, $result);
}
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'TestPlugin' . DS . 'View' . DS . 'Layouts' . DS .'default.ctp'; /**
$result = $View->getLayoutFileName('TestPlugin.default'); * Test getting layout filenames
$this->assertEqual($expected, $result); *
* @return void
*/
public function testGetLayoutFileName() {
$this->Controller->plugin = null;
$this->Controller->name = 'Pages';
$this->Controller->viewPath = 'Pages';
$this->Controller->action = 'display';
$View = new TestView($this->Controller);
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Layouts' . DS .'default.ctp';
$result = $View->getLayoutFileName();
$this->assertEquals($expected, $result);
$View->layoutPath = 'rss'; $View->layoutPath = 'rss';
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Layouts' . DS . 'rss' . DS . 'default.ctp'; $expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Layouts' . DS . 'rss' . DS . 'default.ctp';
@ -348,7 +358,30 @@ class ViewTest extends CakeTestCase {
$View->layoutPath = 'Emails' . DS . 'html'; $View->layoutPath = 'Emails' . DS . 'html';
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Layouts' . DS . 'Emails' . DS . 'html' . DS . 'default.ctp'; $expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Layouts' . DS . 'Emails' . DS . 'html' . DS . 'default.ctp';
$result = $View->getLayoutFileName(); $result = $View->getLayoutFileName();
$this->assertEquals($expected, $result);
}
/**
* Test getting layout filenames for plugins.
*
* @return void
*/
public function testGetLayoutFileNamePlugin() {
$this->Controller->plugin = null;
$this->Controller->name = 'Pages';
$this->Controller->viewPath = 'Pages';
$this->Controller->action = 'display';
$View = new TestView($this->Controller);
CakePlugin::load('TestPlugin');
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'TestPlugin' . DS . 'View' . DS . 'Layouts' . DS .'default.ctp';
$result = $View->getLayoutFileName('TestPlugin.default');
$this->assertEquals($expected, $result);
$View->plugin = 'TestPlugin';
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'TestPlugin' . DS . 'View' . DS . 'Layouts' . DS .'default.ctp';
$result = $View->getLayoutFileName('default');
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
} }
@ -442,7 +475,7 @@ class ViewTest extends CakeTestCase {
$this->assertEquals($result, 'this is the plugin element using params[plugin]'); $this->assertEquals($result, 'this is the plugin element using params[plugin]');
$result = $this->View->element('TestPlugin.plugin_element'); $result = $this->View->element('TestPlugin.plugin_element');
$this->assertEqual($result, 'this is the plugin element using params[plugin]'); $this->assertEquals($result, 'this is the plugin element using params[plugin]');
$result = $this->View->element('test_plugin.plugin_element'); $result = $this->View->element('test_plugin.plugin_element');
$this->assertPattern('/Not Found:/', $result); $this->assertPattern('/Not Found:/', $result);

View file

@ -885,20 +885,15 @@ class View extends Object {
throw new MissingViewException(array('file' => $defaultPath . $name . $this->ext)); throw new MissingViewException(array('file' => $defaultPath . $name . $this->ext));
} }
function _path($name, $plugin) { /**
$paths = $this->_paths($plugin); * Splits a dot syntax plugin name into its plugin and filename.
$exts = $this->_getExtensions(); * If $name does not have a dot, then index 0 will be null.
foreach ($exts as $ext) { * It checks if the plugin is loaded, else filename will stay unchanged for filenames containing dot
foreach ($paths as $path) { *
if (file_exists($path . $name . $ext)) { * @param string $name The name you want to plugin split.
return $path . $name . $ext; * @return array Array with 2 indexes. 0 => plugin name, 1 => filename
} */
} protected function _pluginSplit($name) {
}
return null;
}
function _pluginSplit($name) {
$plugin = null; $plugin = null;
list($first, $second) = pluginSplit($name); list($first, $second) = pluginSplit($name);
if (CakePlugin::loaded($first) === true) { if (CakePlugin::loaded($first) === true) {
@ -910,6 +905,7 @@ class View extends Object {
} }
return array($plugin, $name); return array($plugin, $name);
} }
/** /**
* Returns layout filename for this template as a string. * Returns layout filename for this template as a string.
* *