I am trying to test the action of a controller that allows user profiles to be released. Among other things, I want to check that each registered user can edit his profile, and not another. In case of violation of this restriction, the action should be redirected to the predefined home page.
In this scenario, I have a device that creates a user with ID = 1. Therefore, I thought about testing the constraint this way:
$data = $this->Users->User->read(null, 1);
$this->Users->Auth->login($data);
$this->testAction('/users/edit/2', array('method' => 'get'));
$url = parse_url($this->headers['Location']);
$this->assertEquals($url['path'], '/homepage');
The test passes this statement. So, the next step is to verify the execution '/users/edit/1', which has a registered user ID, shows the form:
$this->testAction('/users/edit/1', array('method' => 'get', 'return' => 'vars'));
$matcher = array(
'tag' => 'form',
'ancestor' => array('tag' => 'div'),
'descendant' => array('tag' => 'fieldset'),
);
$this->assertTag($matcher, $this->vars['content_for_layout'], 'The edition form was not found');
. debug() , $this->Auth->user() , $this->Auth->user('id') null. ,
test to fail.
, , . , ?
!