Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
lib
unicaen
auth
Commits
af53e02e
Commit
af53e02e
authored
Oct 03, 2013
by
Bertrand Gauthier
Browse files
Ajout de factories manquantes pour les services.
Tests unitaires correspondants.
parent
6e00cde4
Changes
7
Hide whitespace changes
Inline
Side-by-side
Module.php
View file @
af53e02e
...
...
@@ -6,7 +6,6 @@ use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
use
Zend\ModuleManager\Feature\ConfigProviderInterface
;
use
Zend\ModuleManager\Feature\ServiceProviderInterface
;
use
Zend\ModuleManager\Feature\ViewHelperProviderInterface
;
use
Zend\View\HelperPluginManager
;
/**
* Point d'entrée du module d'authentification Unicaen.
...
...
config/module.config.php
View file @
af53e02e
...
...
@@ -159,34 +159,16 @@ return array(
'Zend\Authentication\AuthenticationService'
=>
'zfcuser_auth_service'
,
),
'invokables'
=>
array
(
'unicaen-auth_user_service'
=>
'UnicaenAuth\Service\User'
,
'unicaen-auth_user_service'
=>
'UnicaenAuth\Service\User'
,
'UnicaenAuth\Authentication\Storage\Db'
=>
'UnicaenAuth\Authentication\Storage\Db'
,
'UnicaenAuth\Authentication\Storage\Ldap'
=>
'UnicaenAuth\Authentication\Storage\Ldap'
,
),
'abstract_factories'
=>
array
(
'UnicaenAuth\Authentication\Adapter\AbstractFactory'
,
),
'factories'
=>
array
(
'unicaen-auth_module_options'
=>
function
(
Zend
\
ServiceManager\ServiceLocatorInterface
$serviceLocator
)
{
$config
=
$serviceLocator
->
get
(
'Config'
);
return
new
UnicaenAuth\Options\ModuleOptions
(
array_merge
(
$config
[
'zfcuser'
],
$config
[
'unicaen-auth'
]));
},
'UnicaenAuth\Authentication\Storage\Db'
=>
function
()
{
return
new
UnicaenAuth\Authentication\Storage\Db
();
},
'UnicaenAuth\Authentication\Storage\Ldap'
=>
function
()
{
return
new
UnicaenAuth\Authentication\Storage\Ldap
();
},
'UnicaenAuth\Authentication\Storage\LdapDb'
=>
function
(
Zend
\
ServiceManager\ServiceLocatorInterface
$serviceLocator
)
{
$storage
=
new
UnicaenAuth\Authentication\Storage\LdapDb
();
$storage
->
setLdapStorage
(
$serviceLocator
->
get
(
'UnicaenAuth\Authentication\Storage\Ldap'
))
->
setDbStorage
(
$serviceLocator
->
get
(
'UnicaenAuth\Authentication\Storage\Db'
));
return
$storage
;
},
'zfcuser_auth_service'
=>
function
(
Zend
\
ServiceManager\ServiceLocatorInterface
$serviceLocator
)
{
return
new
\
Zend\Authentication\AuthenticationService
(
$serviceLocator
->
get
(
'UnicaenAuth\Authentication\Storage\Chain'
),
$serviceLocator
->
get
(
'ZfcUser\Authentication\Adapter\AdapterChain'
)
);
},
'unicaen-auth_module_options'
=>
'UnicaenAuth\Options\ModuleOptionsFactory'
,
'zfcuser_auth_service'
=>
'UnicaenAuth\Authentication\AuthenticationServiceFactory'
,
'UnicaenAuth\Authentication\Storage\Chain'
=>
'UnicaenAuth\Authentication\Storage\ChainServiceFactory'
,
'UnicaenAuth\Provider\Identity\Chain'
=>
'UnicaenAuth\Provider\Identity\ChainServiceFactory'
,
'UnicaenAuth\Provider\Identity\Ldap'
=>
'UnicaenAuth\Provider\Identity\LdapServiceFactory'
,
...
...
config/unicaen-auth.global.php.dist
View file @
af53e02e
...
...
@@ -24,6 +24,6 @@ $settings = array(
return
array
(
'unicaen-auth'
=>
$settings
,
'zfcuser'
=>
array
(
$k
=
'enable_registration'
=>
isset
(
$settings
[
$k
])
?
$settings
[
$k
]
:
false
,
'enable_registration'
=>
isset
(
$settings
[
'enable_registration'
])
?
$settings
[
'enable_registration'
]
:
false
,
),
);
\ No newline at end of file
src/UnicaenAuth/Authentication/AuthenticationServiceFactory.php
0 → 100644
View file @
af53e02e
<?php
namespace
UnicaenAuth\Authentication
;
use
Zend\ServiceManager\FactoryInterface
;
use
Zend\ServiceManager\ServiceLocatorInterface
;
use
Zend\Authentication\AuthenticationService
;
/**
* Description of AuthenticationServiceFactory
*
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/
class
AuthenticationServiceFactory
implements
FactoryInterface
{
/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return AuthenticationService
*/
public
function
createService
(
ServiceLocatorInterface
$serviceLocator
)
{
return
new
AuthenticationService
(
$serviceLocator
->
get
(
'UnicaenAuth\Authentication\Storage\Chain'
),
$serviceLocator
->
get
(
'ZfcUser\Authentication\Adapter\AdapterChain'
)
);
}
}
\ No newline at end of file
src/UnicaenAuth/Options/ModuleOptionsFactory.php
0 → 100644
View file @
af53e02e
<?php
namespace
UnicaenAuth\Options
;
use
Zend\ServiceManager\FactoryInterface
;
use
Zend\ServiceManager\ServiceLocatorInterface
;
/**
* Description of ModuleOptionsFactory
*
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/
class
ModuleOptionsFactory
implements
FactoryInterface
{
/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return mixed
*/
public
function
createService
(
ServiceLocatorInterface
$serviceLocator
)
{
$config
=
$serviceLocator
->
get
(
'Configuration'
);
$moduleConfig
=
isset
(
$config
[
'unicaen-auth'
])
?
$config
[
'unicaen-auth'
]
:
array
();
$moduleConfig
=
array_merge
(
$config
[
'zfcuser'
],
$moduleConfig
);
return
new
ModuleOptions
(
$moduleConfig
);
}
}
\ No newline at end of file
tests/UnicaenAuthTest/Authentication/AuthenticationServiceFactoryTest.php
0 → 100644
View file @
af53e02e
<?php
namespace
UnicaenAuthTest\Authentication
;
use
UnicaenAppTest\BaseServiceFactoryTest
;
/**
* Description of ModuleOptionsFactoryTest
*
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/
class
ModuleOptionsFactoryTest
extends
BaseServiceFactoryTest
{
protected
$factoryClass
=
'UnicaenAuth\Authentication\AuthenticationServiceFactory'
;
protected
$serviceClass
=
'Zend\Authentication\AuthenticationService'
;
public
function
testCanCreateService
()
{
$storage
=
$this
->
getMock
(
'UnicaenAuth\Authentication\Storage\Chain'
,
array
());
$adapter
=
$this
->
getMock
(
'ZfcUser\Authentication\Adapter\AdapterChain'
,
array
());
$this
->
serviceManager
->
expects
(
$this
->
exactly
(
2
))
->
method
(
'get'
)
->
will
(
$this
->
returnValueMap
(
array
(
array
(
'UnicaenAuth\Authentication\Storage\Chain'
,
$storage
),
array
(
'ZfcUser\Authentication\Adapter\AdapterChain'
,
$adapter
),
)));
$service
=
$this
->
factory
->
createService
(
$this
->
serviceManager
);
$this
->
assertInstanceOf
(
$this
->
serviceClass
,
$service
);
}
}
\ No newline at end of file
tests/UnicaenAuthTest/Options/ModuleOptionsFactoryTest.php
0 → 100644
View file @
af53e02e
<?php
namespace
UnicaenAuthTest\Options
;
use
UnicaenAppTest\BaseServiceFactoryTest
;
use
Zend\Config\Config
;
/**
* Description of ModuleOptionsFactoryTest
*
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/
class
ModuleOptionsFactoryTest
extends
BaseServiceFactoryTest
{
protected
$factoryClass
=
'UnicaenAuth\Options\ModuleOptionsFactory'
;
protected
$serviceClass
=
'UnicaenAuth\Options\ModuleOptions'
;
public
function
testCanCreateServiceWithoutOptions
()
{
$config
=
array
(
'zfcuser'
=>
array
(),
'unicaen-auth'
=>
array
(),
);
$this
->
serviceManager
->
expects
(
$this
->
once
())
->
method
(
'get'
)
->
with
(
'Configuration'
)
->
will
(
$this
->
returnValue
(
$config
));
$service
=
$this
->
factory
->
createService
(
$this
->
serviceManager
);
$this
->
assertInstanceOf
(
$this
->
serviceClass
,
$service
);
}
public
function
testCanCreateServiceWithOptions
()
{
$config
=
array
(
'zfcuser'
=>
array
(
'login_redirect_route'
=>
'login'
,
'logout_redirect_route'
=>
'home'
,
),
'unicaen-auth'
=>
array
(
'login_redirect_route'
=>
'other'
,
'save_ldap_user_in_database'
=>
true
,
),
);
$this
->
serviceManager
->
expects
(
$this
->
once
())
->
method
(
'get'
)
->
with
(
'Configuration'
)
->
will
(
$this
->
returnValue
(
$config
));
$service
=
$this
->
factory
->
createService
(
$this
->
serviceManager
);
/* @var $service \UnicaenAuth\Options\ModuleOptions */
$this
->
assertInstanceOf
(
$this
->
serviceClass
,
$service
);
$this
->
assertEquals
(
'other'
,
$service
->
getLoginRedirectRoute
());
$this
->
assertEquals
(
'home'
,
$service
->
getLogoutRedirectRoute
());
$this
->
assertEquals
(
true
,
$service
->
getSaveLdapUserInDatabase
());
}
}
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment