Tuesday, March 4, 2014

Unit testing and redirects within an exception

Hi

I have a unit test here, and it is failing. The headers['location'] key does not have a value in it when the Product->edit() method raises the exception, even though I still call redirect within the catch. Is this expected behavior?

If I put the redirect before or after the try...catch blog, the headers['location'] has a value, this problem only seems to occur when inside the exception handler.

Can anyone possibly tell me what I might be doing wrong here?

Many thanks
Richard

The test:

$postData = array(
    'Product' => array(
        'id' => ProductTest::TEST_PRODUCT_ONE, price' => 100
    ));
$this->testAction('/admin/products/update', array('data' => $postData));
$this->assertContains('/admin/products/edit', $this->headers['Location']);

The controller:


try {
    if ($this->Product->edit($this->request->data)) {
        return $this->redirect(array('action' => 'edit', $this->Product->id));
    }
}
catch (DomainException $quotaException) {
$this->Session->setFlash(....);
        return $this->redirect(array('action' => 'edit', $this->Product->id));
}

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: