Consider this code:
Controller code
<?php App::uses('AppController', 'Controller'); class UsersController extends AppController { public $components = array( 'Security', 'Session' ); public function example() { if ($this->request->is('post')) { $this->set('some_var', true); } } }
Code view
<?php echo $this->Form->create(); echo $this->Form->input('name'); echo $this->Form->end('Submit');
Since I have the Security component in place, somehow changing the form (for example, adding a field to it), the request will be black. I would like to check this out:
Test code
<?php class UsersControllerTest extends ControllerTestCase { public function testExamplePostValidData() { $this->Controller = $this->generate('Users', array( 'components' => array( 'Security' ) )); $data = array( 'User' => array( 'name' => 'John Doe' ) ); $this->testAction('/users/example', array('data' => $data, 'method' => 'post')); $this->assertTrue($this->vars['some_var']); } public function testExamplePostInvalidData() { $this->Controller = $this->generate('Users', array( 'components' => array( 'Security' ) )); $data = array( 'User' => array( 'name' => 'John Doe', 'some_field' => 'The existence of this should cause the request to be black-holed.' ) ); $this->testAction('/users/example', array('data' => $data, 'method' => 'post')); $this->assertTrue($this->vars['some_var']); } }
The second test testExamplePostInvalidData should fail because some_field is in the $data array, but it passes! What am I doing wrong?
Nick source share