As of now when you test the redirect location of an action on a mock
controller you do this.
{{{
$this->assertEquals($this->headers['Location'], 'http://localhost/blog/
posts/index');
}}}
Logged a pull request the other day on this for the 2.0 Cookbook.
https://github.com/cakephp/docs/pull/141
My first thought was to pollute the headers but after another look
today I decided to override testAction and create a new property and
fill it with http://au2.php.net/parse_url.
{{{
protected function _testAction($url = '', $options = array()) {
$return = parent::_testAction($url, $options);
if (isset($this->headers['Location'])) {
$base = $this->controller->base;
$urlParts = parse_url($this->headers['Location']);
$urlParts['location'] = preg_replace("/^\\{$base}/", '',
$urlParts['path']);
$this->redirect = $urlParts;
$this->redirect['base'] = $base;
}
return $return;
}
}}}
Then I can go like this
{{{
$this->assertEquals($this->redirect['location'], '/posts/index');
}}}
Will asserting redirects be cleaned up in the near future?
That was the only thing I did not like from my first test run of Cake
2.0, everything else so far went smoothly.
kind regards,
Leigh
--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
No comments:
Post a Comment