You check it just like in the controller.
function testCookieWrite() {
$this->testAction('/posts/action_that_writes_to_cookie');
$result = $this->controller->Cookie->read('my_cookie_value');
$expected = 'yes';
$this->assertEquals($expected, $result);
}
Of course, you can always mock the cookie so it doesn't actually write.
Then assert that the write method gets called.
function testCookieWrite() {
$Posts = $this->generate('Posts', array(
'components' => array(
'Cookie' => array('write')
)
));
// assert that Cookie::write() gets called once
$Posts->Cookie->expects($this->once())->method('write');
$this->testAction('/posts/action_that_writes_to_cookie');
}
On Tuesday, August 14, 2012 2:02:51 PM UTC-7, Aaron Smyth wrote:
>
> I'm setting up tests for my controllers, and I'm trying to make sure that
> during its execution, a method is actually setting a cookie. I can't seem
> to validate this in the test I'm writing. Does anyone have any thoughts on
> how I might check Cookie values from within a test case?
--
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.