Skip to content

Commit

Permalink
Fixing double output issues with Scaffold.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Jul 28, 2011
1 parent 8f38065 commit f9373ff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
15 changes: 0 additions & 15 deletions lib/Cake/Controller/Scaffold.php
Expand Up @@ -152,16 +152,6 @@ public function __construct(Controller $controller, CakeRequest $request) {
$this->_scaffold($request);
}

/**
* Outputs the content of a scaffold method passing it through the Controller::afterFilter()
*
* @return void
*/
protected function _output() {
$this->controller->afterFilter();
$this->controller->response->send();
}

/**
* Renders a view action of scaffolded model.
*
Expand All @@ -182,7 +172,6 @@ protected function _scaffoldView(CakeRequest $request) {
Inflector::variable($this->controller->modelClass), $this->request->data
);
$this->controller->render($this->request['action'], $this->layout);
$this->_output();
} elseif ($this->controller->_scaffoldError('view') === false) {
return $this->_scaffoldError();
}
Expand All @@ -201,7 +190,6 @@ protected function _scaffoldIndex($params) {
Inflector::variable($this->controller->name), $this->controller->paginate()
);
$this->controller->render($this->request['action'], $this->layout);
$this->_output();
} elseif ($this->controller->_scaffoldError('index') === false) {
return $this->_scaffoldError();
}
Expand All @@ -219,7 +207,6 @@ protected function _scaffoldForm($action = 'edit') {
array_keys($this->ScaffoldModel->hasAndBelongsToMany)
);
$this->controller->render($action, $this->layout);
$this->_output();
}

/**
Expand Down Expand Up @@ -343,7 +330,6 @@ protected function _sendMessage($message) {
$this->controller->redirect($this->redirect);
} else {
$this->controller->flash($message, $this->redirect);
$this->_output();
}
}

Expand All @@ -354,7 +340,6 @@ protected function _sendMessage($message) {
*/
protected function _scaffoldError() {
return $this->controller->render('error', $this->layout);
$this->_output();
}

/**
Expand Down
12 changes: 11 additions & 1 deletion lib/Cake/Test/Case/Controller/ScaffoldTest.php
Expand Up @@ -427,6 +427,7 @@ public function testIndexScaffold() {
$this->Controller->constructClasses();
ob_start();
new Scaffold($this->Controller, $this->Controller->request);
$this->Controller->response->send();
$result = ob_get_clean();

$this->assertPattern('#<h2>Scaffold Mock</h2>#', $result);
Expand Down Expand Up @@ -466,6 +467,7 @@ public function testViewScaffold() {

ob_start();
new Scaffold($this->Controller, $this->Controller->request);
$this->Controller->response->send();
$result = ob_get_clean();

$this->assertPattern('/<h2>View Scaffold Mock<\/h2>/', $result);
Expand Down Expand Up @@ -506,11 +508,13 @@ public function testEditScaffold() {
Router::reload();
Router::setRequestInfo($this->Controller->request);
$this->Controller->constructClasses();

ob_start();
new Scaffold($this->Controller, $this->Controller->request);
$this->Controller->response->send();
$result = ob_get_clean();

$this->assertContains('<form id="ScaffoldMockEditForm" method="post" action="/scaffold_mock/edit/1"', $result);
$this->assertContains('<form action="/scaffold_mock/edit/1" id="ScaffoldMockEditForm" method="post"', $result);
$this->assertContains('<legend>Edit Scaffold Mock</legend>', $result);

$this->assertContains('input type="hidden" name="data[ScaffoldMock][id]" value="1" id="ScaffoldMockId"', $result);
Expand Down Expand Up @@ -556,6 +560,7 @@ public function testAdminIndexScaffold() {

ob_start();
$Scaffold = new Scaffold($this->Controller, $this->Controller->request);
$this->Controller->response->send();
$result = ob_get_clean();

$this->assertPattern('/<h2>Scaffold Mock<\/h2>/', $result);
Expand Down Expand Up @@ -599,6 +604,7 @@ public function testAdminEditScaffold() {

ob_start();
$Scaffold = new Scaffold($this->Controller, $this->Controller->request);
$this->Controller->response->send();
$result = ob_get_clean();

$this->assertPattern('#admin/scaffold_mock/edit/1#', $result);
Expand Down Expand Up @@ -640,6 +646,7 @@ public function testMultiplePrefixScaffold() {

ob_start();
$Scaffold = new Scaffold($this->Controller, $this->Controller->request);
$this->Controller->response->send();
$result = ob_get_clean();

$this->assertPattern('/<h2>Scaffold Mock<\/h2>/', $result);
Expand Down Expand Up @@ -817,6 +824,7 @@ public function testScaffoldFlashMessages() {

ob_start();
new Scaffold($this->Controller, $this->Controller->request);
$this->Controller->response->send();
$result = ob_get_clean();
$this->assertPattern('/Scaffold Mock has been updated/', $result);
}
Expand Down Expand Up @@ -848,6 +856,7 @@ function testHabtmFieldAdditionWithScaffoldForm() {
$this->Controller->constructClasses();
ob_start();
$Scaffold = new Scaffold($this->Controller, $this->Controller->request);
$this->Controller->response->send();
$result = ob_get_clean();
$this->assertPattern('/name="data\[ScaffoldTag\]\[ScaffoldTag\]"/', $result);

Expand Down Expand Up @@ -885,6 +894,7 @@ public function testEditScaffoldWithScaffoldFields() {
$this->Controller->constructClasses();
ob_start();
new Scaffold($this->Controller, $this->Controller->request);
$this->Controller->response->send();
$result = ob_get_clean();

$this->assertNoPattern('/textarea name="data\[ScaffoldMock\]\[body\]" cols="30" rows="6" id="ScaffoldMockBody"/', $result);
Expand Down

0 comments on commit f9373ff

Please sign in to comment.