From 45a23650172cba7d65a62335cb225c57e3bdaf4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Gallego?= Date: Wed, 26 Jun 2013 11:02:25 +0200 Subject: [PATCH 1/9] Separate form and input filters --- config/module.config.php | 3 +- .../Form/Factory/RegistrationFormFactory.php | 6 +- .../Form/Factory/UserFieldsetFactory.php | 39 +++++++++ src/BaconUser/Form/User/RegistrationForm.php | 59 +++++++++++++ ...{RegistrationForm.php => UserFieldset.php} | 31 ++++--- .../InputFilter/RegistrationFilter.php | 81 ++++-------------- src/BaconUser/InputFilter/UserFilter.php | 84 +++++++++++++++++++ 7 files changed, 219 insertions(+), 84 deletions(-) create mode 100644 src/BaconUser/Form/Factory/UserFieldsetFactory.php create mode 100644 src/BaconUser/Form/User/RegistrationForm.php rename src/BaconUser/Form/{RegistrationForm.php => UserFieldset.php} (79%) create mode 100644 src/BaconUser/InputFilter/UserFilter.php diff --git a/config/module.config.php b/config/module.config.php index 67caa51..0597917 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -33,7 +33,8 @@ 'form_elements' => array( 'factories' => array( - 'BaconUser\Form\RegistrationForm' => 'BaconUser\Form\Factory\RegistrationFormFactory' + 'BaconUser\Form\UserFieldset' => 'BaconUser\Form\Factory\UserFieldsetFactory', + 'BaconUser\Form\User\RegistrationForm' => 'BaconUser\Form\Factory\RegistrationFormFactory' ) ), diff --git a/src/BaconUser/Form/Factory/RegistrationFormFactory.php b/src/BaconUser/Form/Factory/RegistrationFormFactory.php index 6766b03..ec826f3 100644 --- a/src/BaconUser/Form/Factory/RegistrationFormFactory.php +++ b/src/BaconUser/Form/Factory/RegistrationFormFactory.php @@ -9,7 +9,7 @@ namespace BaconUser\Form\Factory; -use BaconUser\Form\RegistrationForm; +use BaconUser\Form\User\RegistrationForm; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; @@ -28,10 +28,8 @@ class RegistrationFormFactory implements FactoryInterface public function createService(ServiceLocatorInterface $serviceLocator) { $parentLocator = $serviceLocator->getServiceLocator(); - $options = $parentLocator->get('BaconUser\Options\UserOptions'); - $form = new RegistrationForm($options); - $form->setHydrator($parentLocator->get('HydratorManager')->get('BaconUser\Hydrator\RegistrationHydrator')); + $form = new RegistrationForm(); $form->setInputFilter($parentLocator->get('InputFilterManager')->get('BaconUser\InputFilter\RegistrationFilter')); return $form; diff --git a/src/BaconUser/Form/Factory/UserFieldsetFactory.php b/src/BaconUser/Form/Factory/UserFieldsetFactory.php new file mode 100644 index 0000000..b252a85 --- /dev/null +++ b/src/BaconUser/Form/Factory/UserFieldsetFactory.php @@ -0,0 +1,39 @@ +getServiceLocator(); + $options = $parentLocator->get('BaconUser\Options\UserOptions'); + + $fieldset = new UserFieldset($options); + $fieldset->setHydrator($parentLocator->get('HydratorManager')->get('BaconUser\Hydrator\RegistrationHydrator')); + //$fieldset->setInputFilter($parentLocator->get('InputFilterManager')->get('BaconUser\InputFilter\RegistrationFilter')); + + return $fieldset; + } +} diff --git a/src/BaconUser/Form/User/RegistrationForm.php b/src/BaconUser/Form/User/RegistrationForm.php new file mode 100644 index 0000000..8b94f12 --- /dev/null +++ b/src/BaconUser/Form/User/RegistrationForm.php @@ -0,0 +1,59 @@ +add(array( + 'type' => 'BaconUser\Form\UserFieldset', + 'name' => 'user', + 'options' => array( + 'use_as_base_fieldset' => true + ) + )); + + $this->add(array( + 'type' => 'Csrf', + 'name' => 'csrf' + )); + + $this->add(array( + 'type' => 'Submit', + 'name' => 'submit', + 'options' => array( + 'label' => 'Register', + ) + )); + + // Add specific registration elements + + $userFieldset = $this->get('user'); + $userFieldset->add(array( + 'type' => 'Password', + 'name' => 'password_verification', + 'options' => array( + 'label' => 'Verify password' + ), + 'attributes' => array( + 'required' => 'required' + ) + )); + } +} diff --git a/src/BaconUser/Form/RegistrationForm.php b/src/BaconUser/Form/UserFieldset.php similarity index 79% rename from src/BaconUser/Form/RegistrationForm.php rename to src/BaconUser/Form/UserFieldset.php index 12551fe..aef9103 100644 --- a/src/BaconUser/Form/RegistrationForm.php +++ b/src/BaconUser/Form/UserFieldset.php @@ -10,16 +10,21 @@ namespace BaconUser\Form; use BaconUser\Options\UserOptionsInterface; -use Zend\Form\Form; +use Zend\Form\Fieldset; /** - * Generic registration form. + * Base fieldset for user */ -class RegistrationForm extends Form +class UserFieldset extends Fieldset { + /** + * Constructor + * + * @param UserOptionsInterface $options + */ public function __construct(UserOptionsInterface $options) { - parent::__construct(null); + parent::__construct('user'); if ($options->getEnableUsername()) { $this->add(array( @@ -28,19 +33,20 @@ public function __construct(UserOptionsInterface $options) 'label' => 'Username', ), 'attributes' => array( - 'type' => 'text', + 'required' => 'required', ), )); } $this->add(array( + 'type' => 'Email', 'name' => 'email', 'options' => array( 'label' => 'Email', ), 'attributes' => array( - 'type' => 'text' - ), + 'required' => 'required' + ) )); if ($options->getEnableDisplayName()) { @@ -50,21 +56,22 @@ public function __construct(UserOptionsInterface $options) 'label' => 'Display name', ), 'attributes' => array( - 'type' => 'text' + 'required' => 'required' ), )); } $this->add(array( + 'type' => 'Password', 'name' => 'password', 'options' => array( 'label' => 'Password', ), 'attributes' => array( - 'type' => 'password' - ), + 'required' => 'required' + ) )); - +/* $this->add(array( 'name' => 'password_verification', 'options' => array( @@ -85,6 +92,6 @@ public function __construct(UserOptionsInterface $options) ), ), array( 'priority' => -100 - )); + ));*/ } } diff --git a/src/BaconUser/InputFilter/RegistrationFilter.php b/src/BaconUser/InputFilter/RegistrationFilter.php index b482ae3..9a221ef 100644 --- a/src/BaconUser/InputFilter/RegistrationFilter.php +++ b/src/BaconUser/InputFilter/RegistrationFilter.php @@ -10,13 +10,12 @@ namespace BaconUser\InputFilter; use BaconUser\Options\UserOptionsInterface; -use Zend\InputFilter\InputFilter; use Zend\Validator\ValidatorInterface; /** * Input filter for the {@see RegistrationForm}. */ -class RegistrationFilter extends InputFilter +class RegistrationFilter extends UserFilter { /** * @param ValidatorInterface $emailUniqueValidator @@ -28,85 +27,33 @@ public function __construct( ValidatorInterface $usernameUniqueValidator, UserOptionsInterface $options ) { - if ($options->getEnableUsername()) { - $this->add(array( - 'name' => 'username', - 'required' => true, - 'filters' => array(array('name' => 'StringTrim')), - 'validators' => array( - array( - 'name' => 'StringLength', - 'options' => array( - 'min' => 3, - 'max' => 255, - ), - ), - $usernameUniqueValidator, - ), - )); - } - - $this->add(array( - 'name' => 'email', - 'required' => true, - 'filters' => array(array('name' => 'StringTrim')), - 'validators' => array( - array( - 'name' => 'EmailAddress' - ), - $emailUniqueValidator, - ), - )); - - if ($options->getEnableDisplayName()) { - $this->add(array( - 'name' => 'display_name', - 'required' => false, - 'filters' => array(array('name' => 'StringTrim')), - 'validators' => array( - array( - 'name' => 'StringLength', - 'options' => array( - 'min' => 3, - 'max' => 255, - ), - ), - ), - )); - } + parent::__construct($options); $this->add(array( - 'name' => 'password', - 'required' => true, - 'filters' => array(array('name' => 'StringTrim')), + 'name' => 'password_verification', + 'required' => true, + 'filters' => array(array('name' => 'StringTrim')), 'validators' => array( array( - 'name' => 'StringLength', - 'options' => array( - 'min' => 6, - ), - ), - ), - )); - - $this->add(array( - 'name' => 'password_verification', - 'required' => true, - 'filters' => array(array('name' => 'StringTrim')), - 'validators' => array( - array( - 'name' => 'StringLength', + 'name' => 'StringLength', 'options' => array( 'min' => 6, ), ), array( - 'name' => 'Identical', + 'name' => 'Identical', 'options' => array( 'token' => 'password', ), ), ), )); + + // Add specific validation rules + $usernameValidators = $this->get('username')->getValidatorChain(); + $usernameValidators->addValidator($usernameUniqueValidator); + + $emailValidators = $this->get('email')->getValidatorChain(); + $emailValidators->addValidator($emailUniqueValidator); } } diff --git a/src/BaconUser/InputFilter/UserFilter.php b/src/BaconUser/InputFilter/UserFilter.php new file mode 100644 index 0000000..3602148 --- /dev/null +++ b/src/BaconUser/InputFilter/UserFilter.php @@ -0,0 +1,84 @@ +getEnableUsername()) { + $this->add(array( + 'name' => 'username', + 'required' => true, + 'filters' => array(array('name' => 'StringTrim')), + 'validators' => array( + array( + 'name' => 'StringLength', + 'options' => array( + 'min' => 3, + 'max' => 255, + ), + ) + ), + )); + } + + $this->add(array( + 'name' => 'email', + 'required' => true, + 'filters' => array(array('name' => 'StringTrim')), + 'validators' => array( + array( + 'name' => 'EmailAddress' + ) + ), + )); + + if ($options->getEnableDisplayName()) { + $this->add(array( + 'name' => 'display_name', + 'required' => false, + 'filters' => array(array('name' => 'StringTrim')), + 'validators' => array( + array( + 'name' => 'StringLength', + 'options' => array( + 'min' => 3, + 'max' => 255, + ), + ), + ), + )); + } + + $this->add(array( + 'name' => 'password', + 'required' => true, + 'filters' => array(array('name' => 'StringTrim')), + 'validators' => array( + array( + 'name' => 'StringLength', + 'options' => array( + 'min' => 6, + ), + ), + ), + )); + } +} From f3997bc35d987863cae4cf6bed9bc51e97f44d47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Gallego?= Date: Wed, 26 Jun 2013 11:11:26 +0200 Subject: [PATCH 2/9] Remove dead code --- .../Form/Factory/UserFieldsetFactory.php | 1 - src/BaconUser/Form/UserFieldset.php | 22 ------------------- 2 files changed, 23 deletions(-) diff --git a/src/BaconUser/Form/Factory/UserFieldsetFactory.php b/src/BaconUser/Form/Factory/UserFieldsetFactory.php index b252a85..bcba13a 100644 --- a/src/BaconUser/Form/Factory/UserFieldsetFactory.php +++ b/src/BaconUser/Form/Factory/UserFieldsetFactory.php @@ -32,7 +32,6 @@ public function createService(ServiceLocatorInterface $serviceLocator) $fieldset = new UserFieldset($options); $fieldset->setHydrator($parentLocator->get('HydratorManager')->get('BaconUser\Hydrator\RegistrationHydrator')); - //$fieldset->setInputFilter($parentLocator->get('InputFilterManager')->get('BaconUser\InputFilter\RegistrationFilter')); return $fieldset; } diff --git a/src/BaconUser/Form/UserFieldset.php b/src/BaconUser/Form/UserFieldset.php index aef9103..ce246e6 100644 --- a/src/BaconUser/Form/UserFieldset.php +++ b/src/BaconUser/Form/UserFieldset.php @@ -71,27 +71,5 @@ public function __construct(UserOptionsInterface $options) 'required' => 'required' ) )); -/* - $this->add(array( - 'name' => 'password_verification', - 'options' => array( - 'label' => 'Verify password', - ), - 'attributes' => array( - 'type' => 'password' - ), - )); - - $this->add(array( - 'name' => 'submit', - 'options' => array( - 'label' => 'Register', - ), - 'attributes' => array( - 'type' => 'submit', - ), - ), array( - 'priority' => -100 - ));*/ } } From ac765f71c2d0b161ebdc767a65a0a69c2e526481 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Gallego?= Date: Sat, 6 Jul 2013 10:15:48 +0200 Subject: [PATCH 3/9] Remove deprecate method --- src/BaconUser/InputFilter/RegistrationFilter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/BaconUser/InputFilter/RegistrationFilter.php b/src/BaconUser/InputFilter/RegistrationFilter.php index 9a221ef..916cee0 100644 --- a/src/BaconUser/InputFilter/RegistrationFilter.php +++ b/src/BaconUser/InputFilter/RegistrationFilter.php @@ -51,9 +51,9 @@ public function __construct( // Add specific validation rules $usernameValidators = $this->get('username')->getValidatorChain(); - $usernameValidators->addValidator($usernameUniqueValidator); + $usernameValidators->attach($usernameUniqueValidator); $emailValidators = $this->get('email')->getValidatorChain(); - $emailValidators->addValidator($emailUniqueValidator); + $emailValidators->attach($emailUniqueValidator); } } From 9e640ffc8db44161967534bd5a2cf76bd7f7c67d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Gallego?= Date: Fri, 30 Aug 2013 16:21:26 +0200 Subject: [PATCH 4/9] Sync with latest master and various fixes --- src/BaconUser/Form/User/RegistrationForm.php | 2 +- .../Factory/RegistrationFilterFactory.php | 14 +------- .../InputFilter/RegistrationFilter.php | 36 ++++++++++--------- src/BaconUser/InputFilter/UserFilter.php | 17 --------- 4 files changed, 21 insertions(+), 48 deletions(-) diff --git a/src/BaconUser/Form/User/RegistrationForm.php b/src/BaconUser/Form/User/RegistrationForm.php index 8b94f12..c1f92af 100644 --- a/src/BaconUser/Form/User/RegistrationForm.php +++ b/src/BaconUser/Form/User/RegistrationForm.php @@ -47,7 +47,7 @@ public function __construct() $userFieldset = $this->get('user'); $userFieldset->add(array( 'type' => 'Password', - 'name' => 'password_verification', + 'name' => 'passwordVerification', 'options' => array( 'label' => 'Verify password' ), diff --git a/src/BaconUser/InputFilter/Factory/RegistrationFilterFactory.php b/src/BaconUser/InputFilter/Factory/RegistrationFilterFactory.php index a1fc230..c9355f3 100644 --- a/src/BaconUser/InputFilter/Factory/RegistrationFilterFactory.php +++ b/src/BaconUser/InputFilter/Factory/RegistrationFilterFactory.php @@ -32,18 +32,6 @@ public function createService(ServiceLocatorInterface $serviceLocator) $userRepository = $parentLocator->get('BaconUser\Repository\UserRepository'); $options = $parentLocator->get('BaconUser\Options\UserOptions'); - $inputFilter = new RegistrationFilter( - new NoObjectExists(array( - 'object_repository' => $userRepository, - 'fields' => 'email', - )), - new NoObjectExists(array( - 'object_repository' => $userRepository, - 'fields' => 'username', - )), - $options - ); - - return $inputFilter; + return new RegistrationFilter($userRepository, $options); } } diff --git a/src/BaconUser/InputFilter/RegistrationFilter.php b/src/BaconUser/InputFilter/RegistrationFilter.php index e9a8f9a..0225e27 100644 --- a/src/BaconUser/InputFilter/RegistrationFilter.php +++ b/src/BaconUser/InputFilter/RegistrationFilter.php @@ -10,6 +10,7 @@ namespace BaconUser\InputFilter; use BaconUser\Options\UserOptionsInterface; +use Doctrine\Common\Persistence\ObjectRepository; use Zend\Validator\ValidatorInterface; /** @@ -18,15 +19,11 @@ class RegistrationFilter extends UserFilter { /** - * @param ValidatorInterface $emailUniqueValidator - * @param ValidatorInterface $usernameUniqueValidator + * @param ObjectRepository $objectRepository * @param UserOptionsInterface $options */ - public function __construct( - ValidatorInterface $emailUniqueValidator, - ValidatorInterface $usernameUniqueValidator, - UserOptionsInterface $options - ) { + public function __construct(ObjectRepository $objectRepository, UserOptionsInterface $options) + { parent::__construct($options); if ($options->getEnableUsername()) { @@ -42,7 +39,13 @@ public function __construct( 'max' => 255, ), ), - $usernameUniqueValidator, + array( + 'name' => 'DoctrineModule\Validator\NoObjectExists', + 'options' => array( + 'object_repository' => $objectRepository, + 'fields' => 'username' + ) + ) ), )); } @@ -55,12 +58,18 @@ public function __construct( array( 'name' => 'EmailAddress' ), - $emailUniqueValidator, + array( + 'name' => 'DoctrineModule\Validator\NoObjectExists', + 'options' => array( + 'object_repository' => $objectRepository, + 'fields' => 'email' + ) + ) ), )); $this->add(array( - 'name' => 'password_verification', + 'name' => 'passwordVerification', 'required' => true, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array( @@ -78,12 +87,5 @@ public function __construct( ), ), )); - - // Add specific validation rules - $usernameValidators = $this->get('username')->getValidatorChain(); - $usernameValidators->attach($usernameUniqueValidator); - - $emailValidators = $this->get('email')->getValidatorChain(); - $emailValidators->attach($emailUniqueValidator); } } diff --git a/src/BaconUser/InputFilter/UserFilter.php b/src/BaconUser/InputFilter/UserFilter.php index 3602148..f2a288b 100644 --- a/src/BaconUser/InputFilter/UserFilter.php +++ b/src/BaconUser/InputFilter/UserFilter.php @@ -50,23 +50,6 @@ public function __construct(UserOptionsInterface $options) ), )); - if ($options->getEnableDisplayName()) { - $this->add(array( - 'name' => 'display_name', - 'required' => false, - 'filters' => array(array('name' => 'StringTrim')), - 'validators' => array( - array( - 'name' => 'StringLength', - 'options' => array( - 'min' => 3, - 'max' => 255, - ), - ), - ), - )); - } - $this->add(array( 'name' => 'password', 'required' => true, From f5d0c1e771a9360cfd6b6aa1db910b3bd35f51c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Gallego?= Date: Fri, 30 Aug 2013 17:09:15 +0200 Subject: [PATCH 5/9] Updated test --- config/module.config.php | 2 +- .../Form/Factory/UserFieldsetFactory.php | 4 +- src/BaconUser/Form/User/RegistrationForm.php | 4 +- src/BaconUser/Form/UserFieldset.php | 5 +- ...torFactory.php => UserHydratorFactory.php} | 10 +- ...istrationHydrator.php => UserHydrator.php} | 14 +- .../Factory/RegistrationFormFactoryTest.php | 6 - .../Form/Factory/UserFieldsetFactoryTest.php | 43 ++++++ .../Form/User/RegistrationFormTest.php | 54 +++++++ ...ationFormTest.php => UserFieldsetTest.php} | 22 +-- ...ryTest.php => UserHydratorFactoryTest.php} | 8 +- ...nHydratorTest.php => UserHydratorTest.php} | 8 +- .../InputFilter/RegistrationFilterTest.php | 12 +- .../InputFilter/UserFilterTest.php | 142 ++++++++++++++++++ 14 files changed, 284 insertions(+), 50 deletions(-) rename src/BaconUser/Hydrator/Factory/{RegistrationHydratorFactory.php => UserHydratorFactory.php} (78%) rename src/BaconUser/Hydrator/{RegistrationHydrator.php => UserHydrator.php} (71%) create mode 100644 tests/BaconUserTest/Form/Factory/UserFieldsetFactoryTest.php create mode 100644 tests/BaconUserTest/Form/User/RegistrationFormTest.php rename tests/BaconUserTest/Form/{RegistrationFormTest.php => UserFieldsetTest.php} (60%) rename tests/BaconUserTest/Hydrator/Factory/{RegistrationHydratorFactoryTest.php => UserHydratorFactoryTest.php} (79%) rename tests/BaconUserTest/Hydrator/{RegistrationHydratorTest.php => UserHydratorTest.php} (84%) create mode 100644 tests/BaconUserTest/InputFilter/UserFilterTest.php diff --git a/config/module.config.php b/config/module.config.php index 48b82ba..f3f63ff 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -44,7 +44,7 @@ 'hydrators' => array( 'factories' => array( - 'BaconUser\Hydrator\RegistrationHydrator' => 'BaconUser\Hydrator\Factory\RegistrationHydratorFactory' + 'BaconUser\Hydrator\UserHydrator' => 'BaconUser\Hydrator\Factory\UserHydrator' ) ), diff --git a/src/BaconUser/Form/Factory/UserFieldsetFactory.php b/src/BaconUser/Form/Factory/UserFieldsetFactory.php index bcba13a..08d5062 100644 --- a/src/BaconUser/Form/Factory/UserFieldsetFactory.php +++ b/src/BaconUser/Form/Factory/UserFieldsetFactory.php @@ -29,9 +29,9 @@ public function createService(ServiceLocatorInterface $serviceLocator) { $parentLocator = $serviceLocator->getServiceLocator(); $options = $parentLocator->get('BaconUser\Options\UserOptions'); + $hydrator = $parentLocator->get('HydratorManager')->get('BaconUser\Hydrator\UserHydrator'); - $fieldset = new UserFieldset($options); - $fieldset->setHydrator($parentLocator->get('HydratorManager')->get('BaconUser\Hydrator\RegistrationHydrator')); + $fieldset = new UserFieldset($hydrator, $options); return $fieldset; } diff --git a/src/BaconUser/Form/User/RegistrationForm.php b/src/BaconUser/Form/User/RegistrationForm.php index c1f92af..138daea 100644 --- a/src/BaconUser/Form/User/RegistrationForm.php +++ b/src/BaconUser/Form/User/RegistrationForm.php @@ -17,9 +17,9 @@ */ class RegistrationForm extends Form { - public function __construct() + public function init() { - parent::__construct('registration-form'); + $this->setName('registration-form'); $this->add(array( 'type' => 'BaconUser\Form\UserFieldset', diff --git a/src/BaconUser/Form/UserFieldset.php b/src/BaconUser/Form/UserFieldset.php index 51fc20c..a4057a6 100644 --- a/src/BaconUser/Form/UserFieldset.php +++ b/src/BaconUser/Form/UserFieldset.php @@ -11,6 +11,7 @@ use BaconUser\Options\UserOptionsInterface; use Zend\Form\Fieldset; +use Zend\Stdlib\Hydrator\HydratorInterface; /** * Base fieldset for user @@ -20,11 +21,13 @@ class UserFieldset extends Fieldset /** * Constructor * + * @param HydratorInterface $hydrator * @param UserOptionsInterface $options */ - public function __construct(UserOptionsInterface $options) + public function __construct(HydratorInterface $hydrator, UserOptionsInterface $options) { parent::__construct('user'); + $this->setHydrator($hydrator); if ($options->getEnableUsername()) { $this->add(array( diff --git a/src/BaconUser/Hydrator/Factory/RegistrationHydratorFactory.php b/src/BaconUser/Hydrator/Factory/UserHydratorFactory.php similarity index 78% rename from src/BaconUser/Hydrator/Factory/RegistrationHydratorFactory.php rename to src/BaconUser/Hydrator/Factory/UserHydratorFactory.php index 1d95ba3..4923e67 100644 --- a/src/BaconUser/Hydrator/Factory/RegistrationHydratorFactory.php +++ b/src/BaconUser/Hydrator/Factory/UserHydratorFactory.php @@ -10,27 +10,27 @@ namespace BaconUser\Hydrator\Factory; use BaconUser\Form\PasswordHashingStrategy; -use BaconUser\Hydrator\RegistrationHydrator; +use BaconUser\Hydrator\UserHydrator; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; /** - * Service factory that instantiates {@see RegistrationHydrator}. + * Service factory that instantiates {@see UserHydrator}. */ -class RegistrationHydratorFactory implements FactoryInterface +class UserHydratorFactory implements FactoryInterface { /** * createService(): defined by FactoryInterface. * * @see FactoryInterface::createService() * @param ServiceLocatorInterface $serviceLocator - * @return RegistrationHydrator + * @return UserHydrator */ public function createService(ServiceLocatorInterface $serviceLocator) { $parentLocator = $serviceLocator->getServiceLocator(); - $hydrator = new RegistrationHydrator( + $hydrator = new UserHydrator( new PasswordHashingStrategy( $parentLocator->get('BaconUser\Password\HandlerInterface') ) diff --git a/src/BaconUser/Hydrator/RegistrationHydrator.php b/src/BaconUser/Hydrator/UserHydrator.php similarity index 71% rename from src/BaconUser/Hydrator/RegistrationHydrator.php rename to src/BaconUser/Hydrator/UserHydrator.php index a42387e..afe0bcf 100644 --- a/src/BaconUser/Hydrator/RegistrationHydrator.php +++ b/src/BaconUser/Hydrator/UserHydrator.php @@ -9,35 +9,33 @@ namespace BaconUser\Hydrator; +use Zend\Stdlib\Exception; use Zend\Stdlib\Hydrator\ClassMethods; use Zend\Stdlib\Hydrator\Strategy\StrategyInterface; /** * Hydrator for the {@see RegistrationForm}. */ -class RegistrationHydrator extends ClassMethods +class UserHydrator extends ClassMethods { /** * @param StrategyInterface $passwordHashingStrategy */ public function __construct(StrategyInterface $passwordHashingStrategy) { - parent::__construct(true); - $this->addStrategy('password_hash', $passwordHashingStrategy); + parent::__construct(false); + $this->addStrategy('passwordHash', $passwordHashingStrategy); } /** - * hydrate(): defined by ClassMethods. - * - * @see ClassMethods::hydrate() - * @param array $data + * @param array $data * @param object $object * @return object */ public function hydrate(array $data, $object) { if (isset($data['password'])) { - $data['password_hash'] = $data['password']; + $data['passwordHash'] = $data['password']; } return parent::hydrate($data, $object); diff --git a/tests/BaconUserTest/Form/Factory/RegistrationFormFactoryTest.php b/tests/BaconUserTest/Form/Factory/RegistrationFormFactoryTest.php index 2ea2a69..0a74b37 100644 --- a/tests/BaconUserTest/Form/Factory/RegistrationFormFactoryTest.php +++ b/tests/BaconUserTest/Form/Factory/RegistrationFormFactoryTest.php @@ -24,21 +24,15 @@ class RegistrationFormFactoryTest extends TestCase public function testFactoryProcessesWithoutErrors() { $options = $this->getMock('BaconUser\Options\UserOptionsInterface'); - $hydrator = $this->getMock('Zend\Stdlib\Hydrator\HydratorInterface'); $inputFilter = $this->getMock('Zend\InputFilter\InputFilterInterface'); $parentLocator = new ServiceManager(); $parentLocator->setService('BaconUser\Options\UserOptions', $options); - $hydratorManager = new HydratorPluginManager(); - $hydratorManager->setServiceLocator($parentLocator); - $hydratorManager->setService('BaconUser\Hydrator\RegistrationHydrator', $hydrator); - $inputFilterManager = new InputFilterPluginManager(); $inputFilterManager->setServiceLocator($parentLocator); $inputFilterManager->setService('BaconUser\InputFilter\RegistrationFilter', $inputFilter); - $parentLocator->setService('HydratorManager', $hydratorManager); $parentLocator->setService('InputFilterManager', $inputFilterManager); $formManager = new FormElementManager(); diff --git a/tests/BaconUserTest/Form/Factory/UserFieldsetFactoryTest.php b/tests/BaconUserTest/Form/Factory/UserFieldsetFactoryTest.php new file mode 100644 index 0000000..b693a56 --- /dev/null +++ b/tests/BaconUserTest/Form/Factory/UserFieldsetFactoryTest.php @@ -0,0 +1,43 @@ +getMock('BaconUser\Options\UserOptionsInterface'); + + $parentLocator = new ServiceManager(); + $parentLocator->setService('BaconUser\Options\UserOptions', $options); + + $hydratorManager = new HydratorPluginManager(); + $hydratorManager->setServiceLocator($parentLocator); + $hydratorManager->setService('BaconUser\Hydrator\UserHydrator', $this->getMock('Zend\Stdlib\Hydrator\HydratorInterface')); + + $parentLocator->setService('HydratorManager', $hydratorManager); + + $formManager = new FormElementManager(); + $formManager->setServiceLocator($parentLocator); + + $factory = new UserFieldsetFactory(); + $factory->createService($formManager); + // Expect no exceptions or errors. + } +} diff --git a/tests/BaconUserTest/Form/User/RegistrationFormTest.php b/tests/BaconUserTest/Form/User/RegistrationFormTest.php new file mode 100644 index 0000000..e6cd89c --- /dev/null +++ b/tests/BaconUserTest/Form/User/RegistrationFormTest.php @@ -0,0 +1,54 @@ +setFactory('BaconUser\Form\UserFieldset', function($serviceLocator) { + return new UserFieldset($this->getMock('Zend\Stdlib\Hydrator\HydratorInterface'), new UserOptions()); + }); + + $this->registrationForm = $formElementManager->get('BaconUser\Form\User\RegistrationForm'); + } + + public function testFormHasDefaultName() + { + $this->assertEquals('registration-form', $this->registrationForm->getName()); + } + + public function testAssertUserFieldsetIsConfiguredAsBaseFieldset() + { + $this->assertTrue($this->registrationForm->get('user')->useAsBaseFieldset(), 'User fieldset is not configured as base fieldset'); + } + + public function testContextSpecificElements() + { + $this->assertTrue($this->registrationForm->has('csrf'), 'CSRF field missing'); + $this->assertTrue($this->registrationForm->has('submit'), 'Submit field missing'); + $this->assertTrue($this->registrationForm->get('user')->has('passwordVerification'), 'Password verification field missing'); + } +} diff --git a/tests/BaconUserTest/Form/RegistrationFormTest.php b/tests/BaconUserTest/Form/UserFieldsetTest.php similarity index 60% rename from tests/BaconUserTest/Form/RegistrationFormTest.php rename to tests/BaconUserTest/Form/UserFieldsetTest.php index e4d57a3..d601ee3 100644 --- a/tests/BaconUserTest/Form/RegistrationFormTest.php +++ b/tests/BaconUserTest/Form/UserFieldsetTest.php @@ -7,37 +7,37 @@ * @license http://opensource.org/licenses/BSD-2-Clause Simplified BSD License */ -namespace BaconUserTest\Form; +namespace BaconUserTest\InputFilter; -use BaconUser\Form\RegistrationForm; +use BaconUser\Form\UserFieldset; use BaconUser\Options\UserOptions; use PHPUnit_Framework_TestCase as TestCase; /** - * @covers BaconUser\Form\RegistrationForm + * @covers BaconUser\Form\UserFieldset */ -class RegistrationFormTest extends TestCase +class UserFieldsetTest extends TestCase { - public function testFormWithAllFieldsEnabled() + public function testFieldsetWithAllFieldsEnabled() { - $form = new RegistrationForm( + $form = new UserFieldset( + $this->getMock('Zend\Stdlib\Hydrator\HydratorInterface'), new UserOptions(array( - 'enable_username' => true, + 'enable_username' => true, )) ); $this->assertTrue($form->has('username'), 'Username field missing'); $this->assertTrue($form->has('email'), 'Email field missing'); $this->assertTrue($form->has('password'), 'Password field missing'); - $this->assertTrue($form->has('password_verification'), 'Password verification field missing'); - $this->assertTrue($form->has('submit'), 'Submit field missing'); } public function testFormWithUsernameDisabled() { - $form = new RegistrationForm( + $form = new UserFieldset( + $this->getMock('Zend\Stdlib\Hydrator\HydratorInterface'), new UserOptions(array( - 'enable_username' => false, + 'enable_username' => false, )) ); diff --git a/tests/BaconUserTest/Hydrator/Factory/RegistrationHydratorFactoryTest.php b/tests/BaconUserTest/Hydrator/Factory/UserHydratorFactoryTest.php similarity index 79% rename from tests/BaconUserTest/Hydrator/Factory/RegistrationHydratorFactoryTest.php rename to tests/BaconUserTest/Hydrator/Factory/UserHydratorFactoryTest.php index c90d6ac..75cbb47 100644 --- a/tests/BaconUserTest/Hydrator/Factory/RegistrationHydratorFactoryTest.php +++ b/tests/BaconUserTest/Hydrator/Factory/UserHydratorFactoryTest.php @@ -9,15 +9,15 @@ namespace BaconUserTest\Hydrator\Factory; -use BaconUser\Hydrator\Factory\RegistrationHydratorFactory; +use BaconUser\Hydrator\Factory\UserHydratorFactory; use PHPUnit_Framework_TestCase as TestCase; use Zend\ServiceManager\ServiceManager; use Zend\Stdlib\Hydrator\HydratorPluginManager; /** - * @covers BaconUser\Hydrator\Factory\RegistrationHydratorFactory + * @covers BaconUser\Hydrator\Factory\UserHydratorFactory */ -class RegistrationHydratorFactoryTest extends TestCase +class UserHydratorFactoryTest extends TestCase { public function testFactoryProcessesWithoutErrors() { @@ -29,7 +29,7 @@ public function testFactoryProcessesWithoutErrors() $hydratorManager = new HydratorPluginManager(); $hydratorManager->setServiceLocator($parentLocator); - $factory = new RegistrationHydratorFactory(); + $factory = new UserHydratorFactory(); $factory->createService($hydratorManager); // Expect no exceptions or errors. } diff --git a/tests/BaconUserTest/Hydrator/RegistrationHydratorTest.php b/tests/BaconUserTest/Hydrator/UserHydratorTest.php similarity index 84% rename from tests/BaconUserTest/Hydrator/RegistrationHydratorTest.php rename to tests/BaconUserTest/Hydrator/UserHydratorTest.php index 21647a6..0f0106d 100644 --- a/tests/BaconUserTest/Hydrator/RegistrationHydratorTest.php +++ b/tests/BaconUserTest/Hydrator/UserHydratorTest.php @@ -10,13 +10,13 @@ namespace BaconUserTest\Hydrator; use BaconUser\Entity\User; -use BaconUser\Hydrator\RegistrationHydrator; +use BaconUser\Hydrator\UserHydrator; use PHPUnit_Framework_TestCase as TestCase; /** - * @covers BaconUser\Hydrator\RegistrationHydrator + * @covers BaconUser\Hydrator\UserHydrator */ -class RegistrationHydratorTest extends TestCase +class UserHydratorTest extends TestCase { public function testHydrate() { @@ -26,7 +26,7 @@ public function testHydrate() ->with($this->equalTo('foobar')) ->will($this->returnValue('bazbat')); - $hydrator = new RegistrationHydrator($hashingStrategy); + $hydrator = new UserHydrator($hashingStrategy); $user = new User(); $hydrator->hydrate( diff --git a/tests/BaconUserTest/InputFilter/RegistrationFilterTest.php b/tests/BaconUserTest/InputFilter/RegistrationFilterTest.php index d3c29eb..66d285e 100644 --- a/tests/BaconUserTest/InputFilter/RegistrationFilterTest.php +++ b/tests/BaconUserTest/InputFilter/RegistrationFilterTest.php @@ -18,7 +18,7 @@ */ class RegistrationFilterTest extends TestCase { - public static function formDataProvider() + /*public static function formDataProvider() { return array( 'completely-valid-input' => array( @@ -103,7 +103,7 @@ public static function formDataProvider() false ), ); - } + }*/ /** * @dataProvider formDataProvider @@ -114,7 +114,7 @@ public static function formDataProvider() * @param bool $usernameIsUnique * @return void */ - public function testInputFilter( + /*public function testInputFilter( array $input, array $output = null, $enableUsername = true, @@ -137,13 +137,13 @@ public function testInputFilter( $this->assertTrue($filter->isValid(), 'Input must be valid'); $this->assertEquals($output, $filter->getValues()); } - } + }*/ /** * @param bool $validates * @return \Zend\Validator\ValidatorInterface */ - protected function getMockValidator($validates) + /*protected function getMockValidator($validates) { $validator = $this->getMock('Zend\Validator\ValidatorInterface'); $validator->expects($this->any()) @@ -157,5 +157,5 @@ protected function getMockValidator($validates) } return $validator; - } + }*/ } diff --git a/tests/BaconUserTest/InputFilter/UserFilterTest.php b/tests/BaconUserTest/InputFilter/UserFilterTest.php new file mode 100644 index 0000000..0df88d0 --- /dev/null +++ b/tests/BaconUserTest/InputFilter/UserFilterTest.php @@ -0,0 +1,142 @@ + array( + array( + 'username' => 'foobar', + 'email' => 'foobar@example.com', + 'password' => 'bazbat', + ), + array( + 'username' => 'foobar', + 'email' => 'foobar@example.com', + 'password' => 'bazbat', + ), + ), + 'space-padded-valid-input' => array( + array( + 'username' => ' foobar ', + 'email' => ' foobar@example.com ', + 'password' => 'bazbat', + ), + array( + 'username' => 'foobar', + 'email' => 'foobar@example.com', + 'password' => 'bazbat', + ), + ), + 'duplicate-email' => array( + array( + 'username' => 'foobar', + 'email' => 'foobar@example.com', + 'password' => 'bazbat', + ), + null, + true, + false, + ), + 'duplicate-username' => array( + array( + 'username' => 'foobar', + 'email' => 'foobar@example.com', + 'password' => 'bazbat', + ), + null, + true, + true, + ), + 'invalid-with-enabled-username' => array( + array( + 'email' => 'foobar@example.com', + 'password' => 'bazbat', + 'password_verification' => 'bazbat', + ), + ), + 'valid-with-disabled-username' => array( + array( + 'email' => 'foobar@example.com', + 'password' => 'bazbat', + 'password_verification' => 'bazbat', + ), + array( + 'email' => 'foobar@example.com', + 'password' => 'bazbat', + 'password_verification' => 'bazbat', + ), + false + ), + ); + } + + /** + * @dataProvider formDataProvider + * @param array $input + * @param array|null $output + * @param bool $enableUsername + * @param bool $emailIsUnique + * @param bool $usernameIsUnique + * @return void + */ + public function testInputFilter( + array $input, + array $output = null, + $enableUsername = true, + $emailIsUnique = true, + $usernameIsUnique = true + ) { + $filter = new UserFilter( + new UserOptions(array( + 'enable_username' => $enableUsername, + )) + ); + + $filter->setData($input); + + if ($output === null) { + $this->assertFalse($filter->isValid(), 'Input must not be valid'); + } else { + $this->assertTrue($filter->isValid(), 'Input must be valid'); + $this->assertEquals($output, $filter->getValues()); + } + } + + /** + * @param bool $validates + * @return \Zend\Validator\ValidatorInterface + */ + /*protected function getMockValidator($validates) + { + $validator = $this->getMock('Zend\Validator\ValidatorInterface'); + $validator->expects($this->any()) + ->method('isValid') + ->will($this->returnValue($validates)); + + if (!$validates) { + $validator->expects($this->any()) + ->method('getMessages') + ->will($this->returnValue(array())); + } + + return $validator; + }*/ +} From 7a89a09d241e9508cb8e18a0f4e22959bffef4fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Gallego?= Date: Tue, 3 Sep 2013 12:05:59 +0200 Subject: [PATCH 6/9] Fix tests --- .../Factory/RegistrationFilterFactory.php | 12 ++++- .../InputFilter/RegistrationFilter.php | 54 +++++-------------- tests/BaconUserTest/Form/UserFieldsetTest.php | 2 +- .../InputFilter/RegistrationFilterTest.php | 41 +++++++------- .../InputFilter/UserFilterTest.php | 31 +---------- 5 files changed, 49 insertions(+), 91 deletions(-) diff --git a/src/BaconUser/InputFilter/Factory/RegistrationFilterFactory.php b/src/BaconUser/InputFilter/Factory/RegistrationFilterFactory.php index c9355f3..a086007 100644 --- a/src/BaconUser/InputFilter/Factory/RegistrationFilterFactory.php +++ b/src/BaconUser/InputFilter/Factory/RegistrationFilterFactory.php @@ -32,6 +32,16 @@ public function createService(ServiceLocatorInterface $serviceLocator) $userRepository = $parentLocator->get('BaconUser\Repository\UserRepository'); $options = $parentLocator->get('BaconUser\Options\UserOptions'); - return new RegistrationFilter($userRepository, $options); + $usernameValidator = new NoObjectExists(array( + 'object_repository' => $userRepository, + 'fields' => 'username' + )); + + $emailValidator = new NoObjectExists(array( + 'object_repository' => $userRepository, + 'fields' => 'email' + )); + + return new RegistrationFilter($userRepository, $usernameValidator, $emailValidator, $options); } } diff --git a/src/BaconUser/InputFilter/RegistrationFilter.php b/src/BaconUser/InputFilter/RegistrationFilter.php index 0225e27..6edde81 100644 --- a/src/BaconUser/InputFilter/RegistrationFilter.php +++ b/src/BaconUser/InputFilter/RegistrationFilter.php @@ -19,54 +19,26 @@ class RegistrationFilter extends UserFilter { /** - * @param ObjectRepository $objectRepository + * @param ObjectRepository $objectRepository + * @param ValidatorInterface $usernameValidator + * @param ValidatorInterface $emailValidator * @param UserOptionsInterface $options */ - public function __construct(ObjectRepository $objectRepository, UserOptionsInterface $options) - { + public function __construct( + ObjectRepository $objectRepository, + ValidatorInterface $usernameValidator, + ValidatorInterface $emailValidator, + UserOptionsInterface $options + ) { parent::__construct($options); if ($options->getEnableUsername()) { - $this->add(array( - 'name' => 'username', - 'required' => true, - 'filters' => array(array('name' => 'StringTrim')), - 'validators' => array( - array( - 'name' => 'StringLength', - 'options' => array( - 'min' => 3, - 'max' => 255, - ), - ), - array( - 'name' => 'DoctrineModule\Validator\NoObjectExists', - 'options' => array( - 'object_repository' => $objectRepository, - 'fields' => 'username' - ) - ) - ), - )); + $usernameInput = $this->get('username'); + $usernameInput->getValidatorChain()->attach($usernameValidator); } - $this->add(array( - 'name' => 'email', - 'required' => true, - 'filters' => array(array('name' => 'StringTrim')), - 'validators' => array( - array( - 'name' => 'EmailAddress' - ), - array( - 'name' => 'DoctrineModule\Validator\NoObjectExists', - 'options' => array( - 'object_repository' => $objectRepository, - 'fields' => 'email' - ) - ) - ), - )); + $emailInput = $this->get('email'); + $emailInput->getValidatorChain()->attach($emailValidator); $this->add(array( 'name' => 'passwordVerification', diff --git a/tests/BaconUserTest/Form/UserFieldsetTest.php b/tests/BaconUserTest/Form/UserFieldsetTest.php index d601ee3..dc7f6df 100644 --- a/tests/BaconUserTest/Form/UserFieldsetTest.php +++ b/tests/BaconUserTest/Form/UserFieldsetTest.php @@ -7,7 +7,7 @@ * @license http://opensource.org/licenses/BSD-2-Clause Simplified BSD License */ -namespace BaconUserTest\InputFilter; +namespace BaconUserTest\Form; use BaconUser\Form\UserFieldset; use BaconUser\Options\UserOptions; diff --git a/tests/BaconUserTest/InputFilter/RegistrationFilterTest.php b/tests/BaconUserTest/InputFilter/RegistrationFilterTest.php index 66d285e..688eb2c 100644 --- a/tests/BaconUserTest/InputFilter/RegistrationFilterTest.php +++ b/tests/BaconUserTest/InputFilter/RegistrationFilterTest.php @@ -18,7 +18,7 @@ */ class RegistrationFilterTest extends TestCase { - /*public static function formDataProvider() + public static function formDataProvider() { return array( 'completely-valid-input' => array( @@ -26,13 +26,13 @@ class RegistrationFilterTest extends TestCase 'username' => 'foobar', 'email' => 'foobar@example.com', 'password' => 'bazbat', - 'password_verification' => 'bazbat', + 'passwordVerification' => 'bazbat', ), array( 'username' => 'foobar', 'email' => 'foobar@example.com', 'password' => 'bazbat', - 'password_verification' => 'bazbat', + 'passwordVerification' => 'bazbat', ), ), 'space-padded-valid-input' => array( @@ -41,21 +41,21 @@ class RegistrationFilterTest extends TestCase 'email' => ' foobar@example.com ', // @todo Bug with identical validator (compares filtered against raw value) 'password' => 'bazbat', - 'password_verification' => 'bazbat', + 'passwordVerification' => 'bazbat', ), array( 'username' => 'foobar', 'email' => 'foobar@example.com', 'password' => 'bazbat', - 'password_verification' => 'bazbat', + 'passwordVerification' => 'bazbat', ), ), 'duplicate-email' => array( array( 'username' => 'foobar', - 'email' => 'foobar@example.com', + 'email' => 'nfoobar@example.com', 'password' => 'bazbat', - 'password_verification' => 'bazbat', + 'passwordVerification' => 'bazbat', ), null, true, @@ -67,7 +67,7 @@ class RegistrationFilterTest extends TestCase 'username' => 'foobar', 'email' => 'foobar@example.com', 'password' => 'bazbat', - 'password_verification' => 'bazbat', + 'passwordVerification' => 'bazbat', ), null, true, @@ -79,31 +79,31 @@ class RegistrationFilterTest extends TestCase 'username' => 'foobar', 'email' => 'foobar@example.com', 'password' => 'foobar', - 'password_verification' => 'bazbat', + 'passwordVerification' => 'bazbat', ), ), 'invalid-with-enabled-username' => array( array( 'email' => 'foobar@example.com', 'password' => 'bazbat', - 'password_verification' => 'bazbat', + 'passwordVerification' => 'bazbat', ), ), 'valid-with-disabled-username' => array( array( 'email' => 'foobar@example.com', 'password' => 'bazbat', - 'password_verification' => 'bazbat', + 'passwordVerification' => 'bazbat', ), array( 'email' => 'foobar@example.com', 'password' => 'bazbat', - 'password_verification' => 'bazbat', + 'passwordVerification' => 'bazbat', ), false ), ); - }*/ + } /** * @dataProvider formDataProvider @@ -114,18 +114,21 @@ class RegistrationFilterTest extends TestCase * @param bool $usernameIsUnique * @return void */ - /*public function testInputFilter( + public function testInputFilter( array $input, array $output = null, $enableUsername = true, $emailIsUnique = true, $usernameIsUnique = true ) { + $objectRepository = $this->getMock('Doctrine\Common\Persistence\ObjectRepository'); + $filter = new RegistrationFilter( - $this->getMockValidator($emailIsUnique), + $objectRepository, $this->getMockValidator($usernameIsUnique), + $this->getMockValidator($emailIsUnique), new UserOptions(array( - 'enable_username' => $enableUsername, + 'enable_username' => $enableUsername, )) ); @@ -137,13 +140,13 @@ class RegistrationFilterTest extends TestCase $this->assertTrue($filter->isValid(), 'Input must be valid'); $this->assertEquals($output, $filter->getValues()); } - }*/ + } /** * @param bool $validates * @return \Zend\Validator\ValidatorInterface */ - /*protected function getMockValidator($validates) + protected function getMockValidator($validates) { $validator = $this->getMock('Zend\Validator\ValidatorInterface'); $validator->expects($this->any()) @@ -157,5 +160,5 @@ class RegistrationFilterTest extends TestCase } return $validator; - }*/ + } } diff --git a/tests/BaconUserTest/InputFilter/UserFilterTest.php b/tests/BaconUserTest/InputFilter/UserFilterTest.php index 0df88d0..f672fc2 100644 --- a/tests/BaconUserTest/InputFilter/UserFilterTest.php +++ b/tests/BaconUserTest/InputFilter/UserFilterTest.php @@ -45,43 +45,20 @@ public static function formDataProvider() 'password' => 'bazbat', ), ), - 'duplicate-email' => array( - array( - 'username' => 'foobar', - 'email' => 'foobar@example.com', - 'password' => 'bazbat', - ), - null, - true, - false, - ), - 'duplicate-username' => array( - array( - 'username' => 'foobar', - 'email' => 'foobar@example.com', - 'password' => 'bazbat', - ), - null, - true, - true, - ), 'invalid-with-enabled-username' => array( array( 'email' => 'foobar@example.com', 'password' => 'bazbat', - 'password_verification' => 'bazbat', ), ), 'valid-with-disabled-username' => array( array( 'email' => 'foobar@example.com', 'password' => 'bazbat', - 'password_verification' => 'bazbat', ), array( 'email' => 'foobar@example.com', 'password' => 'bazbat', - 'password_verification' => 'bazbat', ), false ), @@ -93,20 +70,16 @@ public static function formDataProvider() * @param array $input * @param array|null $output * @param bool $enableUsername - * @param bool $emailIsUnique - * @param bool $usernameIsUnique * @return void */ public function testInputFilter( array $input, array $output = null, - $enableUsername = true, - $emailIsUnique = true, - $usernameIsUnique = true + $enableUsername = true ) { $filter = new UserFilter( new UserOptions(array( - 'enable_username' => $enableUsername, + 'enable_username' => $enableUsername, )) ); From 1e9831f7926df07dba0f7f796cccb814578839c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Gallego?= Date: Tue, 3 Sep 2013 12:15:47 +0200 Subject: [PATCH 7/9] Remove useless code --- .../InputFilter/UserFilterTest.php | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/tests/BaconUserTest/InputFilter/UserFilterTest.php b/tests/BaconUserTest/InputFilter/UserFilterTest.php index f672fc2..85422e9 100644 --- a/tests/BaconUserTest/InputFilter/UserFilterTest.php +++ b/tests/BaconUserTest/InputFilter/UserFilterTest.php @@ -92,24 +92,4 @@ public function testInputFilter( $this->assertEquals($output, $filter->getValues()); } } - - /** - * @param bool $validates - * @return \Zend\Validator\ValidatorInterface - */ - /*protected function getMockValidator($validates) - { - $validator = $this->getMock('Zend\Validator\ValidatorInterface'); - $validator->expects($this->any()) - ->method('isValid') - ->will($this->returnValue($validates)); - - if (!$validates) { - $validator->expects($this->any()) - ->method('getMessages') - ->will($this->returnValue(array())); - } - - return $validator; - }*/ } From 8228ddb0f2f34409d45a6dce9c8724abb8f33228 Mon Sep 17 00:00:00 2001 From: Jason Guthery Date: Wed, 13 Nov 2013 15:00:36 -0600 Subject: [PATCH 8/9] Corrected service identifier for RegistrationForm move to User path --- src/BaconUser/Service/Factory/RegistrationServiceFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BaconUser/Service/Factory/RegistrationServiceFactory.php b/src/BaconUser/Service/Factory/RegistrationServiceFactory.php index bf22872..3b76bd0 100644 --- a/src/BaconUser/Service/Factory/RegistrationServiceFactory.php +++ b/src/BaconUser/Service/Factory/RegistrationServiceFactory.php @@ -28,7 +28,7 @@ class RegistrationServiceFactory implements FactoryInterface public function createService(ServiceLocatorInterface $serviceLocator) { $registrationService = new RegistrationService( - $serviceLocator->get('BaconUser\Form\RegistrationForm'), + $serviceLocator->get('BaconUser\Form\User\RegistrationForm'), $serviceLocator->get('BaconUser\ObjectManager'), $serviceLocator->get('BaconUser\Options\UserOptions') ); From 152496bb7ad5e188bc82a03b97b1b7f428a715c6 Mon Sep 17 00:00:00 2001 From: Jason Guthery Date: Wed, 13 Nov 2013 15:01:41 -0600 Subject: [PATCH 9/9] Corrected service identifier for RegistrationForm move to User path --- .../Service/Factory/RegistrationServiceFactoryTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/BaconUserTest/Service/Factory/RegistrationServiceFactoryTest.php b/tests/BaconUserTest/Service/Factory/RegistrationServiceFactoryTest.php index 5d19d1e..d771c29 100644 --- a/tests/BaconUserTest/Service/Factory/RegistrationServiceFactoryTest.php +++ b/tests/BaconUserTest/Service/Factory/RegistrationServiceFactoryTest.php @@ -26,7 +26,7 @@ public function testFactoryProcessesWithoutErrors() $userPrototype = $this->getMock('BaconUser\Entity\UserInterface'); $locator = new ServiceManager(); - $locator->setService('BaconUser\Form\RegistrationForm', $registrationForm); + $locator->setService('BaconUser\Form\User\RegistrationForm', $registrationForm); $locator->setService('BaconUser\ObjectManager', $objectManager); $locator->setService('BaconUser\Options\UserOptions', $options); $locator->setService('BaconUser\Entity\UserPrototype', $userPrototype);