Wednesday, August 24, 2011

Re: What is the proper way of testing controllers in CakePHP 2.0

No, $this->headers seems to always return an empty array

On 25 Aug, 06:02, jeremyharris <funeralm...@gmail.com> wrote:
> When you debug the $this->headers var, what do you get back? Anything
> at all?
>
> If you're not getting anything back then it might be a problem with
> testAction, although there are tests that show it works.
>
> On Aug 21, 1:48 am, Christophe Roblin <crob...@lionsek.com> wrote:
>
>
>
>
>
>
>
> > Hi,
>
> > I've tried searching the new docs about testing with the new PHPUnit
> > for CakePHP 2.0 Beta, without any success
> > Below is my code for testing the admin action of controller posts with
> > method add.
>
> > My issue is that I expected from the docs I received that headers were
> > set when using testAction, it is always blank
>
> >         public function testAdminAdd() {
> >             $Posts = $this->generate('Posts', array(
> >                 'components' => array(
> >                     'Session'
> >                     )
> >                 )
> >             );
>
> >             $Posts->Session->expects($this->once())-
>
> > >method('setFlash');
>
> >             $this->testAction('/admin/posts/add', array(
> >                 'data' => array(
> >                     'Post' => array('name' => 'New Post')
> >                     )
> >                 )
> >             );
> >            // debug($this);
> >             $this->assertEquals($this->headers['Location'], '/admin/
> > posts/index');
> >             $this->assertEquals($this->vars['post']['Post']['name'],
> > 'New Post');
>
> >             $this->assertPattern('/<html/', $this->contents);
> >             $this->assertPattern('/<form/', $this->view);

--
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: