In case someone finds this post later, I found an easier way to test html 
tags rather than using assertTags from the view by using assertRegExp or 
assertPattern:

$result = $this->testAction('url', array('return'=>'view'));
$this->assertRegExp('/<input name="data\[Model\]\[field\]"/', $result);

Just remember the pattern passed in as the first param if it uses any 
brackets like the data[Model][field] does you need to escape them first 
otherwise it picks it up as a delimiter. 

I still haven't found a way to test what the setFlash messages are, only 
that the method has been called.

$this->view and $this->contents are always null as well when using redirect.

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

Reply via email to