diff --git a/.travis.yml b/.travis.yml index 920dc951..f1ea2622 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,7 @@ php: - 5.4 - 5.5 - 5.6 + - 7.0 - hhvm before_script: @@ -28,5 +29,4 @@ notifications: matrix: fast_finish: true allow_failures: - - php: 5.6 - php: hhvm diff --git a/Module.php b/Module.php index 3c7afd77..e1ac80d6 100644 --- a/Module.php +++ b/Module.php @@ -2,11 +2,9 @@ namespace ZfcUser; -use Zend\ModuleManager\ModuleManager; use Zend\ModuleManager\Feature\AutoloaderProviderInterface; use Zend\ModuleManager\Feature\ConfigProviderInterface; use Zend\ModuleManager\Feature\ServiceProviderInterface; -use Zend\Stdlib\Hydrator\ClassMethods; class Module implements AutoloaderProviderInterface, @@ -36,15 +34,16 @@ public function getControllerPluginConfig() { return array( 'factories' => array( - 'zfcUserAuthentication' => function ($sm) { - $serviceLocator = $sm->getServiceLocator(); - $authService = $serviceLocator->get('zfcuser_auth_service'); - $authAdapter = $serviceLocator->get('ZfcUser\Authentication\Adapter\AdapterChain'); - $controllerPlugin = new Controller\Plugin\ZfcUserAuthentication; - $controllerPlugin->setAuthService($authService); - $controllerPlugin->setAuthAdapter($authAdapter); - return $controllerPlugin; - }, + 'zfcUserAuthentication' => 'ZfcUser\Factory\Controller\Plugin\ZfcUserAuthentication', + ), + ); + } + + public function getControllerConfig() + { + return array( + 'factories' => array( + 'zfcuser' => 'ZfcUser\Factory\Controller\UserControllerFactory', ), ); } @@ -53,25 +52,9 @@ public function getViewHelperConfig() { return array( 'factories' => array( - 'zfcUserDisplayName' => function ($sm) { - $locator = $sm->getServiceLocator(); - $viewHelper = new View\Helper\ZfcUserDisplayName; - $viewHelper->setAuthService($locator->get('zfcuser_auth_service')); - return $viewHelper; - }, - 'zfcUserIdentity' => function ($sm) { - $locator = $sm->getServiceLocator(); - $viewHelper = new View\Helper\ZfcUserIdentity; - $viewHelper->setAuthService($locator->get('zfcuser_auth_service')); - return $viewHelper; - }, - 'zfcUserLoginWidget' => function ($sm) { - $locator = $sm->getServiceLocator(); - $viewHelper = new View\Helper\ZfcUserLoginWidget; - $viewHelper->setViewTemplate($locator->get('zfcuser_module_options')->getUserLoginWidgetViewTemplate()); - $viewHelper->setLoginForm($locator->get('zfcuser_login_form')); - return $viewHelper; - }, + 'zfcUserDisplayName' => 'ZfcUser\Factory\View\Helper\ZfcUserDisplayName', + 'zfcUserIdentity' => 'ZfcUser\Factory\View\Helper\ZfcUserIdentity', + 'zfcUserLoginWidget' => 'ZfcUser\Factory\View\Helper\ZfcUserLoginWidget', ), ); @@ -80,91 +63,34 @@ public function getViewHelperConfig() public function getServiceConfig() { return array( + 'aliases' => array( + 'zfcuser_zend_db_adapter' => 'Zend\Db\Adapter\Adapter', + ), 'invokables' => array( - 'ZfcUser\Authentication\Adapter\Db' => 'ZfcUser\Authentication\Adapter\Db', - 'ZfcUser\Authentication\Storage\Db' => 'ZfcUser\Authentication\Storage\Db', - 'ZfcUser\Form\Login' => 'ZfcUser\Form\Login', - 'zfcuser_user_service' => 'ZfcUser\Service\User', 'zfcuser_register_form_hydrator' => 'Zend\Stdlib\Hydrator\ClassMethods', ), 'factories' => array( + 'zfcuser_redirect_callback' => 'ZfcUser\Factory\Controller\RedirectCallbackFactory', + 'zfcuser_module_options' => 'ZfcUser\Factory\Options\ModuleOptions', + 'ZfcUser\Authentication\Adapter\AdapterChain' => 'ZfcUser\Authentication\Adapter\AdapterChainServiceFactory', - 'zfcuser_module_options' => function ($sm) { - $config = $sm->get('Config'); - return new Options\ModuleOptions(isset($config['zfcuser']) ? $config['zfcuser'] : array()); - }, // We alias this one because it's ZfcUser's instance of // Zend\Authentication\AuthenticationService. We don't want to // hog the FQCN service alias for a Zend\* class. - 'zfcuser_auth_service' => function ($sm) { - return new \Zend\Authentication\AuthenticationService( - $sm->get('ZfcUser\Authentication\Storage\Db'), - $sm->get('ZfcUser\Authentication\Adapter\AdapterChain') - ); - }, - - 'ZfcUser\Authentication\Adapter\AdapterChain' => 'ZfcUser\Authentication\Adapter\AdapterChainServiceFactory', - - 'zfcuser_login_form' => function ($sm) { - $options = $sm->get('zfcuser_module_options'); - $form = new Form\Login(null, $options); - $form->setInputFilter(new Form\LoginFilter($options)); - return $form; - }, - - 'zfcuser_register_form' => function ($sm) { - $options = $sm->get('zfcuser_module_options'); - $form = new Form\Register(null, $options); - //$form->setCaptchaElement($sm->get('zfcuser_captcha_element')); - $form->setInputFilter(new Form\RegisterFilter( - new Validator\NoRecordExists(array( - 'mapper' => $sm->get('zfcuser_user_mapper'), - 'key' => 'email' - )), - new Validator\NoRecordExists(array( - 'mapper' => $sm->get('zfcuser_user_mapper'), - 'key' => 'username' - )), - $options - )); - return $form; - }, + 'zfcuser_auth_service' => 'ZfcUser\Factory\AuthenticationService', - 'zfcuser_change_password_form' => function ($sm) { - $options = $sm->get('zfcuser_module_options'); - $form = new Form\ChangePassword(null, $sm->get('zfcuser_module_options')); - $form->setInputFilter(new Form\ChangePasswordFilter($options)); - return $form; - }, + 'zfcuser_user_hydrator' => 'ZfcUser\Factory\UserHydrator', + 'zfcuser_user_mapper' => 'ZfcUser\Factory\Mapper\User', - 'zfcuser_change_email_form' => function ($sm) { - $options = $sm->get('zfcuser_module_options'); - $form = new Form\ChangeEmail(null, $options); - $form->setInputFilter(new Form\ChangeEmailFilter( - $options, - new Validator\NoRecordExists(array( - 'mapper' => $sm->get('zfcuser_user_mapper'), - 'key' => 'email' - )) - )); - return $form; - }, + 'zfcuser_login_form' => 'ZfcUser\Factory\Form\Login', + 'zfcuser_register_form' => 'ZfcUser\Factory\Form\Register', + 'zfcuser_change_password_form' => 'ZfcUser\Factory\Form\ChangePassword', + 'zfcuser_change_email_form' => 'ZfcUser\Factory\Form\ChangeEmail', - 'zfcuser_user_hydrator' => function ($sm) { - $hydrator = new \Zend\Stdlib\Hydrator\ClassMethods(); - return $hydrator; - }, + 'ZfcUser\Authentication\Adapter\Db' => 'ZfcUser\Factory\Authentication\Adapter\DbFactory', + 'ZfcUser\Authentication\Storage\Db' => 'ZfcUser\Factory\Authentication\Storage\DbFactory', - 'zfcuser_user_mapper' => function ($sm) { - $options = $sm->get('zfcuser_module_options'); - $mapper = new Mapper\User(); - $mapper->setDbAdapter($sm->get('zfcuser_zend_db_adapter')); - $entityClass = $options->getUserEntityClass(); - $mapper->setEntityPrototype(new $entityClass); - $mapper->setHydrator(new Mapper\UserHydrator()); - $mapper->setTableName($options->getTableName()); - return $mapper; - }, + 'zfcuser_user_service' => 'ZfcUser\Factory\Service\UserFactory', ), ); } diff --git a/README.md b/README.md index 20eafc84..ae56404e 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ ZfcUser is a user registration and authentication module for Zend Framework 2. Out of the box, ZfcUser works with Zend\Db, however alternative storage adapter modules are available (see below). ZfcUser provides the foundations for adding user authentication and registration to your ZF2 site. It is designed to be very -simple and easily to extend. +simple and easy to extend. More information and examples are available on the [ZfcUser Wiki](https://github.com/ZF-Commons/ZfcUser/wiki) @@ -86,7 +86,6 @@ Installation return array( 'modules' => array( // ... - 'ZfcBase', 'ZfcUser', ), // ... diff --git a/composer.json b/composer.json index a2d0de32..4a97f21e 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ } }, "require": { - "php": ">=5.3.3", + "php": "^5.3.3|~7.0", "zendframework/zend-authentication": "~2.1", "zendframework/zend-crypt": "~2.1", "zendframework/zend-form": "~2.1", diff --git a/config/module.config.php b/config/module.config.php index dc8e572e..e8f022d1 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -1,20 +1,12 @@ array( 'template_path_stack' => array( 'zfcuser' => __DIR__ . '/../view', ), ), - 'controllers' => array( - 'invokables' => array( - 'zfcuser' => 'ZfcUser\Controller\UserController', - ), - ), - 'service_manager' => array( - 'aliases' => array( - 'zfcuser_zend_db_adapter' => 'Zend\Db\Adapter\Adapter', - ), - ), + 'router' => array( 'routes' => array( 'zfcuser' => array( diff --git a/config/zfcuser.global.php.dist b/config/zfcuser.global.php.dist index 05c13c54..c7b53f35 100644 --- a/config/zfcuser.global.php.dist +++ b/config/zfcuser.global.php.dist @@ -158,7 +158,7 @@ $settings = array( /** * Logout Redirect Route * - * Upon logging out the user will be redirected to the enterd route + * Upon logging out the user will be redirected to the entered route * * Default value: 'zfcuser/login' * Accepted values: A valid route name within your application diff --git a/src/ZfcUser/Authentication/Adapter/Db.php b/src/ZfcUser/Authentication/Adapter/Db.php index c37824f8..b07744ca 100644 --- a/src/ZfcUser/Authentication/Adapter/Db.php +++ b/src/ZfcUser/Authentication/Adapter/Db.php @@ -2,9 +2,7 @@ namespace ZfcUser\Authentication\Adapter; -use DateTime; use Zend\Authentication\Result as AuthenticationResult; -use Zend\ServiceManager\ServiceManagerAwareInterface; use Zend\ServiceManager\ServiceManager; use Zend\Crypt\Password\Bcrypt; use Zend\Session\Container as SessionContainer; @@ -12,7 +10,7 @@ use ZfcUser\Mapper\User as UserMapperInterface; use ZfcUser\Options\AuthenticationOptionsInterface; -class Db extends AbstractAdapter implements ServiceManagerAwareInterface +class Db extends AbstractAdapter { /** * @var UserMapperInterface @@ -40,8 +38,7 @@ class Db extends AbstractAdapter implements ServiceManagerAwareInterface */ public function logout(AuthEvent $e) { - $session = new SessionContainer($this->getStorage()->getNameSpace()); - $session->getManager()->destroy(); + $this->getStorage()->clear(); } public function authenticate(AuthEvent $e) diff --git a/src/ZfcUser/Authentication/Storage/Db.php b/src/ZfcUser/Authentication/Storage/Db.php index 3a5b1d36..62bdef8f 100644 --- a/src/ZfcUser/Authentication/Storage/Db.php +++ b/src/ZfcUser/Authentication/Storage/Db.php @@ -4,11 +4,10 @@ use Zend\Authentication\Storage; use Zend\Authentication\Storage\StorageInterface; -use Zend\ServiceManager\ServiceManagerAwareInterface; use Zend\ServiceManager\ServiceManager; use ZfcUser\Mapper\UserInterface as UserMapper; -class Db implements Storage\StorageInterface, ServiceManagerAwareInterface +class Db implements Storage\StorageInterface { /** * @var StorageInterface @@ -42,7 +41,7 @@ public function isEmpty() if ($this->getStorage()->isEmpty()) { return true; } - $identity = $this->read(); + $identity = $this->getStorage()->read(); if ($identity === null) { $this->clear(); return true; diff --git a/src/ZfcUser/Controller/RedirectCallback.php b/src/ZfcUser/Controller/RedirectCallback.php new file mode 100644 index 00000000..273fea85 --- /dev/null +++ b/src/ZfcUser/Controller/RedirectCallback.php @@ -0,0 +1,118 @@ +router = $router; + $this->application = $application; + $this->options = $options; + } + + /** + * @return Response + */ + public function __invoke() + { + $routeMatch = $this->application->getMvcEvent()->getRouteMatch(); + $redirect = $this->getRedirect($routeMatch->getMatchedRouteName(), $this->getRedirectRouteFromRequest()); + + $response = $this->application->getResponse(); + $response->getHeaders()->addHeaderLine('Location', $redirect); + $response->setStatusCode(302); + return $response; + } + + /** + * Return the redirect from param. + * First checks GET then POST + * @return string + */ + private function getRedirectRouteFromRequest() + { + $request = $this->application->getRequest(); + $redirect = $request->getQuery('redirect'); + if ($redirect && $this->routeExists($redirect)) { + return $redirect; + } + + $redirect = $request->getPost('redirect'); + if ($redirect && $this->routeExists($redirect)) { + return $redirect; + } + + return false; + } + + /** + * @param $route + * @return bool + */ + private function routeExists($route) + { + try { + $this->router->assemble(array(), array('name' => $route)); + } catch (Exception\RuntimeException $e) { + return false; + } + return true; + } + + /** + * Returns the url to redirect to based on current route. + * If $redirect is set and the option to use redirect is set to true, it will return the $redirect url. + * + * @param string $currentRoute + * @param bool $redirect + * @return mixed + */ + protected function getRedirect($currentRoute, $redirect = false) + { + $useRedirect = $this->options->getUseRedirectParameterIfPresent(); + $routeExists = ($redirect && $this->routeExists($redirect)); + if (!$useRedirect || !$routeExists) { + $redirect = false; + } + + switch ($currentRoute) { + case 'zfcuser/register': + case 'zfcuser/login': + case 'zfcuser/authenticate': + $route = ($redirect) ?: $this->options->getLoginRedirectRoute(); + return $this->router->assemble(array(), array('name' => $route)); + break; + case 'zfcuser/logout': + $route = ($redirect) ?: $this->options->getLogoutRedirectRoute(); + return $this->router->assemble(array(), array('name' => $route)); + break; + default: + return $this->router->assemble(array(), array('name' => 'zfcuser')); + } + } +} diff --git a/src/ZfcUser/Controller/UserController.php b/src/ZfcUser/Controller/UserController.php index 228222a7..48c42df0 100644 --- a/src/ZfcUser/Controller/UserController.php +++ b/src/ZfcUser/Controller/UserController.php @@ -2,8 +2,9 @@ namespace ZfcUser\Controller; -use Zend\Form\Form; +use Zend\Form\FormInterface; use Zend\Mvc\Controller\AbstractActionController; +use Zend\ServiceManager\ServiceLocatorInterface; use Zend\Stdlib\ResponseInterface as Response; use Zend\Stdlib\Parameters; use Zend\View\Model\ViewModel; @@ -25,22 +26,22 @@ class UserController extends AbstractActionController protected $userService; /** - * @var Form + * @var FormInterface */ protected $loginForm; /** - * @var Form + * @var FormInterface */ protected $registerForm; /** - * @var Form + * @var FormInterface */ protected $changePasswordForm; /** - * @var Form + * @var FormInterface */ protected $changeEmailForm; @@ -55,6 +56,27 @@ class UserController extends AbstractActionController */ protected $options; + /** + * @var callable $redirectCallback + */ + protected $redirectCallback; + + /** + * @var ServiceLocatorInterface + */ + protected $serviceLocator; + + /** + * @param callable $redirectCallback + */ + public function __construct($redirectCallback) + { + if (!is_callable($redirectCallback)) { + throw new \InvalidArgumentException('You must supply a callable redirectCallback'); + } + $this->redirectCallback = $redirectCallback; + } + /** * User page */ @@ -115,13 +137,9 @@ public function logoutAction() $this->zfcUserAuthentication()->getAuthAdapter()->logoutAdapters(); $this->zfcUserAuthentication()->getAuthService()->clearIdentity(); - $redirect = $this->params()->fromPost('redirect', $this->params()->fromQuery('redirect', false)); - - if ($this->getOptions()->getUseRedirectParameterIfPresent() && $redirect) { - return $this->redirect()->toUrl($redirect); - } + $redirect = $this->redirectCallback; - return $this->redirect()->toRoute($this->getOptions()->getLogoutRedirectRoute()); + return $redirect(); } /** @@ -154,11 +172,9 @@ public function authenticateAction() ); } - if ($this->getOptions()->getUseRedirectParameterIfPresent() && $redirect) { - return $this->redirect()->toUrl($redirect); - } + $redirect = $this->redirectCallback; - return $this->redirect()->toRoute($this->getOptions()->getLoginRedirectRoute()); + return $redirect(); } /** @@ -338,7 +354,7 @@ public function changeEmailAction() public function getUserService() { if (!$this->userService) { - $this->userService = $this->getServiceLocator()->get('zfcuser_user_service'); + $this->userService = $this->serviceLocator->get('zfcuser_user_service'); } return $this->userService; } @@ -352,12 +368,12 @@ public function setUserService(UserService $userService) public function getRegisterForm() { if (!$this->registerForm) { - $this->setRegisterForm($this->getServiceLocator()->get('zfcuser_register_form')); + $this->setRegisterForm($this->serviceLocator->get('zfcuser_register_form')); } return $this->registerForm; } - public function setRegisterForm(Form $registerForm) + public function setRegisterForm(FormInterface$registerForm) { $this->registerForm = $registerForm; } @@ -365,12 +381,12 @@ public function setRegisterForm(Form $registerForm) public function getLoginForm() { if (!$this->loginForm) { - $this->setLoginForm($this->getServiceLocator()->get('zfcuser_login_form')); + $this->setLoginForm($this->serviceLocator->get('zfcuser_login_form')); } return $this->loginForm; } - public function setLoginForm(Form $loginForm) + public function setLoginForm(FormInterface $loginForm) { $this->loginForm = $loginForm; $fm = $this->flashMessenger()->setNamespace('zfcuser-login-form')->getMessages(); @@ -385,12 +401,12 @@ public function setLoginForm(Form $loginForm) public function getChangePasswordForm() { if (!$this->changePasswordForm) { - $this->setChangePasswordForm($this->getServiceLocator()->get('zfcuser_change_password_form')); + $this->setChangePasswordForm($this->serviceLocator->get('zfcuser_change_password_form')); } return $this->changePasswordForm; } - public function setChangePasswordForm(Form $changePasswordForm) + public function setChangePasswordForm(FormInterface $changePasswordForm) { $this->changePasswordForm = $changePasswordForm; return $this; @@ -416,20 +432,19 @@ public function setOptions(UserControllerOptionsInterface $options) public function getOptions() { if (!$this->options instanceof UserControllerOptionsInterface) { - $this->setOptions($this->getServiceLocator()->get('zfcuser_module_options')); + $this->setOptions($this->serviceLocator->get('zfcuser_module_options')); } return $this->options; } /** * Get changeEmailForm. - * - * @return changeEmailForm. + * @return ChangeEmailForm */ public function getChangeEmailForm() { if (!$this->changeEmailForm) { - $this->setChangeEmailForm($this->getServiceLocator()->get('zfcuser_change_email_form')); + $this->setChangeEmailForm($this->serviceLocator->get('zfcuser_change_email_form')); } return $this->changeEmailForm; } @@ -437,7 +452,8 @@ public function getChangeEmailForm() /** * Set changeEmailForm. * - * @param changeEmailForm the value to set. + * @param $changeEmailForm - the value to set. + * @return $this */ public function setChangeEmailForm($changeEmailForm) { diff --git a/src/ZfcUser/Factory/Authentication/Adapter/DbFactory.php b/src/ZfcUser/Factory/Authentication/Adapter/DbFactory.php new file mode 100644 index 00000000..9766089f --- /dev/null +++ b/src/ZfcUser/Factory/Authentication/Adapter/DbFactory.php @@ -0,0 +1,24 @@ +setServiceManager($serviceLocator); + return $db; + } +} diff --git a/src/ZfcUser/Factory/Authentication/Storage/DbFactory.php b/src/ZfcUser/Factory/Authentication/Storage/DbFactory.php new file mode 100644 index 00000000..fa8a274f --- /dev/null +++ b/src/ZfcUser/Factory/Authentication/Storage/DbFactory.php @@ -0,0 +1,24 @@ +setServiceManager($serviceLocator); + return $db; + } +} diff --git a/src/ZfcUser/Factory/AuthenticationService.php b/src/ZfcUser/Factory/AuthenticationService.php new file mode 100644 index 00000000..40881610 --- /dev/null +++ b/src/ZfcUser/Factory/AuthenticationService.php @@ -0,0 +1,30 @@ +get('ZfcUser\Authentication\Storage\Db'), + $serviceLocator->get('ZfcUser\Authentication\Adapter\AdapterChain') + ); + } +} diff --git a/src/ZfcUser/Factory/Controller/Plugin/ZfcUserAuthentication.php b/src/ZfcUser/Factory/Controller/Plugin/ZfcUserAuthentication.php new file mode 100644 index 00000000..d4729c12 --- /dev/null +++ b/src/ZfcUser/Factory/Controller/Plugin/ZfcUserAuthentication.php @@ -0,0 +1,34 @@ +getServiceLocator(); + $authService = $serviceLocator->get('zfcuser_auth_service'); + $authAdapter = $serviceLocator->get('ZfcUser\Authentication\Adapter\AdapterChain'); + $controllerPlugin = new Controller\Plugin\ZfcUserAuthentication; + $controllerPlugin->setAuthService($authService); + $controllerPlugin->setAuthAdapter($authAdapter); + return $controllerPlugin; + } +} diff --git a/src/ZfcUser/Factory/Controller/RedirectCallbackFactory.php b/src/ZfcUser/Factory/Controller/RedirectCallbackFactory.php new file mode 100644 index 00000000..d3ea60b7 --- /dev/null +++ b/src/ZfcUser/Factory/Controller/RedirectCallbackFactory.php @@ -0,0 +1,40 @@ +get('Router'); + + /* @var Application $application */ + $application = $serviceLocator->get('Application'); + + /* @var ModuleOptions $options */ + $options = $serviceLocator->get('zfcuser_module_options'); + + return new RedirectCallback($application, $router, $options); + } +} diff --git a/src/ZfcUser/Factory/Controller/UserControllerFactory.php b/src/ZfcUser/Factory/Controller/UserControllerFactory.php new file mode 100644 index 00000000..88122b4d --- /dev/null +++ b/src/ZfcUser/Factory/Controller/UserControllerFactory.php @@ -0,0 +1,47 @@ +getServiceLocator(); + + /* @var RedirectCallback $redirectCallback */ + $redirectCallback = $serviceManager->get('zfcuser_redirect_callback'); + + /* @var UserController $controller */ + $controller = new UserController($redirectCallback); + $controller->setServiceLocator($serviceManager); + + $controller->setChangeEmailForm($serviceManager->get('zfcuser_change_email_form')); + $controller->setOptions($serviceManager->get('zfcuser_module_options')); + $controller->setChangePasswordForm($serviceManager->get('zfcuser_change_password_form')); + $controller->setLoginForm($serviceManager->get('zfcuser_login_form')); + $controller->setRegisterForm($serviceManager->get('zfcuser_register_form')); + $controller->setUserService($serviceManager->get('zfcuser_user_service')); + + return $controller; + } +} diff --git a/src/ZfcUser/Factory/Form/ChangeEmail.php b/src/ZfcUser/Factory/Form/ChangeEmail.php new file mode 100644 index 00000000..fbb4d081 --- /dev/null +++ b/src/ZfcUser/Factory/Form/ChangeEmail.php @@ -0,0 +1,44 @@ +getServiceLocator(); + $fem = $formElementManager; + } else { + $sm = $formElementManager; + $fem = $sm->get('FormElementManager'); + } + + $options = $sm->get('zfcuser_module_options'); + $form = new Form\ChangeEmail(null, $options); + // Inject the FormElementManager to support custom FormElements + $form->getFormFactory()->setFormElementManager($fem); + + $form->setInputFilter(new Form\ChangeEmailFilter( + $options, + new Validator\NoRecordExists(array( + 'mapper' => $sm->get('zfcuser_user_mapper'), + 'key' => 'email' + )) + )); + + return $form; + } +} diff --git a/src/ZfcUser/Factory/Form/ChangePassword.php b/src/ZfcUser/Factory/Form/ChangePassword.php new file mode 100644 index 00000000..42f7065a --- /dev/null +++ b/src/ZfcUser/Factory/Form/ChangePassword.php @@ -0,0 +1,37 @@ +getServiceLocator(); + $fem = $formElementManager; + } else { + $sm = $formElementManager; + $fem = $sm->get('FormElementManager'); + } + + $options = $sm->get('zfcuser_module_options'); + $form = new Form\ChangePassword(null, $options); + // Inject the FormElementManager to support custom FormElements + $form->getFormFactory()->setFormElementManager($fem); + + $form->setInputFilter(new Form\ChangePasswordFilter($options)); + + return $form; + } +} diff --git a/src/ZfcUser/Factory/Form/Login.php b/src/ZfcUser/Factory/Form/Login.php new file mode 100644 index 00000000..4690d0ba --- /dev/null +++ b/src/ZfcUser/Factory/Form/Login.php @@ -0,0 +1,38 @@ +getServiceLocator(); + $fem = $formElementManager; + } else { + $sm = $formElementManager; + $fem = $sm->get('FormElementManager'); + } + + /** @var FormElementManager $formElementManager */ + $options = $sm->get('zfcuser_module_options'); + $form = new Form\Login(null, $options); + // Inject the FormElementManager to support custom FormElements + $form->getFormFactory()->setFormElementManager($fem); + + $form->setInputFilter(new Form\LoginFilter($options)); + + return $form; + } +} diff --git a/src/ZfcUser/Factory/Form/Register.php b/src/ZfcUser/Factory/Form/Register.php new file mode 100644 index 00000000..7bf24df1 --- /dev/null +++ b/src/ZfcUser/Factory/Form/Register.php @@ -0,0 +1,50 @@ +getServiceLocator(); + $fem = $formElementManager; + } else { + $sm = $formElementManager; + $fem = $sm->get('FormElementManager'); + } + + $options = $sm->get('zfcuser_module_options'); + $form = new Form\Register(null, $options); + // Inject the FormElementManager to support custom FormElements + $form->getFormFactory()->setFormElementManager($fem); + + //$form->setCaptchaElement($sm->get('zfcuser_captcha_element')); + $form->setHydrator($sm->get('zfcuser_register_form_hydrator')); + $form->setInputFilter(new Form\RegisterFilter( + new Validator\NoRecordExists(array( + 'mapper' => $sm->get('zfcuser_user_mapper'), + 'key' => 'email' + )), + new Validator\NoRecordExists(array( + 'mapper' => $sm->get('zfcuser_user_mapper'), + 'key' => 'username' + )), + $options + )); + + return $form; + } +} diff --git a/src/ZfcUser/Factory/Mapper/User.php b/src/ZfcUser/Factory/Mapper/User.php new file mode 100644 index 00000000..ef4f7c50 --- /dev/null +++ b/src/ZfcUser/Factory/Mapper/User.php @@ -0,0 +1,35 @@ +get('zfcuser_module_options'); + $mapper = new Mapper\User(); + $mapper->setDbAdapter($serviceLocator->get('zfcuser_zend_db_adapter')); + $entityClass = $options->getUserEntityClass(); + $mapper->setEntityPrototype(new $entityClass); + $mapper->setHydrator(new Mapper\UserHydrator()); + $mapper->setTableName($options->getTableName()); + return $mapper; + } +} diff --git a/src/ZfcUser/Factory/Options/ModuleOptions.php b/src/ZfcUser/Factory/Options/ModuleOptions.php new file mode 100644 index 00000000..c4173fbc --- /dev/null +++ b/src/ZfcUser/Factory/Options/ModuleOptions.php @@ -0,0 +1,30 @@ +get('Config'); + return new Options\ModuleOptions(isset($config['zfcuser']) ? $config['zfcuser'] : array()); + } +} diff --git a/src/ZfcUser/Factory/Service/UserFactory.php b/src/ZfcUser/Factory/Service/UserFactory.php new file mode 100644 index 00000000..1c22ee0e --- /dev/null +++ b/src/ZfcUser/Factory/Service/UserFactory.php @@ -0,0 +1,24 @@ +setServiceManager($serviceLocator); + return $service; + } +} diff --git a/src/ZfcUser/Factory/UserHydrator.php b/src/ZfcUser/Factory/UserHydrator.php new file mode 100644 index 00000000..12ad6a50 --- /dev/null +++ b/src/ZfcUser/Factory/UserHydrator.php @@ -0,0 +1,27 @@ +getServiceLocator(); + $viewHelper = new View\Helper\ZfcUserDisplayName; + $viewHelper->setAuthService($locator->get('zfcuser_auth_service')); + return $viewHelper; + } +} diff --git a/src/ZfcUser/Factory/View/Helper/ZfcUserIdentity.php b/src/ZfcUser/Factory/View/Helper/ZfcUserIdentity.php new file mode 100644 index 00000000..31615927 --- /dev/null +++ b/src/ZfcUser/Factory/View/Helper/ZfcUserIdentity.php @@ -0,0 +1,31 @@ +getServiceLocator(); + $viewHelper = new View\Helper\ZfcUserIdentity; + $viewHelper->setAuthService($locator->get('zfcuser_auth_service')); + return $viewHelper; + } +} diff --git a/src/ZfcUser/Factory/View/Helper/ZfcUserLoginWidget.php b/src/ZfcUser/Factory/View/Helper/ZfcUserLoginWidget.php new file mode 100644 index 00000000..7d02db62 --- /dev/null +++ b/src/ZfcUser/Factory/View/Helper/ZfcUserLoginWidget.php @@ -0,0 +1,32 @@ +getServiceLocator(); + $viewHelper = new View\Helper\ZfcUserLoginWidget; + $viewHelper->setViewTemplate($locator->get('zfcuser_module_options')->getUserLoginWidgetViewTemplate()); + $viewHelper->setLoginForm($locator->get('zfcuser_login_form')); + return $viewHelper; + } +} diff --git a/src/ZfcUser/Form/Base.php b/src/ZfcUser/Form/Base.php index c3db48a8..f6b47faf 100644 --- a/src/ZfcUser/Form/Base.php +++ b/src/ZfcUser/Form/Base.php @@ -2,7 +2,6 @@ namespace ZfcUser\Form; -use Zend\Form\Form; use Zend\Form\Element; use ZfcBase\Form\ProvidesEventsForm; @@ -44,6 +43,7 @@ public function __construct() $this->add(array( 'name' => 'password', + 'type' => 'password', 'options' => array( 'label' => 'Password', ), @@ -54,6 +54,7 @@ public function __construct() $this->add(array( 'name' => 'passwordVerify', + 'type' => 'password', 'options' => array( 'label' => 'Password Verify', ), @@ -62,17 +63,6 @@ public function __construct() ), )); - if ($this->getRegistrationOptions()->getUseRegistrationFormCaptcha()) { - $this->add(array( - 'name' => 'captcha', - 'type' => 'Zend\Form\Element\Captcha', - 'options' => array( - 'label' => 'Please type the following text', - 'captcha' => $this->getRegistrationOptions()->getFormCaptchaOptions(), - ), - )); - } - $submitElement = new Element\Button('submit'); $submitElement ->setLabel('Submit') @@ -96,5 +86,11 @@ public function __construct() //$csrf = new Element\Csrf('csrf'); //$csrf->getValidator()->setTimeout($this->getRegistrationOptions()->getUserFormTimeout()); //$this->add($csrf); + + $this->getEventManager()->trigger('init', $this); + } + + public function init() + { } } diff --git a/src/ZfcUser/Form/ChangeEmail.php b/src/ZfcUser/Form/ChangeEmail.php index f855a5d4..5385168b 100644 --- a/src/ZfcUser/Form/ChangeEmail.php +++ b/src/ZfcUser/Form/ChangeEmail.php @@ -3,7 +3,6 @@ namespace ZfcUser\Form; use ZfcBase\Form\ProvidesEventsForm; -use ZfcUser\Options\RegistrationOptionsInterface; use ZfcUser\Options\AuthenticationOptionsInterface; class ChangeEmail extends ProvidesEventsForm @@ -45,6 +44,7 @@ public function __construct($name, AuthenticationOptionsInterface $options) $this->add(array( 'name' => 'credential', + 'type' => 'password', 'options' => array( 'label' => 'Password', ), @@ -53,6 +53,14 @@ public function __construct($name, AuthenticationOptionsInterface $options) ), )); + $this->add(array( + 'name' => 'submit', + 'attributes' => array( + 'value' => 'Submit', + 'type' => 'submit' + ), + )); + $this->getEventManager()->trigger('init', $this); } diff --git a/src/ZfcUser/Form/ChangePassword.php b/src/ZfcUser/Form/ChangePassword.php index 43745e5d..47b274fa 100644 --- a/src/ZfcUser/Form/ChangePassword.php +++ b/src/ZfcUser/Form/ChangePassword.php @@ -2,11 +2,8 @@ namespace ZfcUser\Form; -use Zend\Form\Form; -use Zend\Form\Element\Csrf; use ZfcBase\Form\ProvidesEventsForm; use ZfcUser\Options\AuthenticationOptionsInterface; -use ZfcUser\Module as ZfcUser; class ChangePassword extends ProvidesEventsForm { @@ -32,6 +29,7 @@ public function __construct($name, AuthenticationOptionsInterface $options) $this->add(array( 'name' => 'credential', + 'type' => 'password', 'options' => array( 'label' => 'Current Password', ), @@ -52,6 +50,7 @@ public function __construct($name, AuthenticationOptionsInterface $options) $this->add(array( 'name' => 'newCredentialVerify', + 'type' => 'password', 'options' => array( 'label' => 'Verify New Password', ), diff --git a/src/ZfcUser/Form/Login.php b/src/ZfcUser/Form/Login.php index 2112c8fd..dcb01e5d 100644 --- a/src/ZfcUser/Form/Login.php +++ b/src/ZfcUser/Form/Login.php @@ -2,11 +2,9 @@ namespace ZfcUser\Form; -use Zend\Form\Form; use Zend\Form\Element; use ZfcBase\Form\ProvidesEventsForm; use ZfcUser\Options\AuthenticationOptionsInterface; -use ZfcUser\Module as ZfcUser; class Login extends ProvidesEventsForm { @@ -40,6 +38,7 @@ public function __construct($name, AuthenticationOptionsInterface $options) // $this->add(array( 'name' => 'credential', + 'type' => 'password', 'options' => array( 'label' => 'Password', ), diff --git a/src/ZfcUser/Form/Register.php b/src/ZfcUser/Form/Register.php index aaa56f1f..413b8e22 100644 --- a/src/ZfcUser/Form/Register.php +++ b/src/ZfcUser/Form/Register.php @@ -23,6 +23,17 @@ public function __construct($name, RegistrationOptionsInterface $options) $this->setRegistrationOptions($options); parent::__construct($name); + if ($this->getRegistrationOptions()->getUseRegistrationFormCaptcha()) { + $this->add(array( + 'name' => 'captcha', + 'type' => 'Zend\Form\Element\Captcha', + 'options' => array( + 'label' => 'Please type the following text', + 'captcha' => $this->getRegistrationOptions()->getFormCaptchaOptions(), + ), + )); + } + $this->remove('userId'); if (!$this->getRegistrationOptions()->getEnableUsername()) { $this->remove('username'); @@ -34,7 +45,6 @@ public function __construct($name, RegistrationOptionsInterface $options) $this->add($this->captchaElement, array('name'=>'captcha')); } $this->get('submit')->setLabel('Register'); - $this->getEventManager()->trigger('init', $this); } public function setCaptchaElement(Captcha $captchaElement) diff --git a/src/ZfcUser/Form/RegisterFilter.php b/src/ZfcUser/Form/RegisterFilter.php index 071fdcc6..399c7699 100644 --- a/src/ZfcUser/Form/RegisterFilter.php +++ b/src/ZfcUser/Form/RegisterFilter.php @@ -134,6 +134,7 @@ public function setUsernameValidator($usernameValidator) public function setOptions(RegistrationOptionsInterface $options) { $this->options = $options; + return $this; } /** diff --git a/src/ZfcUser/Service/User.php b/src/ZfcUser/Service/User.php index 295fec6c..b865823c 100644 --- a/src/ZfcUser/Service/User.php +++ b/src/ZfcUser/Service/User.php @@ -4,7 +4,6 @@ use Zend\Authentication\AuthenticationService; use Zend\Form\Form; -use Zend\ServiceManager\ServiceManagerAwareInterface; use Zend\ServiceManager\ServiceManager; use Zend\Crypt\Password\Bcrypt; use Zend\Stdlib\Hydrator; @@ -12,7 +11,7 @@ use ZfcUser\Mapper\UserInterface as UserMapperInterface; use ZfcUser\Options\UserServiceOptionsInterface; -class User extends EventProvider implements ServiceManagerAwareInterface +class User extends EventProvider { /** @@ -90,9 +89,7 @@ public function register(array $data) // If user state is enabled, set the default state value if ($this->getOptions()->getEnableUserState()) { - if ($this->getOptions()->getDefaultUserState()) { - $user->setState($this->getOptions()->getDefaultUserState()); - } + $user->setState($this->getOptions()->getDefaultUserState()); } $this->getEventManager()->trigger(__FUNCTION__, $this, array('user' => $user, 'form' => $form)); $this->getUserMapper()->insert($user); @@ -123,9 +120,9 @@ public function changePassword(array $data) $pass = $bcrypt->create($newPass); $currentUser->setPassword($pass); - $this->getEventManager()->trigger(__FUNCTION__, $this, array('user' => $currentUser)); + $this->getEventManager()->trigger(__FUNCTION__, $this, array('user' => $currentUser, 'data' => $data)); $this->getUserMapper()->update($currentUser); - $this->getEventManager()->trigger(__FUNCTION__.'.post', $this, array('user' => $currentUser)); + $this->getEventManager()->trigger(__FUNCTION__.'.post', $this, array('user' => $currentUser, 'data' => $data)); return true; } @@ -143,9 +140,9 @@ public function changeEmail(array $data) $currentUser->setEmail($data['newIdentity']); - $this->getEventManager()->trigger(__FUNCTION__, $this, array('user' => $currentUser)); + $this->getEventManager()->trigger(__FUNCTION__, $this, array('user' => $currentUser, 'data' => $data)); $this->getUserMapper()->update($currentUser); - $this->getEventManager()->trigger(__FUNCTION__.'.post', $this, array('user' => $currentUser)); + $this->getEventManager()->trigger(__FUNCTION__.'.post', $this, array('user' => $currentUser, 'data' => $data)); return true; } diff --git a/src/ZfcUser/language/cs_CZ.mo b/src/ZfcUser/language/cs_CZ.mo new file mode 100644 index 00000000..f49a7ef6 Binary files /dev/null and b/src/ZfcUser/language/cs_CZ.mo differ diff --git a/src/ZfcUser/language/cs_CZ.po b/src/ZfcUser/language/cs_CZ.po new file mode 100644 index 00000000..5a2e6e99 --- /dev/null +++ b/src/ZfcUser/language/cs_CZ.po @@ -0,0 +1,126 @@ +msgid "" +msgstr "" +"Project-Id-Version: ZfcUser\n" +"POT-Creation-Date: 2015-02-09 15:35+0100\n" +"PO-Revision-Date: 2015-02-09 15:36+0100\n" +"Last-Translator: Martin Vagovszký \n" +"Language-Team: ZF Contibutors \n" +"Language: cs_CZ\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 1.5.7\n" +"X-Poedit-KeywordsList: translate\n" +"X-Poedit-Basepath: ../../../\n" +"X-Poedit-SourceCharset: UTF-8\n" +"X-Poedit-SearchPath-0: .\n" + +#: src/ZfcUser/language/msgIds.php:6 +msgid "Username" +msgstr "Uživatelské jméno" + +#: src/ZfcUser/language/msgIds.php:7 +msgid "Email" +msgstr "Email" + +#: src/ZfcUser/language/msgIds.php:8 +msgid "New Email" +msgstr "Nový email" + +#: src/ZfcUser/language/msgIds.php:9 +msgid "Verify New Email" +msgstr "Ověření nového emailu" + +#: src/ZfcUser/language/msgIds.php:10 +msgid "Display Name" +msgstr "Zobrazované jméno" + +#: src/ZfcUser/language/msgIds.php:11 +msgid "Password" +msgstr "Heslo" + +#: src/ZfcUser/language/msgIds.php:12 +msgid "Password Verify" +msgstr "Ověření hesla" + +#: src/ZfcUser/language/msgIds.php:13 +msgid "Current Password" +msgstr "Současné heslo" + +#: src/ZfcUser/language/msgIds.php:14 +msgid "Verify New Password" +msgstr "Ověření nového hesla" + +#: src/ZfcUser/language/msgIds.php:15 +msgid "New Password" +msgstr "Nové heslo" + +#: src/ZfcUser/language/msgIds.php:16 +msgid "Please type the following text" +msgstr "Prosím opište následující text" + +#: src/ZfcUser/language/msgIds.php:17 +msgid "Submit" +msgstr "Odeslat" + +#: src/ZfcUser/language/msgIds.php:18 view/zfc-user/user/login.phtml:1 +msgid "Sign In" +msgstr "Přihlášení" + +#: src/ZfcUser/language/msgIds.php:19 view/zfc-user/user/register.phtml:1 +msgid "Register" +msgstr "Registrace" + +#: src/ZfcUser/language/msgIds.php:20 +msgid "No record matching the input was found" +msgstr "Nenalezen žádný záznam odpovídající danému zadání" + +#: src/ZfcUser/language/msgIds.php:21 +msgid "A record matching the input was found" +msgstr "Byl nalezen záznam odpovídající zadání" + +#: src/ZfcUser/language/msgIds.php:22 +msgid "Authentication failed. Please try again." +msgstr "Autentizace selhala. Prosím zkuste to znovu." + +#: view/zfc-user/user/changeemail.phtml:1 +#, php-format +msgid "Change Email for %s" +msgstr "Změna emailu pro %s" + +#: view/zfc-user/user/changeemail.phtml:3 +msgid "Email address changed successfully." +msgstr "Emailová adresa úspěšně změněna" + +#: view/zfc-user/user/changeemail.phtml:5 +msgid "Unable to update your email address. Please try again." +msgstr "Není možné změnit Vaši emailovou adresu. Zkuste to prosím znovu." + +#: view/zfc-user/user/changepassword.phtml:1 +#, php-format +msgid "Change Password for %s" +msgstr "Změna hesla pro %s" + +#: view/zfc-user/user/changepassword.phtml:3 +msgid "Password changed successfully." +msgstr "Heslo úspěšně upraveno." + +#: view/zfc-user/user/changepassword.phtml:5 +msgid "Unable to update your password. Please try again." +msgstr "Není možné upravit Vaše heslo. Zkuste to prosím později." + +#: view/zfc-user/user/index.phtml:2 +msgid "Hello" +msgstr "Dobrý den" + +#: view/zfc-user/user/index.phtml:3 +msgid "Sign Out" +msgstr "Odhlášení" + +#: view/zfc-user/user/login.phtml:31 +msgid "Not registered?" +msgstr "Nejste registrován/a?" + +#: view/zfc-user/user/login.phtml:31 +msgid "Sign up!" +msgstr "Zaregistrujte se!" diff --git a/src/ZfcUser/language/es_ES.mo b/src/ZfcUser/language/es_ES.mo new file mode 100644 index 00000000..8f65fc53 Binary files /dev/null and b/src/ZfcUser/language/es_ES.mo differ diff --git a/src/ZfcUser/language/es_ES.po b/src/ZfcUser/language/es_ES.po new file mode 100644 index 00000000..684878f7 --- /dev/null +++ b/src/ZfcUser/language/es_ES.po @@ -0,0 +1,129 @@ +msgid "" +msgstr "" +"Project-Id-Version: ZfcUser\n" +"Report-Msgid-Bugs-To: zf-devteam@zend.com\n" +"POT-Creation-Date: 2013-07-22 12:24+0300\n" +"PO-Revision-Date: 2016-05-25 18:13-0300\n" +"Last-Translator: Matias Iglesias \n" +"Language-Team: Meridiem IT Outsourcing \n" +"Language: es_ES\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 1.8.7\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: src/ZfcUser/language/msgIds.php:6 +msgid "Username" +msgstr "Nombre de usuario" + +#: src/ZfcUser/language/msgIds.php:7 +msgid "Email" +msgstr "Correo electrónico" + +#: src/ZfcUser/language/msgIds.php:8 +msgid "New Email" +msgstr "Nuevo correo electrónico" + +#: src/ZfcUser/language/msgIds.php:9 +msgid "Verify New Email" +msgstr "Confirmar correo electrónico" + +#: src/ZfcUser/language/msgIds.php:10 +msgid "Display Name" +msgstr "Nombre a mostrar" + +#: src/ZfcUser/language/msgIds.php:11 +msgid "Password" +msgstr "Contraseña" + +#: src/ZfcUser/language/msgIds.php:12 +msgid "Password Verify" +msgstr "Confirmar Contraseña" + +#: src/ZfcUser/language/msgIds.php:13 +msgid "Current Password" +msgstr "Contraseña actual" + +#: src/ZfcUser/language/msgIds.php:14 +msgid "Verify New Password" +msgstr "Confirmar nueva contraseña" + +#: src/ZfcUser/language/msgIds.php:15 +msgid "New Password" +msgstr "Nueva contraseña" + +#: src/ZfcUser/language/msgIds.php:16 +msgid "Please type the following text" +msgstr "Por favor, ingrese el siguiente texto" + +#: src/ZfcUser/language/msgIds.php:17 +msgid "Submit" +msgstr "Enviar" + +#: src/ZfcUser/language/msgIds.php:18 view/zfc-user/user/login.phtml:1 +msgid "Sign In" +msgstr "Iniciar sesión" + +#: src/ZfcUser/language/msgIds.php:19 view/zfc-user/user/register.phtml:1 +msgid "Register" +msgstr "Registrarse" + +#: src/ZfcUser/language/msgIds.php:20 +msgid "No record matching the input was found" +msgstr "No se encontraron registros coincidentes" + +#: src/ZfcUser/language/msgIds.php:21 +msgid "A record matching the input was found" +msgstr "Se encontró un registro coincidente" + +#: src/ZfcUser/language/msgIds.php:22 +msgid "Authentication failed. Please try again." +msgstr "Autenticación fallida. Por favor, intente nuevamente." + +#: view/zfc-user/user/login.phtml:31 +msgid "Not registered?" +msgstr "Aún no se ha registrado?" + +#: view/zfc-user/user/login.phtml:31 +msgid "Sign up!" +msgstr "Regístrese!" + +#: view/zfc-user/user/changeemail.phtml:1 +#, php-format +msgid "Change Email for %s" +msgstr "Cambiar correo electrónico por %s" + +#: view/zfc-user/user/changeemail.phtml:3 +msgid "Email address changed successfully." +msgstr "" +"La dirección de correo electrónico ha sido cambiada correctamente." + +#: view/zfc-user/user/changeemail.phtml:5 +msgid "Unable to update your email address. Please try again." +msgstr "" +"No se pudo actualizar su dirección de correo electrónico. Por favor, " +"intente nuevamente." + +#: view/zfc-user/user/changepassword.phtml:1 +#, php-format +msgid "Change Password for %s" +msgstr "Cambiar contraseña por %s" + +#: view/zfc-user/user/changepassword.phtml:3 +msgid "Password changed successfully." +msgstr "La contraseña ha sido actualizada correctamente." + +#: view/zfc-user/user/changepassword.phtml:5 +msgid "Unable to update your password. Please try again." +msgstr "" +"No se pudo actualizar su contraseña. Por favor, intente nuevamente." + +#: view/zfc-user/user/index.phtml:2 +msgid "Hello" +msgstr "Hola" + +#: view/zfc-user/user/index.phtml:3 +msgid "Sign Out" +msgstr "Cerrar sesión" diff --git a/src/ZfcUser/language/pt_BR.mo b/src/ZfcUser/language/pt_BR.mo new file mode 100644 index 00000000..47a3123a Binary files /dev/null and b/src/ZfcUser/language/pt_BR.mo differ diff --git a/src/ZfcUser/language/pt_BR.po b/src/ZfcUser/language/pt_BR.po new file mode 100644 index 00000000..a51235d1 --- /dev/null +++ b/src/ZfcUser/language/pt_BR.po @@ -0,0 +1,128 @@ +# +# Mihailov Vasilievic Filho , 2015. +# +msgid "" +msgstr "" +"Project-Id-Version: ZfcUser\n" +"Report-Msgid-Bugs-To: zf-devteam@zend.com\n" +"POT-Creation-Date: 2013-11-08 00:38+0100\n" +"PO-Revision-Date: 2015-05-21 00:52-0300\n" +"Last-Translator: Mihailov Vasilievic Filho \n" +"Language-Team: ZF Contibutors \n" +"Language: pt_BR\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"X-Generator: Poedit 1.6.10\n" +"Content-Transfer-Encoding: 8bit\n" + +#: src/ZfcUser/language/msgIds.php:6 +msgid "Username" +msgstr "Nome de Usuário" + +#: src/ZfcUser/language/msgIds.php:7 +msgid "Email" +msgstr "Email" + +#: src/ZfcUser/language/msgIds.php:8 +msgid "New Email" +msgstr "Novo email" + +#: src/ZfcUser/language/msgIds.php:9 +msgid "Verify New Email" +msgstr "Verificar novo email" + +#: src/ZfcUser/language/msgIds.php:10 +msgid "Display Name" +msgstr "Nome de exibição" + +#: src/ZfcUser/language/msgIds.php:11 +msgid "Password" +msgstr "Senha" + +#: src/ZfcUser/language/msgIds.php:12 +msgid "Password Verify" +msgstr "Verificação de senha" + +#: src/ZfcUser/language/msgIds.php:13 +msgid "Current Password" +msgstr "Senha atual" + +#: src/ZfcUser/language/msgIds.php:14 +msgid "Verify New Password" +msgstr "Verificar nova senha" + +#: src/ZfcUser/language/msgIds.php:15 +msgid "New Password" +msgstr "Nova senha" + +#: src/ZfcUser/language/msgIds.php:16 +msgid "Please type the following text" +msgstr "Por favor, digite o seguinte texto" + +#: src/ZfcUser/language/msgIds.php:17 +msgid "Submit" +msgstr "Enviar" + +#: src/ZfcUser/language/msgIds.php:18 view/zfc-user/user/login.phtml:1 +msgid "Sign In" +msgstr "Iniciar sessão" + +#: src/ZfcUser/language/msgIds.php:19 view/zfc-user/user/register.phtml:1 +msgid "Register" +msgstr "Registrar" + +#: src/ZfcUser/language/msgIds.php:20 +msgid "No record matching the input was found" +msgstr "Nenhum registro correspondente a entrada foi encontrado." + +#: src/ZfcUser/language/msgIds.php:21 +msgid "A record matching the input was found" +msgstr "Um registro correspondente a entrada foi encontrado." + +#: src/ZfcUser/language/msgIds.php:22 +msgid "Authentication failed. Please try again." +msgstr "A autenticação falhou. Por favor, tente novamente." + +#: view/zfc-user/user/login.phtml:31 +msgid "Not registered?" +msgstr "Não registrado?" + +#: view/zfc-user/user/login.phtml:31 +msgid "Sign up!" +msgstr "Inscreva-se!" + +#: view/zfc-user/user/changeemail.phtml:1 +#, php-format +msgid "Change Email for %s" +msgstr "Alterar email de %s" + +#: view/zfc-user/user/changeemail.phtml:3 +msgid "Email address changed successfully." +msgstr "Endereço de e-mail alterado com sucesso." + +#: view/zfc-user/user/changeemail.phtml:5 +msgid "Unable to update your email address. Please try again." +msgstr "" +"Não foi possível atualizar o seu endereço de e-mail. Por favor, tente " +"novamente." + +#: view/zfc-user/user/changepassword.phtml:1 +#, php-format +msgid "Change Password for %s" +msgstr "Mudar senha de %s" + +#: view/zfc-user/user/changepassword.phtml:3 +msgid "Password changed successfully." +msgstr "Senha alterada com sucesso." + +#: view/zfc-user/user/changepassword.phtml:5 +msgid "Unable to update your password. Please try again." +msgstr "Não foi possível atualizar a senha. Por favor, tente novamente." + +#: view/zfc-user/user/index.phtml:2 +msgid "Hello" +msgstr "Olá" + +#: view/zfc-user/user/index.phtml:3 +msgid "Sign Out" +msgstr "Sair" diff --git a/tests/ZfcUserTest/Authentication/Adapter/DbTest.php b/tests/ZfcUserTest/Authentication/Adapter/DbTest.php index 56014e82..623ad7ff 100644 --- a/tests/ZfcUserTest/Authentication/Adapter/DbTest.php +++ b/tests/ZfcUserTest/Authentication/Adapter/DbTest.php @@ -78,8 +78,7 @@ protected function setUp() public function testLogout() { $this->storage->expects($this->once()) - ->method('getNameSpace') - ->will($this->returnValue('test')); + ->method('clear'); $this->db->logout($this->authEvent); } diff --git a/tests/ZfcUserTest/Controller/RedirectCallbackTest.php b/tests/ZfcUserTest/Controller/RedirectCallbackTest.php new file mode 100644 index 00000000..86e9a14c --- /dev/null +++ b/tests/ZfcUserTest/Controller/RedirectCallbackTest.php @@ -0,0 +1,330 @@ +router = $this->getMockBuilder('Zend\Mvc\Router\RouteInterface') + ->disableOriginalConstructor() + ->getMock(); + + $this->moduleOptions = $this->getMockBuilder('ZfcUser\Options\ModuleOptions') + ->disableOriginalConstructor() + ->getMock(); + + $this->application = $this->getMockBuilder('Zend\Mvc\Application') + ->disableOriginalConstructor() + ->getMock(); + $this->setUpApplication(); + + $this->redirectCallback = new RedirectCallback( + $this->application, + $this->router, + $this->moduleOptions + ); + } + + public function testInvoke() + { + $url = 'someUrl'; + + $this->routeMatch->expects($this->once()) + ->method('getMatchedRouteName') + ->will($this->returnValue('someRoute')); + + $headers = $this->getMock('Zend\Http\Headers'); + $headers->expects($this->once()) + ->method('addHeaderLine') + ->with('Location', $url); + + $this->router->expects($this->any()) + ->method('assemble') + ->with(array(), array('name' => 'zfcuser')) + ->will($this->returnValue($url)); + + $this->response->expects($this->once()) + ->method('getHeaders') + ->will($this->returnValue($headers)); + + $this->response->expects($this->once()) + ->method('setStatusCode') + ->with(302); + + $result = $this->redirectCallback->__invoke(); + + $this->assertSame($this->response, $result); + } + + /** + * @dataProvider providerGetRedirectRouteFromRequest + */ + public function testGetRedirectRouteFromRequest($get, $post, $getRouteExists, $postRouteExists) + { + $expectedResult = false; + + $this->request->expects($this->once()) + ->method('getQuery') + ->will($this->returnValue($get)); + + if ($get) { + $this->router->expects($this->any()) + ->method('assemble') + ->with(array(), array('name' => $get)) + ->will($getRouteExists); + + if ($getRouteExists == $this->returnValue(true)) { + $expectedResult = $get; + } + } + + if (!$get || !$getRouteExists) { + $this->request->expects($this->once()) + ->method('getPost') + ->will($this->returnValue($post)); + + if ($post) { + $this->router->expects($this->any()) + ->method('assemble') + ->with(array(), array('name' => $post)) + ->will($postRouteExists); + + if ($postRouteExists == $this->returnValue(true)) { + $expectedResult = $post; + } + } + } + + $method = new \ReflectionMethod( + 'ZfcUser\Controller\RedirectCallback', + 'getRedirectRouteFromRequest' + ); + $method->setAccessible(true); + $result = $method->invoke($this->redirectCallback); + + $this->assertSame($expectedResult, $result); + } + + public function providerGetRedirectRouteFromRequest() + { + return array( + array('user', false, $this->returnValue('route'), false), + array('user', false, $this->returnValue('route'), $this->returnValue(true)), + array('user', 'user', $this->returnValue('route'), $this->returnValue(true)), + array('user', 'user', $this->throwException(new \Zend\Mvc\Router\Exception\RuntimeException), $this->returnValue(true)), + array('user', 'user', $this->throwException(new \Zend\Mvc\Router\Exception\RuntimeException), $this->throwException(new \Zend\Mvc\Router\Exception\RuntimeException)), + array(false, 'user', false, $this->returnValue(true)), + array(false, 'user', false, $this->throwException(new \Zend\Mvc\Router\Exception\RuntimeException)), + array(false, 'user', false, $this->throwException(new \Zend\Mvc\Router\Exception\RuntimeException)), + ); + } + + public function testRouteExistsRouteExists() + { + $route = 'existingRoute'; + + $this->router->expects($this->once()) + ->method('assemble') + ->with(array(), array('name' => $route)); + + $method = new \ReflectionMethod( + 'ZfcUser\Controller\RedirectCallback', + 'routeExists' + ); + $method->setAccessible(true); + $result = $method->invoke($this->redirectCallback, $route); + + $this->assertTrue($result); + } + + public function testRouteExistsRouteDoesntExists() + { + $route = 'existingRoute'; + + $this->router->expects($this->once()) + ->method('assemble') + ->with(array(), array('name' => $route)) + ->will($this->throwException(new \Zend\Mvc\Router\Exception\RuntimeException)); + + $method = new \ReflectionMethod( + 'ZfcUser\Controller\RedirectCallback', + 'routeExists' + ); + $method->setAccessible(true); + $result = $method->invoke($this->redirectCallback, $route); + + $this->assertFalse($result); + } + + /** + * @dataProvider providerGetRedirectNoRedirectParam + */ + public function testGetRedirectNoRedirectParam($currentRoute, $optionsReturn, $expectedResult, $optionsMethod) + { + $this->moduleOptions->expects($this->once()) + ->method('getUseRedirectParameterIfPresent') + ->will($this->returnValue(true)); + + $this->router->expects($this->at(0)) + ->method('assemble'); + $this->router->expects($this->at(1)) + ->method('assemble') + ->with(array(), array('name' => $optionsReturn)) + ->will($this->returnValue($expectedResult)); + + if ($optionsMethod) { + $this->moduleOptions->expects($this->never()) + ->method($optionsMethod) + ->will($this->returnValue($optionsReturn)); + } + $method = new \ReflectionMethod( + 'ZfcUser\Controller\RedirectCallback', + 'getRedirect' + ); + $method->setAccessible(true); + $result = $method->invoke($this->redirectCallback, $currentRoute, $optionsReturn); + + $this->assertSame($expectedResult, $result); + } + + public function providerGetRedirectNoRedirectParam() + { + return array( + array('zfcuser/login', 'zfcuser', '/user', 'getLoginRedirectRoute'), + array('zfcuser/authenticate', 'zfcuser', '/user', 'getLoginRedirectRoute'), + array('zfcuser/logout', 'zfcuser/login', '/user/login', 'getLogoutRedirectRoute'), + array('testDefault', 'zfcuser', '/home', false), + ); + } + + public function testGetRedirectWithOptionOnButNoRedirect() + { + $route = 'zfcuser/login'; + $redirect = false; + $expectedResult = '/user/login'; + + $this->moduleOptions->expects($this->once()) + ->method('getUseRedirectParameterIfPresent') + ->will($this->returnValue(true)); + + $this->moduleOptions->expects($this->once()) + ->method('getLoginRedirectRoute') + ->will($this->returnValue($route)); + + $this->router->expects($this->once()) + ->method('assemble') + ->with(array(), array('name' => $route)) + ->will($this->returnValue($expectedResult)); + + $method = new \ReflectionMethod( + 'ZfcUser\Controller\RedirectCallback', + 'getRedirect' + ); + $method->setAccessible(true); + $result = $method->invoke($this->redirectCallback, $route, $redirect); + + $this->assertSame($expectedResult, $result); + } + + public function testGetRedirectWithOptionOnRedirectDoesntExists() + { + $route = 'zfcuser/login'; + $redirect = 'doesntExists'; + $expectedResult = '/user/login'; + + $this->moduleOptions->expects($this->once()) + ->method('getUseRedirectParameterIfPresent') + ->will($this->returnValue(true)); + + $this->router->expects($this->at(0)) + ->method('assemble') + ->with(array(), array('name' => $redirect)) + ->will($this->throwException(new \Zend\Mvc\Router\Exception\RuntimeException)); + + $this->router->expects($this->at(1)) + ->method('assemble') + ->with(array(), array('name' => $route)) + ->will($this->returnValue($expectedResult)); + + $this->moduleOptions->expects($this->once()) + ->method('getLoginRedirectRoute') + ->will($this->returnValue($route)); + + $method = new \ReflectionMethod( + 'ZfcUser\Controller\RedirectCallback', + 'getRedirect' + ); + $method->setAccessible(true); + $result = $method->invoke($this->redirectCallback, $route, $redirect); + + $this->assertSame($expectedResult, $result); + } + + private function setUpApplication() + { + $this->request = $this->getMockBuilder('Zend\Http\PhpEnvironment\Request') + ->disableOriginalConstructor() + ->getMock(); + + $this->response = $this->getMockBuilder('Zend\Http\PhpEnvironment\Response') + ->disableOriginalConstructor() + ->getMock(); + + $this->routeMatch = $this->getMockBuilder('Zend\Mvc\Router\RouteMatch') + ->disableOriginalConstructor() + ->getMock(); + + $this->mvcEvent = $this->getMockBuilder('Zend\Mvc\MvcEvent') + ->disableOriginalConstructor() + ->getMock(); + $this->mvcEvent->expects($this->any()) + ->method('getRouteMatch') + ->will($this->returnValue($this->routeMatch)); + + + $this->application->expects($this->any()) + ->method('getMvcEvent') + ->will($this->returnValue($this->mvcEvent)); + $this->application->expects($this->any()) + ->method('getRequest') + ->will($this->returnValue($this->request)); + $this->application->expects($this->any()) + ->method('getResponse') + ->will($this->returnValue($this->response)); + } +} diff --git a/tests/ZfcUserTest/Controller/UserControllerTest.php b/tests/ZfcUserTest/Controller/UserControllerTest.php index 15b575f6..f4072312 100644 --- a/tests/ZfcUserTest/Controller/UserControllerTest.php +++ b/tests/ZfcUserTest/Controller/UserControllerTest.php @@ -2,6 +2,8 @@ namespace ZfcUserTest\Controller; +use Zend\Form\FormElementManager; +use ZfcUser\Controller\RedirectCallback; use ZfcUser\Controller\UserController as Controller; use Zend\Http\Response; use Zend\Stdlib\Parameters; @@ -14,7 +16,7 @@ class UserControllerTest extends \PHPUnit_Framework_TestCase { /** - * @var \ZfcUser\Controller\UserController $controller + * @var Controller $controller */ protected $controller; @@ -26,9 +28,18 @@ class UserControllerTest extends \PHPUnit_Framework_TestCase protected $options; + /** + * @var \PHPUnit_Framework_MockObject_MockObject|RedirectCallback + */ + protected $redirectCallback; + public function setUp() { - $controller = new Controller; + $this->redirectCallback = $this->getMockBuilder('ZfcUser\Controller\RedirectCallback') + ->disableOriginalConstructor() + ->getMock(); + + $controller = new Controller($this->redirectCallback); $this->controller = $controller; $this->zfcUserAuthenticationPlugin = $this->getMock('ZfcUser\Controller\Plugin\ZfcUserAuthentication'); @@ -36,8 +47,8 @@ public function setUp() $pluginManager = $this->getMock('Zend\Mvc\Controller\PluginManager', array('get')); $pluginManager->expects($this->any()) - ->method('get') - ->will($this->returnCallback(array($this, 'helperMockCallbackPluginManagerGet'))); + ->method('get') + ->will($this->returnCallback(array($this, 'helperMockCallbackPluginManagerGet'))); $this->pluginManager = $pluginManager; @@ -55,8 +66,8 @@ public function setUpZfcUserAuthenticationPlugin($option) ? $this->returnCallback($option['hasIdentity']) : $this->returnValue($option['hasIdentity']); $this->zfcUserAuthenticationPlugin->expects($this->any()) - ->method('hasIdentity') - ->will($return); + ->method('hasIdentity') + ->will($return); } if (array_key_exists('getAuthAdapter', $option)) { @@ -65,8 +76,8 @@ public function setUpZfcUserAuthenticationPlugin($option) : $this->returnValue($option['getAuthAdapter']); $this->zfcUserAuthenticationPlugin->expects($this->any()) - ->method('getAuthAdapter') - ->will($return); + ->method('getAuthAdapter') + ->will($return); } if (array_key_exists('getAuthService', $option)) { @@ -75,8 +86,8 @@ public function setUpZfcUserAuthenticationPlugin($option) : $this->returnValue($option['getAuthService']); $this->zfcUserAuthenticationPlugin->expects($this->any()) - ->method('getAuthService') - ->will($return); + ->method('getAuthService') + ->will($return); } $this->pluginManagerPlugins['zfcUserAuthentication'] = $this->zfcUserAuthenticationPlugin; @@ -100,21 +111,21 @@ public function testActionControllHasIdentity($methodeName, $hasIdentity, $redir if ($optionGetter) { $this->options->expects($this->once()) - ->method($optionGetter) - ->will($this->returnValue($redirectRoute)); + ->method($optionGetter) + ->will($this->returnValue($redirectRoute)); } $redirect = $this->getMock('Zend\Mvc\Controller\Plugin\Redirect'); $redirect->expects($this->once()) - ->method('toRoute') - ->with($redirectRoute) - ->will($this->returnValue($response)); + ->method('toRoute') + ->with($redirectRoute) + ->will($this->returnValue($response)); $this->pluginManagerPlugins['redirect']= $redirect; $result = call_user_func(array($controller, $methodeName)); - $this->assertInstanceOf('\Zend\Http\Response', $result); + $this->assertInstanceOf('Zend\Http\Response', $result); $this->assertSame($response, $result); } @@ -141,7 +152,7 @@ public function testIndexActionLoggedIn() public function testLoginActionValidFormRedirectFalse($isValid, $wantRedirect) { $controller = $this->controller; - $redirectUrl = 'http://localhost/redirect1'; + $redirectUrl = 'localhost/redirect1'; $plugin = $this->setUpZfcUserAuthenticationPlugin(array( 'hasIdentity'=>false @@ -153,58 +164,58 @@ public function testLoginActionValidFormRedirectFalse($isValid, $wantRedirect) $this->pluginManagerPlugins['flashMessenger']= $flashMessenger; $flashMessenger->expects($this->any()) - ->method('setNamespace') - ->with('zfcuser-login-form') - ->will($this->returnSelf()); + ->method('setNamespace') + ->with('zfcuser-login-form') + ->will($this->returnSelf()); $flashMessenger->expects($this->once()) - ->method('getMessages') - ->will($this->returnValue(array())); + ->method('getMessages') + ->will($this->returnValue(array())); $flashMessenger->expects($this->any()) - ->method('addMessage') - ->will($this->returnSelf()); + ->method('addMessage') + ->will($this->returnSelf()); $postArray = array('some', 'data'); $request = $this->getMock('Zend\Http\Request'); $request->expects($this->any()) - ->method('isPost') - ->will($this->returnValue(true)); + ->method('isPost') + ->will($this->returnValue(true)); $request->expects($this->any()) - ->method('getPost') - ->will($this->returnValue($postArray)); + ->method('getPost') + ->will($this->returnValue($postArray)); $this->helperMakePropertyAccessable($controller, 'request', $request); $form = $this->getMockBuilder('ZfcUser\Form\Login') - ->disableOriginalConstructor() - ->getMock(); + ->disableOriginalConstructor() + ->getMock(); $form->expects($this->any()) - ->method('isValid') - ->will($this->returnValue((bool) $isValid)); + ->method('isValid') + ->will($this->returnValue((bool) $isValid)); $this->options->expects($this->any()) - ->method('getUseRedirectParameterIfPresent') - ->will($this->returnValue((bool) $wantRedirect)); + ->method('getUseRedirectParameterIfPresent') + ->will($this->returnValue((bool) $wantRedirect)); if ($wantRedirect) { $params = new Parameters(); $params->set('redirect', $redirectUrl); $request->expects($this->any()) - ->method('getQuery') - ->will($this->returnValue($params)); + ->method('getQuery') + ->will($this->returnValue($params)); } if ($isValid) { $adapter = $this->getMock('ZfcUser\Authentication\Adapter\AdapterChain'); $adapter->expects($this->once()) - ->method('resetAdapters'); + ->method('resetAdapters'); $service = $this->getMock('Zend\Authentication\AuthenticationService'); $service->expects($this->once()) - ->method('clearIdentity'); + ->method('clearIdentity'); $plugin = $this->setUpZfcUserAuthenticationPlugin(array( 'getAuthAdapter'=>$adapter, @@ -212,18 +223,18 @@ public function testLoginActionValidFormRedirectFalse($isValid, $wantRedirect) )); $form->expects($this->once()) - ->method('setData') - ->with($postArray); + ->method('setData') + ->with($postArray); $expectedResult = new \stdClass(); $forwardPlugin = $this->getMockBuilder('Zend\Mvc\Controller\Plugin\Forward') - ->disableOriginalConstructor() - ->getMock(); + ->disableOriginalConstructor() + ->getMock(); $forwardPlugin->expects($this->once()) - ->method('dispatch') - ->with($controller::CONTROLLER_NAME, array('action' => 'authenticate')) - ->will($this->returnValue($expectedResult)); + ->method('dispatch') + ->with($controller::CONTROLLER_NAME, array('action' => 'authenticate')) + ->will($this->returnValue($expectedResult)); $this->pluginManagerPlugins['forward']= $forwardPlugin; @@ -236,14 +247,14 @@ public function testLoginActionValidFormRedirectFalse($isValid, $wantRedirect) $redirect = $this->getMock('Zend\Mvc\Controller\Plugin\Redirect', array('toUrl')); $redirect->expects($this->any()) - ->method('toUrl') - ->with($route_url . $redirectQuery) - ->will($this->returnCallback(function ($url) use (&$response) { - $response->getHeaders()->addHeaderLine('Location', $url); - $response->setStatusCode(302); + ->method('toUrl') + ->with($route_url . $redirectQuery) + ->will($this->returnCallback(function ($url) use (&$response) { + $response->getHeaders()->addHeaderLine('Location', $url); + $response->setStatusCode(302); - return $response; - })); + return $response; + })); $this->pluginManagerPlugins['redirect']= $redirect; @@ -251,9 +262,9 @@ public function testLoginActionValidFormRedirectFalse($isValid, $wantRedirect) $response = new Response(); $url = $this->getMock('Zend\Mvc\Controller\Plugin\Url', array('fromRoute')); $url->expects($this->once()) - ->method('fromRoute') - ->with($controller::ROUTE_LOGIN) - ->will($this->returnValue($route_url)); + ->method('fromRoute') + ->with($controller::ROUTE_LOGIN) + ->will($this->returnValue($route_url)); $this->pluginManagerPlugins['url']= $url; $TEST = true; @@ -266,7 +277,7 @@ public function testLoginActionValidFormRedirectFalse($isValid, $wantRedirect) if ($isValid) { $this->assertSame($expectedResult, $result); } else { - $this->assertInstanceOf('\Zend\Http\Response', $result); + $this->assertInstanceOf('Zend\Http\Response', $result); $this->assertEquals($response, $result); $this->assertEquals($route_url . $redirectQuery, $result->getHeaders()->get('Location')->getFieldValue()); } @@ -284,35 +295,35 @@ public function testLoginActionIsNotPost($redirect) $flashMessenger = $this->getMock('Zend\Mvc\Controller\Plugin\FlashMessenger'); $flashMessenger->expects($this->once()) - ->method('setNamespace') - ->with('zfcuser-login-form') - ->will($this->returnSelf()); + ->method('setNamespace') + ->with('zfcuser-login-form') + ->will($this->returnSelf()); $this->pluginManagerPlugins['flashMessenger']= $flashMessenger; $request = $this->getMock('Zend\Http\Request'); $request->expects($this->once()) - ->method('isPost') - ->will($this->returnValue(false)); + ->method('isPost') + ->will($this->returnValue(false)); $form = $this->getMockBuilder('ZfcUser\Form\Login') - ->disableOriginalConstructor() - ->getMock(); + ->disableOriginalConstructor() + ->getMock(); $form->expects($this->never()) - ->method('isValid'); + ->method('isValid'); $this->options->expects($this->any()) - ->method('getUseRedirectParameterIfPresent') - ->will($this->returnValue((bool) $redirect)); + ->method('getUseRedirectParameterIfPresent') + ->will($this->returnValue((bool) $redirect)); if ($redirect) { $params = new Parameters(); $params->set('redirect', 'http://localhost/'); $request->expects($this->any()) - ->method('getQuery') - ->will($this->returnValue($params)); + ->method('getQuery') + ->will($this->returnValue($params)); } $this->helperMakePropertyAccessable($this->controller, 'request', $request); @@ -324,7 +335,7 @@ public function testLoginActionIsNotPost($redirect) $this->assertArrayHasKey('redirect', $result); $this->assertArrayHasKey('enableRegistration', $result); - $this->assertInstanceOf('\ZfcUser\Form\Login', $result['loginForm']); + $this->assertInstanceOf('ZfcUser\Form\Login', $result['loginForm']); $this->assertSame($form, $result['loginForm']); if ($redirect) { @@ -347,14 +358,14 @@ public function testLogoutAction($withRedirect, $post, $query) $adapter = $this->getMock('ZfcUser\Authentication\Adapter\AdapterChain'); $adapter->expects($this->once()) - ->method('resetAdapters'); + ->method('resetAdapters'); $adapter->expects($this->once()) - ->method('logoutAdapters'); + ->method('logoutAdapters'); $service = $this->getMock('Zend\Authentication\AuthenticationService'); $service->expects($this->once()) - ->method('clearIdentity'); + ->method('clearIdentity'); $this->setUpZfcUserAuthenticationPlugin(array( 'getAuthAdapter'=>$adapter, @@ -362,57 +373,23 @@ public function testLogoutAction($withRedirect, $post, $query) )); - $params = $this->getMock('\Zend\Mvc\Controller\Plugin\Params'); - $params->expects($this->any()) - ->method('__invoke') - ->will($this->returnSelf()); - $params->expects($this->once()) - ->method('fromPost') - ->will($this->returnCallback(function ($key, $default) use ($post) { - return $post ?: $default; - })); - $params->expects($this->once()) - ->method('fromQuery') - ->will($this->returnCallback(function ($key, $default) use ($query) { - return $query ?: $default; - })); - $this->pluginManagerPlugins['params'] = $params; - $response = new Response(); - $redirect = $this->getMock('Zend\Mvc\Controller\Plugin\Redirect'); - $redirect->expects($this->any()) - ->method('toRoute') - ->will($this->returnValue($response)); - - if ($withRedirect) { - $expectedLocation = $post ?: $query ?: false; - $this->options->expects($this->once()) - ->method('getUseRedirectParameterIfPresent') - ->will($this->returnValue((bool) $withRedirect)); - $redirect->expects($this->any()) - ->method('toUrl') - ->with($expectedLocation) - ->will($this->returnValue($response)); - } else { - $expectedLocation = "/user/logout"; - $this->options->expects($this->once()) - ->method('getLogoutRedirectRoute') - ->will($this->returnValue($expectedLocation)); - $redirect->expects($this->any()) - ->method('toRoute') - ->with($expectedLocation) - ->will($this->returnValue($response)); - } - - $this->pluginManagerPlugins['redirect']= $redirect; + $this->redirectCallback->expects($this->once()) + ->method('__invoke') + ->will($this->returnValue($response)); $result = $controller->logoutAction(); - $this->assertInstanceOf('\Zend\Http\Response', $result); + $this->assertInstanceOf('Zend\Http\Response', $result); $this->assertSame($response, $result); } + public function testLoginRedirectFailsWithUrl() + { + + } + /** * @dataProvider providerTestAuthenticateAction * @depend testActionControllHasIdentity @@ -423,20 +400,20 @@ public function testAuthenticateAction($wantRedirect, $post, $query, $prepareRes $response = new Response(); $hasRedirect = !(is_null($query) && is_null($post)); - $params = $this->getMock('\Zend\Mvc\Controller\Plugin\Params'); + $params = $this->getMock('Zend\Mvc\Controller\Plugin\Params'); $params->expects($this->any()) - ->method('__invoke') - ->will($this->returnSelf()); + ->method('__invoke') + ->will($this->returnSelf()); $params->expects($this->once()) - ->method('fromPost') - ->will($this->returnCallback(function ($key, $default) use ($post) { - return $post ?: $default; - })); + ->method('fromPost') + ->will($this->returnCallback(function ($key, $default) use ($post) { + return $post ?: $default; + })); $params->expects($this->once()) - ->method('fromQuery') - ->will($this->returnCallback(function ($key, $default) use ($query) { - return $query ?: $default; - })); + ->method('fromQuery') + ->will($this->returnCallback(function ($key, $default) use ($query) { + return $query ?: $default; + })); $this->pluginManagerPlugins['params'] = $params; @@ -446,9 +423,9 @@ public function testAuthenticateAction($wantRedirect, $post, $query, $prepareRes $adapter = $this->getMock('ZfcUser\Authentication\Adapter\AdapterChain'); $adapter->expects($this->once()) - ->method('prepareForAuthentication') - ->with($request) - ->will($this->returnValue($prepareResult)); + ->method('prepareForAuthentication') + ->with($request) + ->will($this->returnValue($prepareResult)); $service = $this->getMock('Zend\Authentication\AuthenticationService'); @@ -461,17 +438,17 @@ public function testAuthenticateAction($wantRedirect, $post, $query, $prepareRes if (is_bool($prepareResult)) { - $authResult = $this->getMockBuilder('\Zend\Authentication\Result') - ->disableOriginalConstructor() - ->getMock(); + $authResult = $this->getMockBuilder('Zend\Authentication\Result') + ->disableOriginalConstructor() + ->getMock(); $authResult->expects($this->once()) - ->method('isValid') - ->will($this->returnValue($authValid)); + ->method('isValid') + ->will($this->returnValue($authValid)); $service->expects($this->once()) - ->method('authenticate') - ->with($adapter) - ->will($this->returnValue($authResult)); + ->method('authenticate') + ->with($adapter) + ->will($this->returnValue($authResult)); $redirect = $this->getMock('Zend\Mvc\Controller\Plugin\Redirect'); $this->pluginManagerPlugins['redirect'] = $redirect; @@ -483,23 +460,23 @@ public function testAuthenticateAction($wantRedirect, $post, $query, $prepareRes $this->pluginManagerPlugins['flashMessenger']= $flashMessenger; $flashMessenger->expects($this->once()) - ->method('setNamespace') - ->with('zfcuser-login-form') - ->will($this->returnSelf()); + ->method('setNamespace') + ->with('zfcuser-login-form') + ->will($this->returnSelf()); $flashMessenger->expects($this->once()) - ->method('addMessage'); + ->method('addMessage'); $adapter->expects($this->once()) - ->method('resetAdapters'); + ->method('resetAdapters'); $redirectQuery = ($post ?: $query ?: false); $redirectQuery = $redirectQuery ? '?redirect=' . rawurlencode($redirectQuery) : ''; $redirect->expects($this->once()) - ->method('toUrl') - ->with('user/login' . $redirectQuery) - ->will($this->returnValue($response)); + ->method('toUrl') + ->with('user/login' . $redirectQuery) + ->will($this->returnValue($response)); $url = $this->getMock('Zend\Mvc\Controller\Plugin\Url'); $url->expects($this->once()) @@ -508,26 +485,14 @@ public function testAuthenticateAction($wantRedirect, $post, $query, $prepareRes ->will($this->returnValue('user/login')); $this->pluginManagerPlugins['url'] = $url; - } elseif ($wantRedirect && $hasRedirect) { - $redirect->expects($this->once()) - ->method('toUrl') - ->with(($post ?: $query ?: false)) - ->will($this->returnValue($response)); } else { - - $redirect->expects($this->once()) - ->method('toRoute') - ->with('zfcuser') - ->will($this->returnValue($response)); - - $this->options->expects($this->once()) - ->method('getLoginRedirectRoute') - ->will($this->returnValue('zfcuser')); + $this->redirectCallback->expects($this->once()) + ->method('__invoke'); } $this->options->expects($this->any()) - ->method('getUseRedirectParameterIfPresent') - ->will($this->returnValue((bool) $wantRedirect)); + ->method('getUseRedirectParameterIfPresent') + ->will($this->returnValue((bool) $wantRedirect)); } @@ -549,8 +514,8 @@ public function testRegisterActionIsNotAllowed() )); $this->options->expects($this->once()) - ->method('getEnableRegistration') - ->will($this->returnValue(false)); + ->method('getEnableRegistration') + ->will($this->returnValue(false)); $result = $controller->registerAction(); @@ -568,7 +533,7 @@ public function testRegisterActionIsNotAllowed() public function testRegisterAction($wantRedirect, $postRedirectGetReturn, $registerSuccess, $loginAfterSuccessWith) { $controller = $this->controller; - $redirectUrl = 'http://localhost/redirect1'; + $redirectUrl = 'localhost/redirect1'; $route_url = '/user/register'; $expectedResult = null; @@ -577,32 +542,32 @@ public function testRegisterAction($wantRedirect, $postRedirectGetReturn, $regis )); $this->options->expects($this->any()) - ->method('getEnableRegistration') - ->will($this->returnValue(true)); + ->method('getEnableRegistration') + ->will($this->returnValue(true)); $request = $this->getMock('Zend\Http\Request'); $this->helperMakePropertyAccessable($controller, 'request', $request); - $userService = $this->getMock('\ZfcUser\Service\User'); + $userService = $this->getMock('ZfcUser\Service\User'); $controller->setUserService($userService); - $form = $this->getMockBuilder('\Zend\Form\Form') - ->disableOriginalConstructor() - ->getMock(); + $form = $this->getMockBuilder('Zend\Form\Form') + ->disableOriginalConstructor() + ->getMock(); $controller->setRegisterForm($form); $this->options->expects($this->any()) - ->method('getUseRedirectParameterIfPresent') - ->will($this->returnValue((bool) $wantRedirect)); + ->method('getUseRedirectParameterIfPresent') + ->will($this->returnValue((bool) $wantRedirect)); if ($wantRedirect) { $params = new Parameters(); $params->set('redirect', $redirectUrl); $request->expects($this->any()) - ->method('getQuery') - ->will($this->returnValue($params)); + ->method('getQuery') + ->will($this->returnValue($params)); } @@ -614,7 +579,7 @@ public function testRegisterAction($wantRedirect, $postRedirectGetReturn, $regis $this->pluginManagerPlugins['url']= $url; - $prg = $this->getMock('\Zend\Mvc\Controller\Plugin\PostRedirectGet'); + $prg = $this->getMock('Zend\Mvc\Controller\Plugin\PostRedirectGet'); $this->pluginManagerPlugins['prg'] = $prg; $redirectQuery = $wantRedirect ? '?redirect=' . rawurlencode($redirectUrl) : ''; @@ -629,32 +594,32 @@ public function testRegisterAction($wantRedirect, $postRedirectGetReturn, $regis $user->setUsername('zfc-user'); $userService->expects($this->once()) - ->method('register') - ->with($postRedirectGetReturn) - ->will($this->returnValue($user)); + ->method('register') + ->with($postRedirectGetReturn) + ->will($this->returnValue($user)); $userService->expects($this->any()) - ->method('getOptions') - ->will($this->returnValue($this->options)); + ->method('getOptions') + ->will($this->returnValue($this->options)); $this->options->expects($this->once()) - ->method('getLoginAfterRegistration') - ->will($this->returnValue(!empty($loginAfterSuccessWith))); + ->method('getLoginAfterRegistration') + ->will($this->returnValue(!empty($loginAfterSuccessWith))); if ($loginAfterSuccessWith) { $this->options->expects($this->once()) - ->method('getAuthIdentityFields') - ->will($this->returnValue(array($loginAfterSuccessWith))); + ->method('getAuthIdentityFields') + ->will($this->returnValue(array($loginAfterSuccessWith))); $expectedResult = new \stdClass(); $forwardPlugin = $this->getMockBuilder('Zend\Mvc\Controller\Plugin\Forward') - ->disableOriginalConstructor() - ->getMock(); + ->disableOriginalConstructor() + ->getMock(); $forwardPlugin->expects($this->once()) - ->method('dispatch') - ->with($controller::CONTROLLER_NAME, array('action' => 'authenticate')) - ->will($this->returnValue($expectedResult)); + ->method('dispatch') + ->with($controller::CONTROLLER_NAME, array('action' => 'authenticate')) + ->will($this->returnValue($expectedResult)); $this->pluginManagerPlugins['forward']= $forwardPlugin; } else { @@ -669,9 +634,9 @@ public function testRegisterAction($wantRedirect, $postRedirectGetReturn, $regis $redirect = $this->getMock('Zend\Mvc\Controller\Plugin\Redirect'); $redirect->expects($this->once()) - ->method('toUrl') - ->with($route_url . $redirectQuery) - ->will($this->returnValue($response)); + ->method('toUrl') + ->with($route_url . $redirectQuery) + ->will($this->returnValue($response)); $this->pluginManagerPlugins['redirect']= $redirect; @@ -725,7 +690,7 @@ public function testRegisterAction($wantRedirect, $postRedirectGetReturn, $regis $this->assertArrayHasKey('redirect', $result); $this->assertEquals($expectedResult, $result); } else { - $this->assertInstanceOf('\Zend\Http\Response', $result); + $this->assertInstanceOf('Zend\Http\Response', $result); $this->assertSame($response, $result); } } @@ -744,9 +709,9 @@ public function testChangepasswordAction($status, $postRedirectGetReturn, $isVal 'hasIdentity'=>true )); - $form = $this->getMockBuilder('\Zend\Form\Form') - ->disableOriginalConstructor() - ->getMock(); + $form = $this->getMockBuilder('Zend\Form\Form') + ->disableOriginalConstructor() + ->getMock(); $controller->setChangePasswordForm($form); @@ -758,16 +723,16 @@ public function testChangepasswordAction($status, $postRedirectGetReturn, $isVal $this->pluginManagerPlugins['flashMessenger']= $flashMessenger; $flashMessenger->expects($this->any()) - ->method('setNamespace') - ->with('change-password') - ->will($this->returnSelf()); + ->method('setNamespace') + ->with('change-password') + ->will($this->returnSelf()); $flashMessenger->expects($this->once()) - ->method('getMessages') - ->will($this->returnValue($status ? array('test') : array())); + ->method('getMessages') + ->will($this->returnValue($status ? array('test') : array())); - $prg = $this->getMock('\Zend\Mvc\Controller\Plugin\PostRedirectGet'); + $prg = $this->getMock('Zend\Mvc\Controller\Plugin\PostRedirectGet'); $this->pluginManagerPlugins['prg'] = $prg; @@ -779,39 +744,39 @@ public function testChangepasswordAction($status, $postRedirectGetReturn, $isVal if ($postRedirectGetReturn !== false && !($postRedirectGetReturn instanceof Response)) { $form->expects($this->once()) - ->method('setData') - ->with($postRedirectGetReturn); + ->method('setData') + ->with($postRedirectGetReturn); $form->expects($this->once()) - ->method('isValid') - ->will($this->returnValue((bool) $isValid)); + ->method('isValid') + ->will($this->returnValue((bool) $isValid)); if ($isValid) { - $userService = $this->getMock('\ZfcUser\Service\User'); + $userService = $this->getMock('ZfcUser\Service\User'); $controller->setUserService($userService); $form->expects($this->once()) - ->method('getData') - ->will($this->returnValue($postRedirectGetReturn)); + ->method('getData') + ->will($this->returnValue($postRedirectGetReturn)); $userService->expects($this->once()) - ->method('changePassword') - ->with($postRedirectGetReturn) - ->will($this->returnValue((bool) $changeSuccess)); + ->method('changePassword') + ->with($postRedirectGetReturn) + ->will($this->returnValue((bool) $changeSuccess)); if ($changeSuccess) { $flashMessenger->expects($this->once()) - ->method('addMessage') - ->with(true); + ->method('addMessage') + ->with(true); $redirect = $this->getMock('Zend\Mvc\Controller\Plugin\Redirect'); $redirect->expects($this->once()) - ->method('toRoute') - ->with($controller::ROUTE_CHANGEPASSWD) - ->will($this->returnValue($response)); + ->method('toRoute') + ->with($controller::ROUTE_CHANGEPASSWD) + ->will($this->returnValue($response)); $this->pluginManagerPlugins['redirect']= $redirect; } @@ -823,7 +788,7 @@ public function testChangepasswordAction($status, $postRedirectGetReturn, $isVal $exceptedReturn = null; if ($postRedirectGetReturn instanceof Response) { - $this->assertInstanceOf('\Zend\Http\Response', $result); + $this->assertInstanceOf('Zend\Http\Response', $result); $this->assertSame($postRedirectGetReturn, $result); } else { @@ -844,7 +809,7 @@ public function testChangepasswordAction($status, $postRedirectGetReturn, $isVal $this->assertArrayHasKey('changePasswordForm', $result); $this->assertEquals($exceptedReturn, $result); } else { - $this->assertInstanceOf('\Zend\Http\Response', $result); + $this->assertInstanceOf('Zend\Http\Response', $result); $this->assertSame($response, $result); } } @@ -859,8 +824,8 @@ public function testChangeEmailAction($status, $postRedirectGetReturn, $isValid, { $controller = $this->controller; $response = new Response(); - $userService = $this->getMock('\ZfcUser\Service\User'); - $authService = $this->getMock('\Zend\Authentication\AuthenticationService'); + $userService = $this->getMock('ZfcUser\Service\User'); + $authService = $this->getMock('Zend\Authentication\AuthenticationService'); $identity = new UserIdentity(); $controller->setUserService($userService); @@ -869,31 +834,31 @@ public function testChangeEmailAction($status, $postRedirectGetReturn, $isValid, 'hasIdentity'=>true )); - $form = $this->getMockBuilder('\Zend\Form\Form') - ->disableOriginalConstructor() - ->getMock(); + $form = $this->getMockBuilder('Zend\Form\Form') + ->disableOriginalConstructor() + ->getMock(); $controller->setChangeEmailForm($form); $userService->expects($this->once()) - ->method('getAuthService') - ->will($this->returnValue($authService)); + ->method('getAuthService') + ->will($this->returnValue($authService)); $authService->expects($this->once()) - ->method('getIdentity') - ->will($this->returnValue($identity)); + ->method('getIdentity') + ->will($this->returnValue($identity)); $identity->setEmail('user@example.com'); - $requestParams = $this->getMock('\Zend\Stdlib\Parameters'); + $requestParams = $this->getMock('Zend\Stdlib\Parameters'); $requestParams->expects($this->once()) - ->method('set') - ->with('identity', $identity->getEmail()); + ->method('set') + ->with('identity', $identity->getEmail()); - $request = $this->getMock('\Zend\Http\Request'); + $request = $this->getMock('Zend\Http\Request'); $request->expects($this->once()) - ->method('getPost') - ->will($this->returnValue($requestParams)); + ->method('getPost') + ->will($this->returnValue($requestParams)); $this->helperMakePropertyAccessable($controller, 'request', $request); @@ -904,16 +869,16 @@ public function testChangeEmailAction($status, $postRedirectGetReturn, $isValid, $this->pluginManagerPlugins['flashMessenger']= $flashMessenger; $flashMessenger->expects($this->any()) - ->method('setNamespace') - ->with('change-email') - ->will($this->returnSelf()); + ->method('setNamespace') + ->with('change-email') + ->will($this->returnSelf()); $flashMessenger->expects($this->once()) - ->method('getMessages') - ->will($this->returnValue($status ? array('test') : array())); + ->method('getMessages') + ->will($this->returnValue($status ? array('test') : array())); - $prg = $this->getMock('\Zend\Mvc\Controller\Plugin\PostRedirectGet'); + $prg = $this->getMock('Zend\Mvc\Controller\Plugin\PostRedirectGet'); $this->pluginManagerPlugins['prg'] = $prg; @@ -925,38 +890,38 @@ public function testChangeEmailAction($status, $postRedirectGetReturn, $isValid, if ($postRedirectGetReturn !== false && !($postRedirectGetReturn instanceof Response)) { $form->expects($this->once()) - ->method('setData') - ->with($postRedirectGetReturn); + ->method('setData') + ->with($postRedirectGetReturn); $form->expects($this->once()) - ->method('isValid') - ->will($this->returnValue((bool) $isValid)); + ->method('isValid') + ->will($this->returnValue((bool) $isValid)); if ($isValid) { $userService->expects($this->once()) - ->method('changeEmail') - ->with($postRedirectGetReturn) - ->will($this->returnValue((bool) $changeSuccess)); + ->method('changeEmail') + ->with($postRedirectGetReturn) + ->will($this->returnValue((bool) $changeSuccess)); if ($changeSuccess) { $flashMessenger->expects($this->once()) - ->method('addMessage') - ->with(true); + ->method('addMessage') + ->with(true); $redirect = $this->getMock('Zend\Mvc\Controller\Plugin\Redirect'); $redirect->expects($this->once()) - ->method('toRoute') - ->with($controller::ROUTE_CHANGEEMAIL) - ->will($this->returnValue($response)); + ->method('toRoute') + ->with($controller::ROUTE_CHANGEEMAIL) + ->will($this->returnValue($response)); $this->pluginManagerPlugins['redirect']= $redirect; } else { $flashMessenger->expects($this->once()) - ->method('addMessage') - ->with(false); + ->method('addMessage') + ->with(false); } } } @@ -966,7 +931,7 @@ public function testChangeEmailAction($status, $postRedirectGetReturn, $isValid, $exceptedReturn = null; if ($postRedirectGetReturn instanceof Response) { - $this->assertInstanceOf('\Zend\Http\Response', $result); + $this->assertInstanceOf('Zend\Http\Response', $result); $this->assertSame($postRedirectGetReturn, $result); } else { @@ -988,7 +953,7 @@ public function testChangeEmailAction($status, $postRedirectGetReturn, $isValid, $this->assertArrayHasKey('changeEmailForm', $result); $this->assertEquals($exceptedReturn, $result); } else { - $this->assertInstanceOf('\Zend\Http\Response', $result); + $this->assertInstanceOf('Zend\Http\Response', $result); $this->assertSame($response, $result); } } @@ -999,13 +964,13 @@ public function testChangeEmailAction($status, $postRedirectGetReturn, $isValid, * @depend testActionControllHasIdentity */ public function testSetterGetterServices( - $methode, + $method, $useServiceLocator, $servicePrototype, $serviceName, $callback = null ) { - $controller = new Controller; + $controller = new Controller($this->redirectCallback); $controller->setPluginManager($this->pluginManager); @@ -1018,23 +983,22 @@ public function testSetterGetterServices( if ($useServiceLocator) { - $serviceLocator = $this->getMock('\Zend\ServiceManager\ServiceLocatorInterface'); + $serviceLocator = $this->getMock('Zend\ServiceManager\ServiceLocatorInterface'); $serviceLocator->expects($this->once()) - ->method('get') - ->with($serviceName) - ->will($this->returnValue($servicePrototype)); - + ->method('get') + ->with($serviceName) + ->will($this->returnValue($servicePrototype)); $controller->setServiceLocator($serviceLocator); } else { - call_user_func(array($controller, 'set' . $methode), $servicePrototype); + call_user_func(array($controller, 'set' . $method), $servicePrototype); } - $result = call_user_func(array($controller, 'get' . $methode)); + $result = call_user_func(array($controller, 'get' . $method)); $this->assertInstanceOf(get_class($servicePrototype), $result); $this->assertSame($servicePrototype, $result); // we need two check for every case - $result = call_user_func(array($controller, 'get' . $methode)); + $result = call_user_func(array($controller, 'get' . $method)); $this->assertInstanceOf(get_class($servicePrototype), $result); $this->assertSame($servicePrototype, $result); } @@ -1103,13 +1067,13 @@ public function providerTestSetterGetterServices () $that->pluginManagerPlugins['flashMessenger']= $flashMessenger; $flashMessenger->expects($that->any()) - ->method('setNamespace') - ->with('zfcuser-login-form') - ->will($that->returnSelf()); + ->method('setNamespace') + ->with('zfcuser-login-form') + ->will($that->returnSelf()); $flashMessenger->expects($that->once()) - ->method('getMessages') - ->will($that->returnValue(array())); + ->method('getMessages') + ->will($that->returnValue(array())); }; $loginFormCallback[] = function ($that, $controller) { $flashMessenger = $that->getMock( @@ -1118,19 +1082,19 @@ public function providerTestSetterGetterServices () $that->pluginManagerPlugins['flashMessenger']= $flashMessenger; $flashMessenger->expects($that->any()) - ->method('setNamespace') - ->with('zfcuser-login-form') - ->will($that->returnSelf()); + ->method('setNamespace') + ->with('zfcuser-login-form') + ->will($that->returnSelf()); $flashMessenger->expects($that->once()) - ->method('getMessages') - ->will($that->returnValue(array("message1","message2"))); + ->method('getMessages') + ->will($that->returnValue(array("message1","message2"))); }; return array( - // $methode, $useServiceLocator, $servicePrototype, $serviceName, $loginFormCallback + // $method, $useServiceLocator, $servicePrototype, $serviceName, $loginFormCallback array('UserService', true, new UserService(), 'zfcuser_user_service' ), array('UserService', false, new UserService(), null ), array('RegisterForm', true, new Form(), 'zfcuser_register_form' ), diff --git a/tests/ZfcUserTest/Factory/Form/ChangeEmailFormFactoryTest.php b/tests/ZfcUserTest/Factory/Form/ChangeEmailFormFactoryTest.php new file mode 100644 index 00000000..c9bc3d0f --- /dev/null +++ b/tests/ZfcUserTest/Factory/Form/ChangeEmailFormFactoryTest.php @@ -0,0 +1,26 @@ +setService('zfcuser_module_options', new ModuleOptions); + $serviceManager->setService('zfcuser_user_mapper', new UserMapper); + + $formElementManager = new FormElementManager(); + $formElementManager->setServiceLocator($serviceManager); + $serviceManager->setService('FormElementManager', $formElementManager); + + $factory = new ChangeEmailFactory(); + + $this->assertInstanceOf('ZfcUser\Form\ChangeEmail', $factory->createService($formElementManager)); + } +} diff --git a/tests/ZfcUserTest/Factory/Form/ChangePasswordFormFactoryTest.php b/tests/ZfcUserTest/Factory/Form/ChangePasswordFormFactoryTest.php new file mode 100644 index 00000000..17f79fee --- /dev/null +++ b/tests/ZfcUserTest/Factory/Form/ChangePasswordFormFactoryTest.php @@ -0,0 +1,26 @@ +setService('zfcuser_module_options', new ModuleOptions); + $serviceManager->setService('zfcuser_user_mapper', new UserMapper); + + $formElementManager = new FormElementManager(); + $formElementManager->setServiceLocator($serviceManager); + $serviceManager->setService('FormElementManager', $formElementManager); + + $factory = new ChangePasswordFactory(); + + $this->assertInstanceOf('ZfcUser\Form\ChangePassword', $factory->createService($formElementManager)); + } +} diff --git a/tests/ZfcUserTest/Factory/Form/LoginFormFactoryTest.php b/tests/ZfcUserTest/Factory/Form/LoginFormFactoryTest.php new file mode 100644 index 00000000..8f07e0d8 --- /dev/null +++ b/tests/ZfcUserTest/Factory/Form/LoginFormFactoryTest.php @@ -0,0 +1,24 @@ +setService('zfcuser_module_options', new ModuleOptions); + + $formElementManager = new FormElementManager(); + $formElementManager->setServiceLocator($serviceManager); + $serviceManager->setService('FormElementManager', $formElementManager); + + $factory = new LoginFactory(); + + $this->assertInstanceOf('ZfcUser\Form\Login', $factory->createService($formElementManager)); + } +} diff --git a/tests/ZfcUserTest/Factory/Form/RegisterFormFactoryTest.php b/tests/ZfcUserTest/Factory/Form/RegisterFormFactoryTest.php new file mode 100644 index 00000000..1d1a601a --- /dev/null +++ b/tests/ZfcUserTest/Factory/Form/RegisterFormFactoryTest.php @@ -0,0 +1,28 @@ +setService('zfcuser_module_options', new ModuleOptions); + $serviceManager->setService('zfcuser_user_mapper', new UserMapper); + $serviceManager->setService('zfcuser_register_form_hydrator', new ClassMethods()); + + $formElementManager = new FormElementManager(); + $formElementManager->setServiceLocator($serviceManager); + $serviceManager->setService('FormElementManager', $formElementManager); + + $factory = new RegisterFactory(); + + $this->assertInstanceOf('ZfcUser\Form\Register', $factory->createService($formElementManager)); + } +} diff --git a/tests/ZfcUserTest/Form/BaseTest.php b/tests/ZfcUserTest/Form/BaseTest.php index ea6932d3..e333717f 100644 --- a/tests/ZfcUserTest/Form/BaseTest.php +++ b/tests/ZfcUserTest/Form/BaseTest.php @@ -2,28 +2,13 @@ namespace ZfcUserTest\Form; -use ZfcUserTest\Form\TestAsset\BaseExtension as Form; +use ZfcUser\Form\Base as Form; class BaseTest extends \PHPUnit_Framework_TestCase { - /** - * @dataProvider providerTestConstruct - */ - public function testConstruct($useCaptcha = false) + public function testConstruct() { - $options = $this->getMock('ZfcUser\Options\RegistrationOptionsInterface'); - $options->expects($this->once()) - ->method('getUseRegistrationFormCaptcha') - ->will($this->returnValue($useCaptcha)); - if ($useCaptcha && class_exists('\Zend\Captcha\AbstractAdapter')) { - $captcha = $this->getMockForAbstractClass('\Zend\Captcha\AbstractAdapter'); - - $options->expects($this->once()) - ->method('getFormCaptchaOptions') - ->will($this->returnValue($captcha)); - } - - $form = new Form($options); + $form = new Form(); $elements = $form->getElements(); @@ -35,12 +20,4 @@ public function testConstruct($useCaptcha = false) $this->assertArrayHasKey('submit', $elements); $this->assertArrayHasKey('userId', $elements); } - - public function providerTestConstruct() - { - return array( - array(true), - array(false) - ); - } } diff --git a/tests/ZfcUserTest/Form/RegisterTest.php b/tests/ZfcUserTest/Form/RegisterTest.php index 8bb8c679..f6dab831 100644 --- a/tests/ZfcUserTest/Form/RegisterTest.php +++ b/tests/ZfcUserTest/Form/RegisterTest.php @@ -6,7 +6,10 @@ class RegisterTest extends \PHPUnit_Framework_TestCase { - public function testConstruct() + /** + * @dataProvider providerTestConstruct + */ + public function testConstruct($useCaptcha = false) { $options = $this->getMock('ZfcUser\Options\RegistrationOptionsInterface'); $options->expects($this->once()) @@ -17,7 +20,15 @@ public function testConstruct() ->will($this->returnValue(false)); $options->expects($this->any()) ->method('getUseRegistrationFormCaptcha') - ->will($this->returnValue(false)); + ->will($this->returnValue($useCaptcha)); + if ($useCaptcha && class_exists('\Zend\Captcha\AbstractAdapter')) { + $captcha = $this->getMockForAbstractClass('\Zend\Captcha\AbstractAdapter'); + + $options->expects($this->once()) + ->method('getFormCaptchaOptions') + ->will($this->returnValue($captcha)); + } + $form = new Form(null, $options); $elements = $form->getElements(); @@ -30,6 +41,14 @@ public function testConstruct() $this->assertArrayHasKey('passwordVerify', $elements); } + public function providerTestConstruct() + { + return array( + array(true), + array(false) + ); + } + public function testSetGetRegistrationOptions() { $options = $this->getMock('ZfcUser\Options\RegistrationOptionsInterface'); diff --git a/tests/ZfcUserTest/Form/TestAsset/BaseExtension.php b/tests/ZfcUserTest/Form/TestAsset/BaseExtension.php deleted file mode 100644 index ff8753ed..00000000 --- a/tests/ZfcUserTest/Form/TestAsset/BaseExtension.php +++ /dev/null @@ -1,42 +0,0 @@ -setRegistrationOptions($options); - parent::__construct(null); - } - - /** - * Set Regsitration Options - * - * @param RegistrationOptionsInterface $registrationOptions - * @return Register - */ - public function setRegistrationOptions(RegistrationOptionsInterface $registrationOptions) - { - $this->registrationOptions = $registrationOptions; - return $this; - } - - /** - * Get Regsitration Options - * - * @return RegistrationOptionsInterface - */ - public function getRegistrationOptions() - { - return $this->registrationOptions; - } -} diff --git a/tests/ZfcUserTest/Service/UserTest.php b/tests/ZfcUserTest/Service/UserTest.php index db92f3ca..23c25d7f 100644 --- a/tests/ZfcUserTest/Service/UserTest.php +++ b/tests/ZfcUserTest/Service/UserTest.php @@ -119,7 +119,7 @@ public function testRegisterWithUsernameAndDisplayNameUserStateDisabled() $this->options->expects($this->once()) ->method('getEnableUserState') ->will($this->returnValue(true)); - $this->options->expects($this->exactly(2)) + $this->options->expects($this->once()) ->method('getDefaultUserState') ->will($this->returnValue(1)); @@ -153,6 +153,148 @@ public function testRegisterWithUsernameAndDisplayNameUserStateDisabled() $this->assertSame($user, $result); } + /** + * @covers ZfcUser\Service\User::register + */ + public function testRegisterWithDefaultUserStateOfZero() + { + $expectArray = array('username' => 'ZfcUser', 'display_name' => 'Zfc User'); + + $user = $this->getMock('ZfcUser\Entity\User'); + $user->expects($this->once()) + ->method('setPassword'); + $user->expects($this->once()) + ->method('getPassword'); + $user->expects($this->once()) + ->method('setUsername') + ->with('ZfcUser'); + $user->expects($this->once()) + ->method('setDisplayName') + ->with('Zfc User'); + $user->expects($this->once()) + ->method('setState') + ->with(0); + + $this->options->expects($this->once()) + ->method('getUserEntityClass') + ->will($this->returnValue('ZfcUser\Entity\User')); + $this->options->expects($this->once()) + ->method('getPasswordCost') + ->will($this->returnValue(4)); + $this->options->expects($this->once()) + ->method('getEnableUsername') + ->will($this->returnValue(true)); + $this->options->expects($this->once()) + ->method('getEnableDisplayName') + ->will($this->returnValue(true)); + $this->options->expects($this->once()) + ->method('getEnableUserState') + ->will($this->returnValue(true)); + $this->options->expects($this->once()) + ->method('getDefaultUserState') + ->will($this->returnValue(0)); + + $registerForm = $this->getMockBuilder('ZfcUser\Form\Register')->disableOriginalConstructor()->getMock(); + $registerForm->expects($this->once()) + ->method('setHydrator'); + $registerForm->expects($this->once()) + ->method('bind'); + $registerForm->expects($this->once()) + ->method('setData') + ->with($expectArray); + $registerForm->expects($this->once()) + ->method('getData') + ->will($this->returnValue($user)); + $registerForm->expects($this->once()) + ->method('isValid') + ->will($this->returnValue(true)); + + $this->eventManager->expects($this->exactly(2)) + ->method('trigger'); + + $this->mapper->expects($this->once()) + ->method('insert') + ->with($user) + ->will($this->returnValue($user)); + + $this->service->setRegisterForm($registerForm); + + $result = $this->service->register($expectArray); + + $this->assertSame($user, $result); + $this->assertEquals(0, $user->getState()); + } + + /** + * @covers ZfcUser\Service\User::register + */ + public function testRegisterWithUserStateDisabled() + { + $expectArray = array('username' => 'ZfcUser', 'display_name' => 'Zfc User'); + + $user = $this->getMock('ZfcUser\Entity\User'); + $user->expects($this->once()) + ->method('setPassword'); + $user->expects($this->once()) + ->method('getPassword'); + $user->expects($this->once()) + ->method('setUsername') + ->with('ZfcUser'); + $user->expects($this->once()) + ->method('setDisplayName') + ->with('Zfc User'); + $user->expects($this->never()) + ->method('setState'); + + $this->options->expects($this->once()) + ->method('getUserEntityClass') + ->will($this->returnValue('ZfcUser\Entity\User')); + $this->options->expects($this->once()) + ->method('getPasswordCost') + ->will($this->returnValue(4)); + $this->options->expects($this->once()) + ->method('getEnableUsername') + ->will($this->returnValue(true)); + $this->options->expects($this->once()) + ->method('getEnableDisplayName') + ->will($this->returnValue(true)); + $this->options->expects($this->once()) + ->method('getEnableUserState') + ->will($this->returnValue(false)); + $this->options->expects($this->never()) + ->method('getDefaultUserState'); + + $registerForm = $this->getMockBuilder('ZfcUser\Form\Register')->disableOriginalConstructor()->getMock(); + $registerForm->expects($this->once()) + ->method('setHydrator'); + $registerForm->expects($this->once()) + ->method('bind'); + $registerForm->expects($this->once()) + ->method('setData') + ->with($expectArray); + $registerForm->expects($this->once()) + ->method('getData') + ->will($this->returnValue($user)); + $registerForm->expects($this->once()) + ->method('isValid') + ->will($this->returnValue(true)); + + $this->eventManager->expects($this->exactly(2)) + ->method('trigger'); + + $this->mapper->expects($this->once()) + ->method('insert') + ->with($user) + ->will($this->returnValue($user)); + + $this->service->setRegisterForm($registerForm); + + $result = $this->service->register($expectArray); + + $this->assertSame($user, $result); + $this->assertEquals(0, $user->getState()); + } + /** * @covers ZfcUser\Service\User::changePassword */ diff --git a/view/zfc-user/user/_form.phtml b/view/zfc-user/user/_form.phtml new file mode 100644 index 00000000..0f64c709 --- /dev/null +++ b/view/zfc-user/user/_form.phtml @@ -0,0 +1,13 @@ +form()->openTag($form) ?> +
+ + getLabel() != null && !$element instanceof Zend\Form\Element\Button): ?> +
formLabel($element) ?>
+ +
formElement($element) . $this->formElementErrors($element) ?>
+ +
+redirect): ?> + + +form()->closeTag() ?> \ No newline at end of file diff --git a/view/zfc-user/user/changeemail.phtml b/view/zfc-user/user/changeemail.phtml index cddec3c0..77a093ba 100644 --- a/view/zfc-user/user/changeemail.phtml +++ b/view/zfc-user/user/changeemail.phtml @@ -11,25 +11,6 @@ $form = $this->changeEmailForm; $form->prepare(); $form->setAttribute('action', $this->url('zfcuser/changeemail')); $form->setAttribute('method', 'post'); - ?> -form()->openTag($form) ?> -
- - getLabel() != null): ?> -
formLabel($element) ?>
- - -
formButton($element) ?>
- -
formCaptcha($element) . $this->formElementErrors($element) ?>
- -
formInput($element) . $this->formElementErrors($element) ?>
- - -
- redirect): ?> - - - -form()->closeTag() ?> + +partial('_form.phtml', ['form' => $form]); ?> diff --git a/view/zfc-user/user/changepassword.phtml b/view/zfc-user/user/changepassword.phtml index 7512dd09..84036501 100644 --- a/view/zfc-user/user/changepassword.phtml +++ b/view/zfc-user/user/changepassword.phtml @@ -11,37 +11,10 @@ $form = $this->changePasswordForm; $form->prepare(); $form->setAttribute('action', $this->url('zfcuser/changepassword')); $form->setAttribute('method', 'post'); +$form->setAttribute('autocomplete', 'off'); $emailElement = $form->get('identity'); $emailElement->setValue($this->zfcUserIdentity()->getEmail()); - -echo $this->form()->openTag($form); - ?> -
-formElementErrors($form->get('identity')); ?> -
formInput($form->get('identity')); ?>
- -
formLabel($form->get('credential')); ?>
-
formInput($form->get('credential')) . $this->formElementErrors($form->get('credential')); -?>
- -
formLabel($form->get('newCredential')); ?>
-
formInput($form->get('newCredential')) . $this->formElementErrors($form->get('newCredential')); -?>
- -
formLabel($form->get('newCredentialVerify')); ?>
-
formInput($form->get('newCredentialVerify')) . $this->formElementErrors($form->get('newCredentialVerify')); -?>
- -
formInput($form->get('csrf')); -echo $this->formInput($form->get('submit')); -?>
- -
-form()->closeTag(); ?> +partial('_form.phtml', ['form' => $form]); ?> diff --git a/view/zfc-user/user/login.phtml b/view/zfc-user/user/login.phtml index 3d1df3bd..3acee7aa 100644 --- a/view/zfc-user/user/login.phtml +++ b/view/zfc-user/user/login.phtml @@ -5,28 +5,11 @@ $form = $this->loginForm; $form->prepare(); $form->setAttribute('action', $this->url('zfcuser/login')); $form->setAttribute('method', 'post'); +$form->setAttribute('autocomplete', 'off'); ?> -form()->openTag($form) ?> - -
- formElementErrors($form->get('identity')) ?> - -
formLabel($form->get('identity')) ?>
-
formInput($form->get('identity')) ?>
- -
formLabel($form->get('credential')) ?>
-
formInput($form->get('credential')) ?>
- - redirect): ?> - - - -
formButton($form->get('submit')) ?>
-
- -form()->closeTag() ?> +partial('_form.phtml', ['form' => $form]); ?> enableRegistration) : ?> -translate('Not registered?'); ?> translate('Sign up!'); ?> +translate('Not registered?'); ?> translate('Sign up!'); ?> diff --git a/view/zfc-user/user/register.phtml b/view/zfc-user/user/register.phtml index 102b7ef0..1bdafa27 100644 --- a/view/zfc-user/user/register.phtml +++ b/view/zfc-user/user/register.phtml @@ -9,24 +9,7 @@ $form = $this->registerForm; $form->prepare(); $form->setAttribute('action', $this->url('zfcuser/register')); $form->setAttribute('method', 'post'); +$form->setAttribute('autocomplete', 'off'); ?> -form()->openTag($form) ?> -
- - -
formLabel($element) ?>
- - -
formButton($element) ?>
- -
formCaptcha($element) . $this->formElementErrors($element) ?>
- -
formInput($element) . $this->formElementErrors($element) ?>
- - -
- redirect): ?> - - -form()->closeTag() ?> +partial('_form.phtml', ['form' => $form]); ?>