I figured out how to test for an exact flash message. For instance a mocked
up Posts controllers add action, testing a flash message of 'Post
successfully saved':
$Posts->Session->expects($this->once())->method('setFlash')->with($this->equalTo('Post
successfully saved'));
$Posts of course is your mock.
This may help someone some day.
On Saturday, March 10, 2012 7:56:37 PM UTC-8, andrewperk wrote:
>
> Hello,
>
> I have a couple of questions about testing certain things:
>
> Flash Messages: I know how to test that the setFlash method has ran
> using mocks, but is there a way to verify that it contains the correct
> message?
>
> assertTags() Views: I use testAction to return the view then use
> assertTags to test that the view contains certain HTML. But, Is there
> a way to just test that the view contains only a part of the html
> rather than having to test the whole view?
>
> Currently when I use assertTags I have to be exact, all the way down
> to the attribute of the element and any nested elements. I would just
> like to test that a view contains just a few elements on the page, not
> every single one with all attributes as this takes forever to build
> out this array on a complex view.
>
> For instance, I would just like to test that the view contains a
> certain input with an id of post_id, but I can't do this if any html
> comes before it, it wants me to match the entire thing.
>
> $result = $this->testAction('/url/page_with_form',
> array('return'=>'view'));
> $expected = array(
> array('input'=>array('id'=>'post_id')),
> );
>
> This will not work because I didn't include the array structure for
> the form thats wrapped around it, if I add the entire form and all the
> divs that the form helper generates it works just fine.
>
> Thanks,
>
> Andrew
>
>
>
>
>
--
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
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php