Skip to content

Commit

Permalink
Merge pull request #645 from huoxito/2.2
Browse files Browse the repository at this point in the history
Make controller test template extends ControllerTestCase instead of CakeTestCase
  • Loading branch information
markstory committed May 12, 2012
2 parents eeff950 + 287c7b4 commit 5d3291b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 40 deletions.
2 changes: 1 addition & 1 deletion lib/Cake/Console/Command/Task/TestTask.php
Expand Up @@ -460,7 +460,7 @@ public function generateConstructor($type, $fullClassName, $plugin) {
}
if ($type == 'controller') {
$className = substr($fullClassName, 0, -10);
$construct = "new Test$fullClassName();\n";
$construct = "new $fullClassName();\n";
$post = "\$this->{$className}->constructClasses();\n";
}
if ($type == 'helper') {
Expand Down
33 changes: 4 additions & 29 deletions lib/Cake/Console/Templates/default/classes/test.ctp
Expand Up @@ -23,40 +23,15 @@ echo "<?php\n";
App::uses('<?php echo $dependency[0]; ?>', '<?php echo $dependency[1]; ?>');
<?php endforeach; ?>

<?php if ($mock && strtolower($type) === 'controller'): ?>
/**
* Test<?php echo $fullClassName; ?>
*
*/
class Test<?php echo $fullClassName; ?> extends <?php echo $fullClassName; ?> {

/**
* Auto render
*
* @var boolean
*/
public $autoRender = false;

/**
* Redirect action
*
* @param mixed $url
* @param mixed $status
* @param boolean $exit
* @return void
*/
public function redirect($url, $status = null, $exit = true) {
$this->redirectUrl = $url;
}

}

<?php endif; ?>
/**
* <?php echo $fullClassName; ?> Test Case
*
*/
<?php if ($type === 'Controller'): ?>
class <?php echo $fullClassName; ?>Test extends ControllerTestCase {
<?php else: ?>
class <?php echo $fullClassName; ?>Test extends CakeTestCase {
<?php endif; ?>

<?php if (!empty($fixtures)): ?>
/**
Expand Down
14 changes: 4 additions & 10 deletions lib/Cake/Test/Case/Console/Command/Task/TestTaskTest.php
Expand Up @@ -455,9 +455,7 @@ public function testBakeModelTest() {
}

/**
* test baking controller test files, ensure that the stub class is generated.
* Conditional assertion is known to fail on PHP4 as classnames are all lower case
* causing issues with inflection of path name from classname.
* test baking controller test files
*
* @return void
*/
Expand All @@ -468,14 +466,10 @@ public function testBakeControllerTest() {
$result = $this->Task->bake('Controller', 'TestTaskComments');

$this->assertContains("App::uses('TestTaskCommentsController', 'Controller')", $result);
$this->assertContains('class TestTaskCommentsControllerTest extends CakeTestCase', $result);

$this->assertContains('class TestTestTaskCommentsController extends TestTaskCommentsController', $result);
$this->assertContains('public $autoRender = false', $result);
$this->assertContains('function redirect($url, $status = null, $exit = true)', $result);
$this->assertContains('class TestTaskCommentsControllerTest extends ControllerTestCase', $result);

$this->assertContains('function setUp()', $result);
$this->assertContains("\$this->TestTaskComments = new TestTestTaskCommentsController()", $result);
$this->assertContains("\$this->TestTaskComments = new TestTaskCommentsController()", $result);
$this->assertContains("\$this->TestTaskComments->constructClasses()", $result);

$this->assertContains('function tearDown()', $result);
Expand Down Expand Up @@ -556,7 +550,7 @@ public function testBakeHelperTest() {
*/
public function testGenerateConstructor() {
$result = $this->Task->generateConstructor('controller', 'PostsController', null);
$expected = array('', "new TestPostsController();\n", "\$this->Posts->constructClasses();\n");
$expected = array('', "new PostsController();\n", "\$this->Posts->constructClasses();\n");
$this->assertEquals($expected, $result);

$result = $this->Task->generateConstructor('model', 'Post', null);
Expand Down

0 comments on commit 5d3291b

Please sign in to comment.