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
d0195c34
Commit
d0195c34
authored
Jul 05, 2013
by
Bertrand Gauthier
Browse files
Storage d'authentification Ldap : tests unitaires ; légères améliorations.
parent
9b715b05
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/UnicaenAuth/Authentication/Storage/Ldap.php
View file @
d0195c34
...
...
@@ -27,6 +27,11 @@ class Ldap implements Storage\StorageInterface, ServiceManagerAwareInterface
* @var LdapPeopleService
*/
protected
$mapper
;
/**
* @var ModuleOptions
*/
protected
$options
;
/**
* @var People
...
...
tests/UnicaenAuthTest/Authentication/Storage/LdapTest.php
0 → 100644
View file @
d0195c34
<?php
namespace
UnicaenAuthTest\Authentication\Storage
;
use
PHPUnit_Framework_TestCase
;
use
UnicaenAppTest\Entity\Ldap\TestAsset\People
;
use
UnicaenAuth\Authentication\Storage\Ldap
;
use
Zend\ServiceManager\ServiceManager
;
/**
* Description of LdapTest
*
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/
class
LdapTest
extends
PHPUnit_Framework_TestCase
{
protected
$storage
;
protected
$mapper
;
protected
$serviceManager
;
protected
$options
;
/**
* Sets up the fixture, for example, open a network connection.
* This method is called before a test is executed.
*/
protected
function
setUp
()
{
$this
->
options
=
$options
=
new
\
UnicaenAuth\Options\ModuleOptions
();
$this
->
mapper
=
$mapper
=
$this
->
getMock
(
'UnicaenApp\Service\Ldap\People'
,
array
(
'findOneByUsername'
));
$this
->
serviceManager
=
new
ServiceManager
();
$this
->
serviceManager
->
setFactory
(
'ldap_people_service'
,
function
()
use
(
$mapper
)
{
$service
=
new
\
UnicaenApp\Service\Ldap\People
();
$service
->
setMapper
(
$mapper
);
return
$service
;
});
$this
->
serviceManager
->
setFactory
(
'unicaen-auth_module_options'
,
function
()
use
(
$options
)
{
return
$options
;
});
$this
->
storage
=
new
Ldap
();
$this
->
storage
->
setMapper
(
$this
->
mapper
)
->
setServiceManager
(
$this
->
serviceManager
);
}
public
function
testCanRetrieveDefaultInnerStorage
()
{
$this
->
assertInstanceOf
(
'Zend\Authentication\Storage\StorageInterface'
,
$this
->
storage
->
getStorage
());
}
public
function
testCanWriteToInnerStorage
()
{
$this
->
storage
->
write
(
$content
=
'content'
);
$this
->
assertFalse
(
$this
->
storage
->
isEmpty
());
$this
->
assertFalse
(
$this
->
storage
->
getStorage
()
->
isEmpty
());
$this
->
assertEquals
(
$content
,
$this
->
storage
->
getStorage
()
->
read
());
$this
->
storage
->
clear
();
$this
->
assertTrue
(
$this
->
storage
->
isEmpty
());
$this
->
assertTrue
(
$this
->
storage
->
getStorage
()
->
isEmpty
());
}
public
function
testCanRetrieveMapperFromLdapService
()
{
$this
->
assertSame
(
$this
->
mapper
,
$this
->
storage
->
getMapper
());
}
public
function
testCanRetrieveOptionsFromServiceManager
()
{
$this
->
assertSame
(
$this
->
options
,
$this
->
storage
->
getOptions
());
}
public
function
testReadingReturnsNullIfInnerStorageIsEmpty
()
{
$this
->
mapper
->
expects
(
$this
->
never
())
->
method
(
'findOneByUsername'
);
$this
->
storage
->
clear
();
$result
=
$this
->
storage
->
read
();
$this
->
assertNull
(
$result
);
}
public
function
testReadingReturnsNullIfNoUserFound
()
{
$this
->
mapper
->
expects
(
$this
->
once
())
->
method
(
'findOneByUsername'
)
->
will
(
$this
->
returnValue
(
null
));
$this
->
storage
->
write
(
'username'
);
$result
=
$this
->
storage
->
read
();
$this
->
assertNull
(
$result
);
}
public
function
testReadingReturnsFoundUser
()
{
$entity
=
new
People
();
$this
->
mapper
->
expects
(
$this
->
once
())
->
method
(
'findOneByUsername'
)
->
will
(
$this
->
returnValue
(
$entity
));
$this
->
storage
->
write
(
$login
=
'username'
);
$result
=
$this
->
storage
->
read
();
$this
->
assertSame
(
$entity
,
$result
);
}
public
function
testReadingDoesNotFetchUserTwice
()
{
$this
->
mapper
->
expects
(
$this
->
once
())
->
method
(
'findOneByUsername'
)
->
will
(
$this
->
returnValue
(
new
People
()));
$this
->
storage
->
write
(
'username'
);
$firestResult
=
$this
->
storage
->
read
();
$this
->
mapper
->
expects
(
$this
->
never
())
->
method
(
'findOneByUsername'
);
$nextResult
=
$this
->
storage
->
read
();
$this
->
assertSame
(
$firestResult
,
$nextResult
);
}
}
\ 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