Quantcast

Zend_Test_PHPUnit and hashed form elements

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Zend_Test_PHPUnit and hashed form elements

Tobias Schifftner
Hello there,

is there a way of testing forms containing a Zend_Form_Element_Hash? For example when you have a login form.

Thx,
Tobias
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Zend_Test_PHPUnit and hashed form elements

weierophinney
Administrator
-- Milchbazi <[hidden email]> wrote
(on Sunday, 03 August 2008, 12:53 AM -0700):
> is there a way of testing forms containing a Zend_Form_Element_Hash? For
> example when you have a login form.

You may need to specify an alternate Zend_Session_Namespace extension to
ensure the hops are expired correctly; you may want to look at the Hash
unit tests to see how Stas tested that component.

--
Matthew Weier O'Phinney
Software Architect       | [hidden email]
Zend Framework           | http://framework.zend.com/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Zend_Test_PHPUnit and hashed form elements

Tobias Schifftner
Hello Matthew,

thanks for your answer. But I don't actually try to test the hashed element. I just wanna test a form containing it. But whenever a form contains a hash element, I'm unable to process the form. For example the login form:

        $form = new Zend_Form(array(
            'action'   => '/login',
            'method'   => 'post',
            'name'   => 'loginForm',
            'elements' => array(
                'username' => array('text', array(
                    'validators' => array(
                        'alnum',
                        array('regex', false, array('/^[a-z]/i')),
                        array('stringLength', false, array(6, 20))
                    ),
                    'required' => true,
                    'label' => 'Username',
                    'filters'  => array('StringToLower'),
                 )),
                'password' => array('password', array(
                    'validators' => array(
                        array('stringLength', false, array(6))
                    ),
                    'required' => true,
                    'label' => 'Password',
                )),
                #'hash' => 'hash',
                'submit' => 'submit',
                )
            ));



    function testLogin()
    {
        $this->dispatch('/');
        $this->request
             ->setMethod('POST')
             ->setPost(array(
                 'username' => 'username',
                 'password' => 'password'
             ));
        $this->dispatch('/login');
        $this->assertModule('ucp');
        $this->assertController('auth');
        $this->assertAction('login');
        $this->assertRedirectTo('/');
        $this->dispatch('/');
        $this->assertTrue(Zend_Auth::getInstance()->hasIdentity());
        $this->assertEquals((int) User::get('userId'), 1);
        $this->resetResponse();
        $this->request->setPost(array());
    }

As soon as I disable the hash element it processes fine. Any ideas?

By the way: Thanks for the great work on ZF - it's really awesome!

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Zend_Test_PHPUnit and hashed form elements

weierophinney
Administrator
-- Milchbazi <[hidden email]> wrote
(on Monday, 04 August 2008, 08:32 AM -0700):
> thanks for your answer. But I don't actually try to test the hashed element.
> I just wanna test a form containing it. But whenever a form contains a hash
> element, I'm unable to process the form. For example the login form:

I recommended looking at the Hash element tests as they may give you an
idea of how to write tests against forms that contain a Hash element
that will work with the controller test cases.

I'll see if I can find a solution, but you'll likely need to wait until
after the 1.6 final release.

>         $form = new Zend_Form(array(
>             'action'   => '/login',
>             'method'   => 'post',
>             'name'   => 'loginForm',
>             'elements' => array(
>                 'username' => array('text', array(
>                     'validators' => array(
>                         'alnum',
>                         array('regex', false, array('/^[a-z]/i')),
>                         array('stringLength', false, array(6, 20))
>                     ),
>                     'required' => true,
>                     'label' => 'Username',
>                     'filters'  => array('StringToLower'),
>                  )),
>                 'password' => array('password', array(
>                     'validators' => array(
>                         array('stringLength', false, array(6))
>                     ),
>                     'required' => true,
>                     'label' => 'Password',
>                 )),
>                 #'hash' => 'hash',
>                 'submit' => 'submit',
>                 )
>             ));
>
>
>
>     function testLogin()
>     {
>         $this->dispatch('/');
>         $this->request
>              ->setMethod('POST')
>              ->setPost(array(
>                  'username' => 'username',
>                  'password' => 'password'
>              ));
>         $this->dispatch('/login');
>         $this->assertModule('ucp');
>         $this->assertController('auth');
>         $this->assertAction('login');
> $this->assertRedirectTo('/');
>         $this->dispatch('/');
>         $this->assertTrue(Zend_Auth::getInstance()->hasIdentity());
>         $this->assertEquals((int) User::get('userId'), 1);
>         $this->resetResponse();
>         $this->request->setPost(array());
>     }
>
> As soon as I disable the hash element it processes fine. Any ideas?
>
> By the way: Thanks for the great work on ZF - it's really awesome!
>
>
> --
> View this message in context: http://www.nabble.com/Zend_Test_PHPUnit-and-hashed-form-elements-tp18796568p18813545.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>

--
Matthew Weier O'Phinney
Software Architect       | [hidden email]
Zend Framework           | http://framework.zend.com/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Zend_Test_PHPUnit and hashed form elements

Tobias Schifftner
Ah, ok. Now I see what you mean. I looked at it and it seems that you have to provide a valid hash taken from the session. This would be a way, but in my opinion tests should not contain more information as a user has with a browser. When I write a form this form should work the same way in the browser as in the PHPUnit_TestCase. Don't you think?

Well, may be I'm totally wrong here. Let's see what the 1.6 final release will bring. ;-)
Thank you!


 
Matthew Weier O'Phinney-3 wrote
-- Milchbazi <tobias@schifftner.de> wrote
(on Monday, 04 August 2008, 08:32 AM -0700):
> thanks for your answer. But I don't actually try to test the hashed element.
> I just wanna test a form containing it. But whenever a form contains a hash
> element, I'm unable to process the form. For example the login form:

I recommended looking at the Hash element tests as they may give you an
idea of how to write tests against forms that contain a Hash element
that will work with the controller test cases.

I'll see if I can find a solution, but you'll likely need to wait until
after the 1.6 final release.

>         $form = new Zend_Form(array(
>             'action'   => '/login',
>             'method'   => 'post',
>             'name'   => 'loginForm',
>             'elements' => array(
>                 'username' => array('text', array(
>                     'validators' => array(
>                         'alnum',
>                         array('regex', false, array('/^[a-z]/i')),
>                         array('stringLength', false, array(6, 20))
>                     ),
>                     'required' => true,
>                     'label' => 'Username',
>                     'filters'  => array('StringToLower'),
>                  )),
>                 'password' => array('password', array(
>                     'validators' => array(
>                         array('stringLength', false, array(6))
>                     ),
>                     'required' => true,
>                     'label' => 'Password',
>                 )),
>                 #'hash' => 'hash',
>                 'submit' => 'submit',
>                 )
>             ));
>
>
>
>     function testLogin()
>     {
>         $this->dispatch('/');
>         $this->request
>              ->setMethod('POST')
>              ->setPost(array(
>                  'username' => 'username',
>                  'password' => 'password'
>              ));
>         $this->dispatch('/login');
>         $this->assertModule('ucp');
>         $this->assertController('auth');
>         $this->assertAction('login');
> $this->assertRedirectTo('/');
>         $this->dispatch('/');
>         $this->assertTrue(Zend_Auth::getInstance()->hasIdentity());
>         $this->assertEquals((int) User::get('userId'), 1);
>         $this->resetResponse();
>         $this->request->setPost(array());
>     }
>
> As soon as I disable the hash element it processes fine. Any ideas?
>
> By the way: Thanks for the great work on ZF - it's really awesome!
>
>
> --
> View this message in context: http://www.nabble.com/Zend_Test_PHPUnit-and-hashed-form-elements-tp18796568p18813545.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>

--
Matthew Weier O'Phinney
Software Architect       | matthew@zend.com
Zend Framework           | http://framework.zend.com/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Zend_Test_PHPUnit and hashed form elements

weierophinney
Administrator
-- Milchbazi <[hidden email]> wrote
(on Monday, 04 August 2008, 09:54 AM -0700):
> Ah, ok. Now I see what you mean. I looked at it and it seems that you have to
> provide a valid hash taken from the session. This would be a way, but in my
> opinion tests should not contain more information as a user has with a
> browser. When I write a form this form should work the same way in the
> browser as in the PHPUnit_TestCase. Don't you think?
>
> Well, may be I'm totally wrong here. Let's see what the 1.6 final release
> will bring. ;-)

As I noted, I have limited time to work on this particular issue, and
have no other issues logged against Zend_Test_PHPUnit. If you can come
up with an adequate solution, I'll gladly patch; otherwise, post an
issue, and I'll look into it following the 1.6.0 final release.


> Matthew Weier O'Phinney-3 wrote:
> >
> > -- Milchbazi <[hidden email]> wrote
> > (on Monday, 04 August 2008, 08:32 AM -0700):
> >> thanks for your answer. But I don't actually try to test the hashed
> >> element.
> >> I just wanna test a form containing it. But whenever a form contains a
> >> hash
> >> element, I'm unable to process the form. For example the login form:
> >
> > I recommended looking at the Hash element tests as they may give you an
> > idea of how to write tests against forms that contain a Hash element
> > that will work with the controller test cases.
> >
> > I'll see if I can find a solution, but you'll likely need to wait until
> > after the 1.6 final release.
> >
> >>         $form = new Zend_Form(array(
> >>             'action'   => '/login',
> >>             'method'   => 'post',
> >>             'name'   => 'loginForm',
> >>             'elements' => array(
> >>                 'username' => array('text', array(
> >>                     'validators' => array(
> >>                         'alnum',
> >>                         array('regex', false, array('/^[a-z]/i')),
> >>                         array('stringLength', false, array(6, 20))
> >>                     ),
> >>                     'required' => true,
> >>                     'label' => 'Username',
> >>                     'filters'  => array('StringToLower'),
> >>                  )),
> >>                 'password' => array('password', array(
> >>                     'validators' => array(
> >>                         array('stringLength', false, array(6))
> >>                     ),
> >>                     'required' => true,
> >>                     'label' => 'Password',
> >>                 )),
> >>                 #'hash' => 'hash',
> >>                 'submit' => 'submit',
> >>                 )
> >>             ));
> >>
> >>
> >>
> >>     function testLogin()
> >>     {
> >>         $this->dispatch('/');
> >>         $this->request
> >>              ->setMethod('POST')
> >>              ->setPost(array(
> >>                  'username' => 'username',
> >>                  'password' => 'password'
> >>              ));
> >>         $this->dispatch('/login');
> >>         $this->assertModule('ucp');
> >>         $this->assertController('auth');
> >>         $this->assertAction('login');
> >> $this->assertRedirectTo('/');
> >>         $this->dispatch('/');
> >>         $this->assertTrue(Zend_Auth::getInstance()->hasIdentity());
> >>         $this->assertEquals((int) User::get('userId'), 1);
> >>         $this->resetResponse();
> >>         $this->request->setPost(array());
> >>     }
> >>
> >> As soon as I disable the hash element it processes fine. Any ideas?
> >>
> >> By the way: Thanks for the great work on ZF - it's really awesome!
> >>
> >>
> >> --
> >> View this message in context:
> >> http://www.nabble.com/Zend_Test_PHPUnit-and-hashed-form-elements-tp18796568p18813545.html
> >> Sent from the Zend Framework mailing list archive at Nabble.com.
> >>
> >
> > --
> > Matthew Weier O'Phinney
> > Software Architect       | [hidden email]
> > Zend Framework           | http://framework.zend.com/
> >
> >
>
> --
> View this message in context: http://www.nabble.com/Zend_Test_PHPUnit-and-hashed-form-elements-tp18796568p18815186.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>

--
Matthew Weier O'Phinney
Software Architect       | [hidden email]
Zend Framework           | http://framework.zend.com/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Zend_Test_PHPUnit and hashed form elements

Tobias Schifftner
This issue has been added to Zend Framework Issue Tracker. See http://framework.zend.com/issues/browse/ZF-3869

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Zend_Test_PHPUnit and hashed form elements

weierophinney
Administrator
-- Milchbazi <[hidden email]> wrote
(on Wednesday, 06 August 2008, 05:22 AM -0700):
>
> This issue has been added to Zend Framework Issue Tracker. See
> http://framework.zend.com/issues/browse/ZF-3869
> http://framework.zend.com/issues/browse/ZF-3869 

Excellent, thanks. I'll see if I can address it today; if not, at the
latest we'll likely have a mini-release in a week or so after the 1.6.0
final release.

--
Matthew Weier O'Phinney
Software Architect       | [hidden email]
Zend Framework           | http://framework.zend.com/
Loading...