Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Expanding test cases for ViewTask to be more specific and finer tests…

… for admin_ methods.
  • Loading branch information...
commit 4cb70580a20a179038f70889a65dac6574a45100 1 parent 5441881
@markstory markstory authored
View
2  cake/console/libs/tasks/view.php
@@ -363,7 +363,7 @@ function getContent($template = null, $vars = null) {
$adminRoute = Configure::read('Routing.admin');
if (!empty($adminRoute) && strpos($template, $adminRoute) !== false) {
- $template = str_replace($adminRoute.'_', '', $template);
+ $template = str_replace($adminRoute . '_', '', $template);
}
if (in_array($template, array('add', 'edit'))) {
$action = $template;
View
87 cake/tests/cases/console/libs/tasks/view.test.php
@@ -153,6 +153,37 @@ function testGetContent() {
}
/**
+ * test getContent() using an admin_prefixed action.
+ *
+ * @return void
+ **/
+ function testGetContentWithAdminAction() {
+ Configure::write('Routing.admin', 'admin');
+ $vars = array(
+ 'modelClass' => 'TestViewModel',
+ 'schema' => array(),
+ 'primaryKey' => 'id',
+ 'displayField' => 'name',
+ 'singularVar' => 'testViewModel',
+ 'pluralVar' => 'testViewModels',
+ 'singularHumanName' => 'Test View Model',
+ 'pluralHumanName' => 'Test View Models',
+ 'fields' => array('id', 'name', 'body'),
+ 'associations' => array()
+ );
+ $result = $this->Task->getContent('admin_view', $vars);
+
+ $this->assertPattern('/Delete Test View Model/', $result);
+ $this->assertPattern('/Edit Test View Model/', $result);
+ $this->assertPattern('/List Test View Models/', $result);
+ $this->assertPattern('/New Test View Model/', $result);
+
+ $this->assertPattern('/testViewModel\[\'TestViewModel\'\]\[\'id\'\]/', $result);
+ $this->assertPattern('/testViewModel\[\'TestViewModel\'\]\[\'name\'\]/', $result);
+ $this->assertPattern('/testViewModel\[\'TestViewModel\'\]\[\'body\'\]/', $result);
+ }
+
+/**
* test Bake method
*
* @return void
@@ -201,9 +232,18 @@ function testBakeActions() {
$this->Task->controllerName = 'ViewTaskComments';
$this->Task->controllerPath = 'view_task_comments';
- $this->Task->expectAt(0, 'createFile', array(TMP . 'view_task_comments' . DS . 'view.ctp', '*'));
- $this->Task->expectAt(1, 'createFile', array(TMP . 'view_task_comments' . DS . 'edit.ctp', '*'));
- $this->Task->expectAt(2, 'createFile', array(TMP . 'view_task_comments' . DS . 'index.ctp', '*'));
+ $this->Task->expectAt(0, 'createFile', array(
+ TMP . 'view_task_comments' . DS . 'view.ctp',
+ new PatternExpectation('/ViewTaskComments/')
+ ));
+ $this->Task->expectAt(1, 'createFile', array(
+ TMP . 'view_task_comments' . DS . 'edit.ctp',
+ new PatternExpectation('/Edit ViewTaskComment/')
+ ));
+ $this->Task->expectAt(2, 'createFile', array(
+ TMP . 'view_task_comments' . DS . 'index.ctp',
+ new PatternExpectation('/ViewTaskComment/')
+ ));
$this->Task->bakeActions(array('view', 'edit', 'index'), array());
}
@@ -290,10 +330,22 @@ function testExecuteInteractive() {
$this->Task->setReturnValueAt(2, 'in', 'n');
$this->Task->expectCallCount('createFile', 4);
- $this->Task->expectAt(0, 'createFile', array(TMP . 'view_task_comments' . DS . 'index.ctp', '*'));
- $this->Task->expectAt(1, 'createFile', array(TMP . 'view_task_comments' . DS . 'view.ctp', '*'));
- $this->Task->expectAt(2, 'createFile', array(TMP . 'view_task_comments' . DS . 'add.ctp', '*'));
- $this->Task->expectAt(3, 'createFile', array(TMP . 'view_task_comments' . DS . 'edit.ctp', '*'));
+ $this->Task->expectAt(0, 'createFile', array(
+ TMP . 'view_task_comments' . DS . 'index.ctp',
+ new PatternExpectation('/ViewTaskComment/')
+ ));
+ $this->Task->expectAt(1, 'createFile', array(
+ TMP . 'view_task_comments' . DS . 'view.ctp',
+ new PatternExpectation('/ViewTaskComment/')
+ ));
+ $this->Task->expectAt(2, 'createFile', array(
+ TMP . 'view_task_comments' . DS . 'add.ctp',
+ new PatternExpectation('/Add ViewTaskComment/')
+ ));
+ $this->Task->expectAt(3, 'createFile', array(
+ TMP . 'view_task_comments' . DS . 'edit.ctp',
+ new PatternExpectation('/Edit ViewTaskComment/')
+ ));
$this->Task->execute();
}
@@ -304,6 +356,7 @@ function testExecuteInteractive() {
* @return void
**/
function testExecuteInteractiveWithAdmin() {
+ Configure::write('Routing.admin', 'admin');
$this->Task->connection = 'test_suite';
$this->Task->args = array();
@@ -314,10 +367,22 @@ function testExecuteInteractiveWithAdmin() {
$this->Task->setReturnValueAt(2, 'in', 'y');
$this->Task->expectCallCount('createFile', 4);
- $this->Task->expectAt(0, 'createFile', array(TMP . 'view_task_comments' . DS . 'admin_index.ctp', '*'));
- $this->Task->expectAt(1, 'createFile', array(TMP . 'view_task_comments' . DS . 'admin_view.ctp', '*'));
- $this->Task->expectAt(2, 'createFile', array(TMP . 'view_task_comments' . DS . 'admin_add.ctp', '*'));
- $this->Task->expectAt(3, 'createFile', array(TMP . 'view_task_comments' . DS . 'admin_edit.ctp', '*'));
+ $this->Task->expectAt(0, 'createFile', array(
+ TMP . 'view_task_comments' . DS . 'admin_index.ctp',
+ new PatternExpectation('/ViewTaskComment/')
+ ));
+ $this->Task->expectAt(1, 'createFile', array(
+ TMP . 'view_task_comments' . DS . 'admin_view.ctp',
+ new PatternExpectation('/ViewTaskComment/')
+ ));
+ $this->Task->expectAt(2, 'createFile', array(
+ TMP . 'view_task_comments' . DS . 'admin_add.ctp',
+ new PatternExpectation('/Add ViewTaskComment/')
+ ));
+ $this->Task->expectAt(3, 'createFile', array(
+ TMP . 'view_task_comments' . DS . 'admin_edit.ctp',
+ new PatternExpectation('/Edit ViewTaskComment/')
+ ));
$this->Task->execute();
}
Please sign in to comment.
Something went wrong with that request. Please try again.