Tag Archive: zend form


It’s sunday and I’m playing with Zend_Test. Here are some basic things that took me time to find out :
Grep simple text in the page :

  1. $this->assertQueryContentContains(‘body’, “your email is invalid”);

Verify unvalid users can not log in :

  1. $this->request->setMethod(‘POST’)
  2. ->setPost(array(
  3. ’email’ => ‘fakeaddress@fakedomain.com’,
  4. ‘password’ => ‘fakepassw’
  5. ));
  6. $this->dispatch(‘/user/login’);
  7. $this->assertNotRedirect();
  8. $this->assertFalse(Zend_Auth::getInstance()->hasIdentity());

The interesting part is the last part :

  1. $this->assertFalse(Zend_Auth::getInstance()->hasIdentity());

And, let’s test a form :

  1. $this->assertQueryCountMin(‘form’, 1);
  2. $this->assertQueryCountMin(‘input[name~=”email”]’, 1);
  3. $this->assertQueryCountMin(‘input[name~=”password”]’, 1);
  4. $this->assertQueryCountMin(‘input[name~=”submit”]’, 1);

Nothing fancy here, only some tips that can only make your discovering of Zend_Test easyer ! Happy testing !

Advertisements

The integration of Dojo in the Zend Framework is very nice, it allows us to play with some nice features of this library. Well, let’s get to work, and build a simple login form :

  1. class  LoginForm extends Zend_Dojo_Form
  2. {
  3. public function init()
  4. {
  5. // Dojo-enable the form:
  6. Zend_Dojo::enableForm($this);
  7. $this->setName(‘Login’);
  8. $this->setAction(‘/user/login’)
  9. ->setMethod(‘post’);
  10. // EMAIL
  11. $this->addElement(
  12. ‘ValidationTextBox’,
  13. ’email’,
  14. array(
  15. ‘value’      => ”,
  16. ‘label’      => ‘Email address : ‘,
  17. ‘trim’       => true,
  18. ‘lowercase’  => true,
  19. ‘required’   => true,
  20. ‘regExp’         => ‘^.{4,}$’,
  21. ‘invalidMessage’ => ‘Insert your email’,
  22. ‘validators’ => array(
  23. ‘EmailAddress’,
  24. array(‘StringLength’, false, 4)
  25. ),
  26. ‘filters’  => array(‘StringToLower’),
  27. )
  28. );
  29. // PASSWORD
  30. $this->addElement(
  31. ‘PasswordTextBox’,
  32. ‘password’,
  33. array(
  34. ‘label’          => ‘Password’,
  35. ‘required’       => true,
  36. ‘trim’           => true,
  37. ‘regExp’         => ‘^.{4,}$’,
  38. ‘invalidMessage’ => ‘Invalid password’,
  39. ‘validators’  => array(array(‘StringLength’, false, 4))
  40. )
  41. );
  42. // SUBMIT
  43. $this->addElement(
  44. ‘SubmitButton’,
  45. ‘submit’,
  46. array(
  47. ‘required’   => false,
  48. ‘ignore’     => true,
  49. ‘label’      => ‘Submit Button!’,
  50. )
  51. );
  52. }
  53. }

And it’s pretty straight forward to use :

  1. // initialize the
  2. form = new LoginForm();