Skip to content

Commit

Permalink
Migrating ThemeViewTest to phpunit
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Jun 1, 2010
1 parent 0743cee commit 33b2f04
Showing 1 changed file with 16 additions and 36 deletions.
52 changes: 16 additions & 36 deletions cake/tests/cases/libs/view/theme.test.php
Expand Up @@ -126,7 +126,7 @@ function getLayoutFileName($name = null) {
* @return void
*/
function cakeError($method, $messages) {
$error =& new ThemeViewTestErrorHandler($method, $messages);
$error = new ThemeViewTestErrorHandler($method, $messages);
return $error;
}
}
Expand All @@ -147,11 +147,15 @@ class ThemeViewTest extends CakeTestCase {
*/
function setUp() {
Router::reload();
$this->Controller =& new Controller();
$this->PostsController =& new ThemePostsController();
$this->Controller = new Controller();
$this->PostsController = new ThemePostsController();
$this->PostsController->viewPath = 'posts';
$this->PostsController->index();
$this->ThemeView =& new ThemeView($this->PostsController);
$this->ThemeView = new ThemeView($this->PostsController);
App::build(array(
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS),
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
));
}

/**
Expand All @@ -165,6 +169,7 @@ function tearDown() {
unset($this->PostsController);
unset($this->Controller);
ClassRegistry::flush();
App::build();
}
/**
* test that the theme view can be constructed without going into the registry
Expand All @@ -174,34 +179,11 @@ function tearDown() {
function testConstructionNoRegister() {
ClassRegistry::flush();
$controller = null;
$Theme =& new ThemeView($controller, false);
$ThemeTwo =& ClassRegistry::getObject('view');
$Theme = new ThemeView($controller, false);
$ThemeTwo = ClassRegistry::getObject('view');
$this->assertFalse($ThemeTwo);
}

/**
* startTest
*
* @access public
* @return void
*/
function startTest() {
App::build(array(
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS),
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
));
}

/**
* endTest
*
* @access public
* @return void
*/
function endTest() {
App::build();
}

/**
* testPluginGetTemplate method
*
Expand All @@ -215,7 +197,7 @@ function testPluginThemedGetTemplate() {
$this->Controller->action = 'index';
$this->Controller->theme = 'test_theme';

$ThemeView =& new TestThemeView($this->Controller);
$ThemeView = new TestThemeView($this->Controller);
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS . 'plugins' . DS . 'test_plugin' . DS . 'tests' . DS .'index.ctp';
$result = $ThemeView->getViewFileName('index');
$this->assertEqual($result, $expected);
Expand All @@ -242,7 +224,7 @@ function testGetTemplate() {
$this->Controller->action = 'display';
$this->Controller->params['pass'] = array('home');

$ThemeView =& new TestThemeView($this->Controller);
$ThemeView = new TestThemeView($this->Controller);
$ThemeView->theme = 'test_theme';
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS .'pages' . DS .'home.ctp';
$result = $ThemeView->getViewFileName('home');
Expand Down Expand Up @@ -282,12 +264,10 @@ function testMissingView() {

$this->Controller->params['pass'] = array('home');

restore_error_handler();
$View =& new TestThemeView($this->Controller);
$View = new TestThemeView($this->Controller);
ob_start();
$result = $View->getViewFileName('does_not_exist');
$expected = str_replace(array("\t", "\r\n", "\n"), "", ob_get_clean());
set_error_handler('simpleTestErrorHandler');
$this->assertPattern("/PagesController::/", $expected);
$this->assertPattern("/views(\/|\\\)themed(\/|\\\)my_theme(\/|\\\)pages(\/|\\\)does_not_exist.ctp/", $expected);
}
Expand All @@ -304,7 +284,7 @@ function testMissingLayout() {
$this->Controller->layout = 'whatever';
$this->Controller->theme = 'my_theme';

$View =& new TestThemeView($this->Controller);
$View = new TestThemeView($this->Controller);
ob_start();
$result = $View->getLayoutFileName();
$expected = str_replace(array("\t", "\r\n", "\n"), "", ob_get_clean());
Expand All @@ -327,7 +307,7 @@ function testMemoryLeakInPaths() {
$this->Controller->layout = 'whatever';
$this->Controller->theme = 'test_theme';

$View =& new ThemeView($this->Controller);
$View = new ThemeView($this->Controller);
$View->element('test_element');

$start = memory_get_usage();
Expand Down

0 comments on commit 33b2f04

Please sign in to comment.