Permalink
Browse files

Cleaning up

- Adding docblock
- Adding visibility keyword
- Update assertion methods.
- Split up tests into smaller methods.
  • Loading branch information...
1 parent 210f8c9 commit d8cbe8a1f72ad9e425c31dc8c64fd246cbde21b9 @ceeram ceeram committed with markstory Nov 13, 2011
Showing with 57 additions and 28 deletions.
  1. +47 −14 lib/Cake/Test/Case/View/ViewTest.php
  2. +10 −14 lib/Cake/View/View.php
@@ -297,7 +297,7 @@ public function testCamelCasePluginGetTemplate() {
*
* @return void
*/
- public function testGetTemplate() {
+ public function testGetViewFileNames() {
$this->Controller->plugin = null;
$this->Controller->name = 'Pages';
$this->Controller->viewPath = 'Pages';
@@ -318,27 +318,37 @@ public function testGetTemplate() {
$result = $View->getViewFileName('../Posts/index');
$this->assertEquals($expected, $result);
- $expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Layouts' . DS .'default.ctp';
- $result = $View->getLayoutFileName();
- $this->assertEquals($expected, $result);
-
- $expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS .'Pages' . DS .'home.ctp';
- $result = $View->getViewFileName('TestPlugin.home');
- $this->assertEqual($expected, $result);
+ $expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS .'Pages' . DS .'page.home.ctp';
+ $result = $View->getViewFileName('page.home');
+ $this->assertEquals($expected, $result, 'Should not ruin files with dots.');
CakePlugin::load('TestPlugin');
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS .'Pages' . DS .'home.ctp';
$result = $View->getViewFileName('TestPlugin.home');
- $this->assertEqual($expected, $result);
+ $this->assertEquals($expected, $result, 'Plugin is missing the view, cascade to app.');
$View->viewPath = 'Tests';
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'TestPlugin' . DS . 'View' . DS .'Tests' . DS .'index.ctp';
$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');
- $this->assertEqual($expected, $result);
+/**
+ * Test getting layout filenames
+ *
+ * @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';
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Layouts' . DS . 'rss' . DS . 'default.ctp';
@@ -348,7 +358,30 @@ public function testGetTemplate() {
$View->layoutPath = 'Emails' . DS . 'html';
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Layouts' . DS . 'Emails' . DS . 'html' . DS . 'default.ctp';
$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);
}
@@ -442,7 +475,7 @@ public function testElement() {
$this->assertEquals($result, 'this is the plugin element using params[plugin]');
$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');
$this->assertPattern('/Not Found:/', $result);
View
@@ -885,20 +885,15 @@ protected function _getViewFileName($name = null) {
throw new MissingViewException(array('file' => $defaultPath . $name . $this->ext));
}
- function _path($name, $plugin) {
- $paths = $this->_paths($plugin);
- $exts = $this->_getExtensions();
- foreach ($exts as $ext) {
- foreach ($paths as $path) {
- if (file_exists($path . $name . $ext)) {
- return $path . $name . $ext;
- }
- }
- }
- return null;
- }
-
- function _pluginSplit($name) {
+/**
+ * Splits a dot syntax plugin name into its plugin and filename.
+ * If $name does not have a dot, then index 0 will be null.
+ * It checks if the plugin is loaded, else filename will stay unchanged for filenames containing dot
+ *
+ * @param string $name The name you want to plugin split.
+ * @return array Array with 2 indexes. 0 => plugin name, 1 => filename
+ */
+ protected function _pluginSplit($name) {
$plugin = null;
list($first, $second) = pluginSplit($name);
if (CakePlugin::loaded($first) === true) {
@@ -910,6 +905,7 @@ function _pluginSplit($name) {
}
return array($plugin, $name);
}
+
/**
* Returns layout filename for this template as a string.
*

0 comments on commit d8cbe8a

Please sign in to comment.