Commit ebc17517 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Utilisation de factories pour les aides de vue.

Tests unitaires correspondants.
parent 7bfdc98b
...@@ -128,25 +128,11 @@ class Module implements ConfigProviderInterface, ViewHelperProviderInterface, Se ...@@ -128,25 +128,11 @@ class Module implements ConfigProviderInterface, ViewHelperProviderInterface, Se
{ {
return array( return array(
'factories' => array( 'factories' => array(
'userConnection' => function (HelperPluginManager $sm) { 'userConnection' => 'UnicaenAuth\View\Helper\UserConnectionFactory',
return new View\Helper\UserConnection($sm->getServiceLocator()->get('zfcuser_auth_service')); 'userCurrent' => 'UnicaenAuth\View\Helper\UserCurrentFactory',
}, 'userStatus' => 'UnicaenAuth\View\Helper\UserStatusFactory',
'userCurrent' => function (HelperPluginManager $sm) { 'userProfile' => 'UnicaenAuth\View\Helper\UserProfileFactory',
return new View\Helper\UserCurrent($sm->getServiceLocator()->get('zfcuser_auth_service')); 'userInfo' => 'UnicaenAuth\View\Helper\UserInfoFactory',
},
'userStatus' => function (HelperPluginManager $sm) {
return new View\Helper\UserStatus($sm->getServiceLocator()->get('zfcuser_auth_service'));
},
'userProfile' => function (HelperPluginManager $sm) {
$helper = new View\Helper\UserProfile($sm->getServiceLocator()->get('zfcuser_auth_service'));
$helper->setIdentityProvider($sm->getServiceLocator()->get('BjyAuthorize\Service\Authorize')->getIdentityProvider());
return $helper;
},
'userInfo' => function (HelperPluginManager $sm) {
$helper = new View\Helper\UserInfo($sm->getServiceLocator()->get('zfcuser_auth_service'));
$helper->setMapperStructure($sm->getServiceLocator()->get('ldap_structure_mapper'));
return $helper;
},
), ),
'invokables' => array( 'invokables' => array(
'appConnection' => 'UnicaenAuth\View\Helper\AppConnection', 'appConnection' => 'UnicaenAuth\View\Helper\AppConnection',
......
<?php
namespace UnicaenAuth\View\Helper;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
/**
* Description of UserConnectionFactory
*
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/
class UserConnectionFactory implements FactoryInterface
{
/**
* Create service
*
* @param ServiceLocatorInterface $helperPluginManager
* @return UserConnection
*/
public function createService(ServiceLocatorInterface $helperPluginManager)
{
$authService = $helperPluginManager->getServiceLocator()->get('zfcuser_auth_service');
return new UserConnection($authService);
}
}
\ No newline at end of file
<?php
namespace UnicaenAuth\View\Helper;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
/**
* Description of UserCurrentFactory
*
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/
class UserCurrentFactory implements FactoryInterface
{
/**
* Create service
*
* @param ServiceLocatorInterface $helperPluginManager
* @return UserCurrent
*/
public function createService(ServiceLocatorInterface $helperPluginManager)
{
$authService = $helperPluginManager->getServiceLocator()->get('zfcuser_auth_service');
return new UserCurrent($authService);
}
}
\ No newline at end of file
<?php
namespace UnicaenAuth\View\Helper;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
/**
* Description of UserInfoFactory
*
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/
class UserInfoFactory implements FactoryInterface
{
/**
* Create service
*
* @param ServiceLocatorInterface $helperPluginManager
* @return UserInfo
*/
public function createService(ServiceLocatorInterface $helperPluginManager)
{
$serviceLocator = $helperPluginManager->getServiceLocator();
$authService = $serviceLocator->get('zfcuser_auth_service');
$mapper = $serviceLocator->get('ldap_structure_mapper');
$helper = new UserInfo($authService);
$helper->setMapperStructure($mapper);
return $helper;
}
}
\ No newline at end of file
<?php
namespace UnicaenAuth\View\Helper;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
/**
* Description of UserProfileFactory
*
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/
class UserProfileFactory implements FactoryInterface
{
/**
* Create service
*
* @param ServiceLocatorInterface $helperPluginManager
* @return UserProfile
*/
public function createService(ServiceLocatorInterface $helperPluginManager)
{
$serviceLocator = $helperPluginManager->getServiceLocator();
$authService = $serviceLocator->get('zfcuser_auth_service');
$authorize = $serviceLocator->get('BjyAuthorize\Service\Authorize');
$identityProvider = $authorize->getIdentityProvider();
$helper = new UserProfile($authService);
$helper->setIdentityProvider($identityProvider);
return $helper;
}
}
\ No newline at end of file
<?php
namespace UnicaenAuth\View\Helper;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
/**
* Description of UserStatusFactory
*
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/
class UserStatusFactory implements FactoryInterface
{
/**
* Create service
*
* @param ServiceLocatorInterface $helperPluginManager
* @return UserStatus
*/
public function createService(ServiceLocatorInterface $helperPluginManager)
{
$authService = $helperPluginManager->getServiceLocator()->get('zfcuser_auth_service');
return new UserStatus($authService);
}
}
\ No newline at end of file
<?php
namespace UnicaenAppTest\View\Helper;
use UnicaenAppTest\View\Helper\BaseServiceFactoryTest;
/**
* Description of UserConnectionFactoryTest
*
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/
class UserConnectionFactoryTest extends BaseServiceFactoryTest
{
protected $factoryClass = 'UnicaenAuth\View\Helper\UserConnectionFactory';
protected $serviceClass = 'UnicaenAuth\View\Helper\UserConnection';
public function testCanCreateService()
{
$authService = $this->getMock('Zend\Authentication\AuthenticationService', array());
$this->serviceManager->expects($this->once())
->method('get')
->with('zfcuser_auth_service')
->will($this->returnValue($authService));
$service = $this->factory->createService($this->pluginManager);
$this->assertInstanceOf($this->serviceClass, $service);
}
}
\ No newline at end of file
<?php
namespace UnicaenAppTest\View\Helper;
use UnicaenAppTest\View\Helper\BaseServiceFactoryTest;
/**
* Description of UserCurrentFactoryTest
*
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/
class UserCurrentFactoryTest extends BaseServiceFactoryTest
{
protected $factoryClass = 'UnicaenAuth\View\Helper\UserCurrentFactory';
protected $serviceClass = 'UnicaenAuth\View\Helper\UserCurrent';
public function testCanCreateService()
{
$authService = $this->getMock('Zend\Authentication\AuthenticationService', array());
$this->serviceManager->expects($this->once())
->method('get')
->with('zfcuser_auth_service')
->will($this->returnValue($authService));
$service = $this->factory->createService($this->pluginManager);
$this->assertInstanceOf($this->serviceClass, $service);
}
}
\ No newline at end of file
<?php
namespace UnicaenAppTest\View\Helper;
use UnicaenAppTest\View\Helper\BaseServiceFactoryTest;
/**
* Description of UserInfoFactoryTest
*
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/
class UserInfoFactoryTest extends BaseServiceFactoryTest
{
protected $factoryClass = 'UnicaenAuth\View\Helper\UserInfoFactory';
protected $serviceClass = 'UnicaenAuth\View\Helper\UserInfo';
public function testCanCreateService()
{
$authService = $this->getMock('Zend\Authentication\AuthenticationService', array());
$mapper = $this->getMock('UnicaenApp\Mapper\Ldap\Structure', array());
$this->serviceManager->expects($this->exactly(2))
->method('get')
->will($this->returnValueMap(array(
array('zfcuser_auth_service', $authService),
array('ldap_structure_mapper', $mapper))));
$service = $this->factory->createService($this->pluginManager);
$this->assertInstanceOf($this->serviceClass, $service);
$this->assertSame($mapper, $service->getMapperStructure());
}
}
\ No newline at end of file
<?php
namespace UnicaenAppTest\View\Helper;
use UnicaenAppTest\View\Helper\BaseServiceFactoryTest;
/**
* Description of UserProfileFactoryTest
*
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/
class UserProfileFactoryTest extends BaseServiceFactoryTest
{
protected $factoryClass = 'UnicaenAuth\View\Helper\UserProfileFactory';
protected $serviceClass = 'UnicaenAuth\View\Helper\UserProfile';
public function testCanCreateService()
{
$authService = $this->getMock('Zend\Authentication\AuthenticationService', array());
$authorize = $this->getMock('BjyAuthorize\Service\Authorize', array('getIdentityProvider'), array(), '', false);
$identityProvider = $this->getMockForAbstractClass('BjyAuthorize\Provider\Identity\ProviderInterface', array());
$authorize->expects($this->once())
->method('getIdentityProvider')
->will($this->returnValue($identityProvider));
$this->serviceManager->expects($this->exactly(2))
->method('get')
->will($this->returnValueMap(array(
array('zfcuser_auth_service', $authService),
array('BjyAuthorize\Service\Authorize', $authorize))));
$service = $this->factory->createService($this->pluginManager);
$this->assertInstanceOf($this->serviceClass, $service);
$this->assertSame($identityProvider, $service->getIdentityProvider());
}
}
\ No newline at end of file
<?php
namespace UnicaenAppTest\View\Helper;
use UnicaenAppTest\View\Helper\BaseServiceFactoryTest;
/**
* Description of UserStatusFactoryTest
*
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/
class UserStatusFactoryTest extends BaseServiceFactoryTest
{
protected $factoryClass = 'UnicaenAuth\View\Helper\UserStatusFactory';
protected $serviceClass = 'UnicaenAuth\View\Helper\UserStatus';
public function testCanCreateService()
{
$authService = $this->getMock('Zend\Authentication\AuthenticationService', array());
$this->serviceManager->expects($this->once())
->method('get')
->with('zfcuser_auth_service')
->will($this->returnValue($authService));
$service = $this->factory->createService($this->pluginManager);
$this->assertInstanceOf($this->serviceClass, $service);
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment