Updating the rest of the controller task test case to use phpunit.

This commit is contained in:
mark_story 2010-05-30 00:59:36 -04:00
parent ca5fb9fb93
commit 5ef9103a52

View file

@ -94,7 +94,7 @@ class ControllerTaskTest extends CakeTestCase {
array(&$this->Dispatcher)
);
$this->Task->Project = $this->getMock('ProjectTask',
array('in', 'out', 'err', 'createFile', '_stop', '_checkUnitTest'),
array('in', 'out', 'err', 'createFile', '_stop', '_checkUnitTest', 'getPrefix'),
array(&$this->Dispatcher)
);
$this->Task->Test = $this->getMock('TestTask', array(), array(&$this->Dispatcher));
@ -324,7 +324,7 @@ class ControllerTaskTest extends CakeTestCase {
*
* @return void
*/
public function xxtestBakeActionsUsingSessions() {
public function testBakeActionsUsingSessions() {
$skip = $this->skipIf(!defined('ARTICLE_MODEL_CREATED'),
'Testing bakeActions requires Article, Comment & Tag Model to be undefined. %s');
if ($skip) {
@ -350,7 +350,7 @@ class ControllerTaskTest extends CakeTestCase {
$this->assertTrue(strpos($result, 'function delete($id = null)') !== false);
$this->assertTrue(strpos($result, 'if ($this->Article->delete($id))') !== false);
$this->assertTrue(strpos($result, "\$this->Session->setFlash(__('Article deleted', true));") !== false);
$this->assertTrue(strpos($result, "\$this->Session->setFlash(__('Article deleted'));") !== false);
$result = $this->Task->bakeActions('Articles', 'admin_', true);
@ -366,7 +366,7 @@ class ControllerTaskTest extends CakeTestCase {
*
* @return void
*/
public function xxtestBakeActionsWithNoSessions() {
public function testBakeActionsWithNoSessions() {
$skip = $this->skipIf(!defined('ARTICLE_MODEL_CREATED'),
'Testing bakeActions requires Article, Tag, Comment Models to be undefined. %s');
if ($skip) {
@ -402,7 +402,7 @@ class ControllerTaskTest extends CakeTestCase {
*
* @return void
*/
public function xxtestBakeTest() {
public function testBakeTest() {
$this->Task->plugin = 'ControllerTest';
$this->Task->connection = 'test_suite';
$this->Task->interactive = false;
@ -420,23 +420,26 @@ class ControllerTaskTest extends CakeTestCase {
*
* @return void
*/
public function xxtestInteractive() {
public function testInteractive() {
$this->Task->connection = 'test_suite';
$this->Task->path = '/my/path';
$this->Task->expects($this->any())->method('in')->will($this->returnValue('1'));
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('y')); // build interactive
$this->Task->expects($this->at(2))->method('in')->will($this->returnValue('n')); // build no scaffolds
$this->Task->expects($this->at(3))->method('in')->will($this->returnValue('y')); // build normal methods
$this->Task->expects($this->at(4))->method('in')->will($this->returnValue('n')); // build admin methods
$this->Task->expects($this->at(5))->method('in')->will($this->returnValue('n')); // helpers?
$this->Task->expects($this->at(6))->method('in')->will($this->returnValue('n')); // components?
$this->Task->expects($this->at(7))->method('in')->will($this->returnValue('y')); // use sessions
$this->Task->expects($this->at(8))->method('in')->will($this->returnValue('y')); // looks good
$this->Task->path = '/my/path/';
$this->Task->execute();
$this->Task->expects($this->at(8))->method('in')->will($this->returnValue('1'));
$this->Task->expects($this->at(12))->method('in')->will($this->returnValue('y')); // build interactive
$this->Task->expects($this->at(13))->method('in')->will($this->returnValue('n')); // build no scaffolds
$this->Task->expects($this->at(14))->method('in')->will($this->returnValue('y')); // build normal methods
$this->Task->expects($this->at(15))->method('in')->will($this->returnValue('n')); // build admin methods
$this->Task->expects($this->at(16))->method('in')->will($this->returnValue('n')); // helpers?
$this->Task->expects($this->at(17))->method('in')->will($this->returnValue('n')); // components?
$this->Task->expects($this->at(18))->method('in')->will($this->returnValue('y')); // use sessions
$this->Task->expects($this->at(25))->method('in')->will($this->returnValue('y')); // looks good
$filename = '/my/path/articles_controller.php';
$this->Task->expects($this->at(0))->method('createFile')->with($filename, new PatternExpectation('/class ArticlesController/'));
$this->Task->expects($this->once())->method('createFile')->with(
$filename,
new PHPUnit_Framework_Constraint_PCREMatch('/class ArticlesController/')
);
$this->Task->execute();
}
/**
@ -445,27 +448,32 @@ class ControllerTaskTest extends CakeTestCase {
* @return void
* @access public
*/
function xxtestInteractiveAdminMethodsNotInteractive() {
function testInteractiveAdminMethodsNotInteractive() {
$this->Task->connection = 'test_suite';
$this->Task->interactive = true;
$this->Task->path = '/my/path';
$this->Task->setReturnValue('in', '1');
$this->Task->setReturnValueAt(1, 'in', 'y'); // build interactive
$this->Task->setReturnValueAt(2, 'in', 'n'); // build no scaffolds
$this->Task->setReturnValueAt(3, 'in', 'y'); // build normal methods
$this->Task->setReturnValueAt(4, 'in', 'y'); // build admin methods
$this->Task->setReturnValueAt(5, 'in', 'n'); // helpers?
$this->Task->setReturnValueAt(6, 'in', 'n'); // components?
$this->Task->setReturnValueAt(7, 'in', 'y'); // use sessions
$this->Task->setReturnValueAt(8, 'in', 'y'); // looks good
$this->Task->setReturnValue('createFile', true);
$this->Task->Project->setReturnValue('getPrefix', 'admin_');
$this->Task->path = '/my/path/';
$this->Task->expects($this->at(8))->method('in')->will($this->returnValue('1'));
$this->Task->expects($this->at(12))->method('in')->will($this->returnValue('y')); // build interactive
$this->Task->expects($this->at(13))->method('in')->will($this->returnValue('n')); // build no scaffolds
$this->Task->expects($this->at(14))->method('in')->will($this->returnValue('y')); // build normal methods
$this->Task->expects($this->at(15))->method('in')->will($this->returnValue('y')); // build admin methods
$this->Task->expects($this->at(16))->method('in')->will($this->returnValue('n')); // helpers?
$this->Task->expects($this->at(17))->method('in')->will($this->returnValue('n')); // components?
$this->Task->expects($this->at(18))->method('in')->will($this->returnValue('y')); // use sessions
$this->Task->expects($this->at(25))->method('in')->will($this->returnValue('y')); // looks good
$this->Task->Project->expects($this->any())
->method('getPrefix')
->will($this->returnValue('admin_'));
$filename = '/my/path/articles_controller.php';
$this->Task->expects($this->once())->method('createFile')->with(
$filename,
new PHPUnit_Framework_Constraint_PCREMatch('/class ArticlesController/')
)->will($this->returnValue(true));
$result = $this->Task->execute();
$this->assertPattern('/admin_index/', $result);
$filename = '/my/path/articles_controller.php';
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class ArticlesController/')));
}
/**
@ -473,7 +481,7 @@ class ControllerTaskTest extends CakeTestCase {
*
* @return void
*/
public function xxtestExecuteIntoAll() {
public function testExecuteIntoAll() {
$skip = $this->skipIf(!defined('ARTICLE_MODEL_CREATED'),
'Execute into all could not be run as an Article, Tag or Comment model was already loaded. %s');
if ($skip) {
@ -483,12 +491,14 @@ class ControllerTaskTest extends CakeTestCase {
$this->Task->path = '/my/path/';
$this->Task->args = array('all');
$this->Task->expects($this->any())->method('createFile')->will($this->returnValue(true));
$this->Task->expects($this->any())->method('_checkUnitTest')->will($this->returnValue(true));
$this->Task->Test->expectCallCount('bake', 1);
$this->Task->Test->expects($this->once())->method('bake');
$filename = '/my/path/articles_controller.php';
$this->Task->expects($this->at(0))->method('createFile')->with($filename, new PatternExpectation('/class ArticlesController/'));
$this->Task->expects($this->once())->method('createFile')->with(
$filename,
new PHPUnit_Framework_Constraint_PCREMatch('/class ArticlesController/')
)->will($this->returnValue(true));
$this->Task->execute();
}
@ -498,7 +508,7 @@ class ControllerTaskTest extends CakeTestCase {
*
* @return void
*/
public function xxtestExecuteWithController() {
public function testExecuteWithController() {
$skip = $this->skipIf(!defined('ARTICLE_MODEL_CREATED'),
'Execute with scaffold param requires no Article, Tag or Comment model to be defined. %s');
if ($skip) {
@ -509,19 +519,31 @@ class ControllerTaskTest extends CakeTestCase {
$this->Task->args = array('Articles');
$filename = '/my/path/articles_controller.php';
$this->Task->expectAt(0, 'createFile', array(
$filename, new PatternExpectation('/\$scaffold/')
));
$this->Task->expects($this->once())->method('createFile')->with(
$filename,
new PHPUnit_Framework_Constraint_PCREMatch('/\$scaffold/')
);
$this->Task->execute();
}
/**
* test that both plural and singular forms work for controller baking.
* data provider for testExecuteWithControllerNameVariations
*
* @return void
*/
public function xxtestExecuteWithControllerNameVariations() {
static function nameVariations() {
return array(
array('Articles'), array('Article'), array('article'), array('articles')
);
}
/**
* test that both plural and singular forms work for controller baking.
*
* @dataProvider nameVariations
* @return void
*/
public function testExecuteWithControllerNameVariations($name) {
$skip = $this->skipIf(!defined('ARTICLE_MODEL_CREATED'),
'Execute with scaffold param requires no Article, Tag or Comment model to be defined. %s');
if ($skip) {
@ -529,41 +551,12 @@ class ControllerTaskTest extends CakeTestCase {
}
$this->Task->connection = 'test_suite';
$this->Task->path = '/my/path/';
$this->Task->args = array('Articles');
$this->Task->args = array($name);
$filename = '/my/path/articles_controller.php';
$this->Task->expectAt(0, 'createFile', array(
$filename, new PatternExpectation('/\$scaffold/')
));
$this->Task->execute();
$this->Task->args = array('Article');
$filename = '/my/path/articles_controller.php';
$this->Task->expectAt(1, 'createFile', array(
$filename, new PatternExpectation('/class ArticlesController/')
));
$this->Task->execute();
$this->Task->args = array('article');
$filename = '/my/path/articles_controller.php';
$this->Task->expectAt(2, 'createFile', array(
$filename, new PatternExpectation('/class ArticlesController/')
));
$this->Task->args = array('articles');
$filename = '/my/path/articles_controller.php';
$this->Task->expectAt(3, 'createFile', array(
$filename, new PatternExpectation('/class ArticlesController/')
));
$this->Task->execute();
$this->Task->args = array('Articles');
$filename = '/my/path/articles_controller.php';
$this->Task->expectAt(4, 'createFile', array(
$filename, new PatternExpectation('/class ArticlesController/')
));
$this->Task->execute();
$this->Task->expects($this->once())->method('createFile')->with(
$filename, new PHPUnit_Framework_Constraint_PCREMatch('/\$scaffold/')
);
$this->Task->execute();
}
@ -572,7 +565,7 @@ class ControllerTaskTest extends CakeTestCase {
*
* @return void
*/
public function xxtestExecuteWithPublicParam() {
public function testExecuteWithPublicParam() {
$skip = $this->skipIf(!defined('ARTICLE_MODEL_CREATED'),
'Execute with scaffold param requires no Article, Tag or Comment model to be defined. %s');
if ($skip) {
@ -583,10 +576,10 @@ class ControllerTaskTest extends CakeTestCase {
$this->Task->args = array('Articles', 'public');
$filename = '/my/path/articles_controller.php';
$this->Task->expectAt(0, 'createFile', array(
$filename, new NoPatternExpectation('/var \$scaffold/')
));
$expected = new PHPUnit_Framework_Constraint_Not(new PHPUnit_Framework_Constraint_PCREMatch('/\$scaffold/'));
$this->Task->expects($this->once())->method('createFile')->with(
$filename, $expected
);
$this->Task->execute();
}
@ -595,7 +588,7 @@ class ControllerTaskTest extends CakeTestCase {
*
* @return void
*/
public function xxtestExecuteWithControllerAndBoth() {
public function testExecuteWithControllerAndBoth() {
$skip = $this->skipIf(!defined('ARTICLE_MODEL_CREATED'),
'Execute with scaffold param requires no Article, Tag or Comment model to be defined. %s');
if ($skip) {
@ -607,10 +600,9 @@ class ControllerTaskTest extends CakeTestCase {
$this->Task->args = array('Articles', 'public', 'admin');
$filename = '/my/path/articles_controller.php';
$this->Task->expectAt(0, 'createFile', array(
$filename, new PatternExpectation('/admin_index/')
));
$this->Task->expects($this->once())->method('createFile')->with(
$filename, new PHPUnit_Framework_Constraint_PCREMatch('/admin_index/')
);
$this->Task->execute();
}
@ -619,7 +611,7 @@ class ControllerTaskTest extends CakeTestCase {
*
* @return void
*/
public function xxtestExecuteWithControllerAndAdmin() {
public function testExecuteWithControllerAndAdmin() {
$skip = $this->skipIf(!defined('ARTICLE_MODEL_CREATED'),
'Execute with scaffold param requires no Article, Tag or Comment model to be defined. %s');
if ($skip) {
@ -631,10 +623,9 @@ class ControllerTaskTest extends CakeTestCase {
$this->Task->args = array('Articles', 'admin');
$filename = '/my/path/articles_controller.php';
$this->Task->expectAt(0, 'createFile', array(
$filename, new PatternExpectation('/admin_index/')
));
$this->Task->expects($this->once())->method('createFile')->with(
$filename, new PHPUnit_Framework_Constraint_PCREMatch('/admin_index/')
);
$this->Task->execute();
}
}