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

Corrections tests unitaires pour branche bootstrap3

parent 66c80859
...@@ -119,8 +119,10 @@ class PeopleTest extends \PHPUnit_Framework_TestCase ...@@ -119,8 +119,10 @@ class PeopleTest extends \PHPUnit_Framework_TestCase
$this->entity->setPassword('whatever'); $this->entity->setPassword('whatever');
} }
public function testCanGettingRolesReturnsMembership() public function testGettingRolesContainsMembershipAndSupannRole()
{ {
$this->assertEquals($this->entity->getMemberOf(), $this->entity->getRoles()); $this->assertEquals(
array_merge($this->entity->getMemberOf(), $this->entity->getSupannRolesEntite()),
$this->entity->getRoles());
} }
} }
\ No newline at end of file
...@@ -116,6 +116,6 @@ class ChainTest extends PHPUnit_Framework_TestCase ...@@ -116,6 +116,6 @@ class ChainTest extends PHPUnit_Framework_TestCase
->method('getRole') ->method('getRole')
->will($this->returnValue($role = new NamedRole('role 1'))); ->will($this->returnValue($role = new NamedRole('role 1')));
$this->assertEquals(array($role), $this->provider->getIdentityRoles()); $this->assertEquals(array('role 1' => $role), $this->provider->getIdentityRoles());
} }
} }
\ No newline at end of file
<?php <?php
namespace UnicaenAuthTest\Provider\Identity; namespace UnicaenAuthTest\Provider\Identity;
use UnicaenAuth\Acl\NamedRole;
/** /**
* Description of LdapTest * Description of LdapTest
* *
...@@ -17,24 +15,32 @@ class DbTest extends BaseTest ...@@ -17,24 +15,32 @@ class DbTest extends BaseTest
$role = new \UnicaenAuth\Entity\Db\Role(); $role = new \UnicaenAuth\Entity\Db\Role();
$role->setRoleId('role id'); $role->setRoleId('role id');
$identity1 = $this->getMock('UnicaenAuth\Entity\Db\User'); $identity1 = $this->getMock('UnicaenAuth\Entity\Db\User', array('getRoles', 'getUsername'));
$identity1->expects($this->once()) $identity1->expects($this->once())
->method('getRoles') ->method('getRoles')
->will($this->returnValue(array($role))); ->will($this->returnValue(array($role)));
$identity1->expects($this->once())
->method('getUsername')
->will($this->returnValue($username = 'username1'));
$expectedRoles1 = array($role, $username);
$role2 = new \UnicaenAuth\Entity\Db\Role(); $role2 = new \UnicaenAuth\Entity\Db\Role();
$role2->setRoleId('role id 2'); $role2->setRoleId('role id 2');
$identity2 = $this->getMock('UnicaenAuth\Entity\Db\User'); $identity2 = $this->getMock('UnicaenAuth\Entity\Db\User', array('getRoles', 'getUsername'));
$identity2->expects($this->once()) $identity2->expects($this->once())
->method('getRoles') ->method('getRoles')
->will($this->returnValue(array($role))); ->will($this->returnValue(array($role)));
$identity2->expects($this->once())
->method('getUsername')
->will($this->returnValue($username = 'username2'));
$expectedRoles = array($role); $expectedRoles2 = array($role, $username);
return array( return array(
'object-identity' => array($identity1, $expectedRoles), 'object-identity' => array($identity1, $expectedRoles1),
'array-identity' => array(array('db' => $identity2), $expectedRoles), 'array-identity' => array(array('db' => $identity2), $expectedRoles2),
); );
} }
...@@ -46,7 +52,7 @@ class DbTest extends BaseTest ...@@ -46,7 +52,7 @@ class DbTest extends BaseTest
$this->authService->expects($this->once()) $this->authService->expects($this->once())
->method('getIdentity') ->method('getIdentity')
->will($this->returnValue($identity)); ->will($this->returnValue($identity));
$roles = $this->provider->getIdentityRoles(); $roles = $this->provider->getIdentityRoles();
$this->assertEquals($expectedRoles, $roles); $this->assertEquals($expectedRoles, $roles);
......
<?php <?php
namespace UnicaenAuthTest\Provider\Identity; namespace UnicaenAuthTest\Provider\Identity;
use UnicaenApp\Entity\Ldap\Group;
use UnicaenAuth\Acl\NamedRole;
/** /**
* Description of LdapTest * Description of LdapTest
* *
...@@ -23,55 +20,47 @@ class LdapTest extends BaseTest ...@@ -23,55 +20,47 @@ class LdapTest extends BaseTest
parent::setUp(); parent::setUp();
$this->mapper = $this->getMock('UnicaenApp\Mapper\Ldap\Db', array('findOneByDn')); $this->mapper = $this->getMock('UnicaenApp\Mapper\Ldap\Db', array('findOneByDn'));
$this->provider->setServiceLocator($this->serviceManager);
} }
public function provideAuthServiceIdentity() public function provideAuthServiceIdentity()
{ {
$identity1 = $this->getMock('UnicaenAuth\Entity\Ldap\People'); $identity1 = $this->getMock('UnicaenAuth\Entity\Ldap\People', array('getRoles', 'getUsername'));
$identity1->expects($this->once()) $identity1->expects($this->once())
->method('getRoles') ->method('getRoles')
->will($this->returnValue(array('cn=admin_reseau,ou=groups,dc=unicaen,dc=fr'))); ->will($this->returnValue(array('cn=admin_reseau,ou=groups,dc=unicaen,dc=fr')));
$identity1->expects($this->once())
->method('getUsername')
->will($this->returnValue('username1'));
$identity2 = $this->getMock('UnicaenAuth\Entity\Ldap\People'); $expectedRoles1 = array('cn=admin_reseau,ou=groups,dc=unicaen,dc=fr', 'username1');
$identity2 = $this->getMock('UnicaenAuth\Entity\Ldap\People', array('getRoles', 'getUsername'));
$identity2->expects($this->once()) $identity2->expects($this->once())
->method('getRoles') ->method('getRoles')
->will($this->returnValue(array('cn=admin_reseau,ou=groups,dc=unicaen,dc=fr'))); ->will($this->returnValue(array('cn=admin_reseau,ou=groups,dc=unicaen,dc=fr')));
$identity2->expects($this->once())
->method('getUsername')
->will($this->returnValue('username2'));
$expectedRoles2 = array('cn=admin_reseau,ou=groups,dc=unicaen,dc=fr', 'username2');
return array( return array(
'object-identity' => array($identity1), 'object-identity' => array($identity1, $expectedRoles1),
'array-identity' => array(array('ldap' => $identity2)), 'array-identity' => array(array('ldap' => $identity2), $expectedRoles2),
); );
} }
/** /**
* @dataProvider provideAuthServiceIdentity * @dataProvider provideAuthServiceIdentity
*/ */
public function testGettingIdentityRolesReturnsPeopleRoles($identity) public function testGettingIdentityRolesReturnsPeopleRoles($identity, $expectedRoles)
{ {
$group = new Group(array(
'dn' => 'cn=admin_reseau,ou=groups,dc=unicaen,dc=fr',
'description' => 'ldap group'
));
$this->authService->expects($this->once()) $this->authService->expects($this->once())
->method('getIdentity') ->method('getIdentity')
->will($this->returnValue($identity)); ->will($this->returnValue($identity));
$this->mapper->expects($this->once())
->method('findOneByDn')
->with($group->getDn())
->will($this->returnValue($group));
$this->serviceManager->expects($this->once())
->method('get')
->with('ldap_group_mapper')
->will($this->returnValue($this->mapper));
$roles = $this->provider->getIdentityRoles(); $roles = $this->provider->getIdentityRoles();
$expected = array(new NamedRole($group->getDn(), null, $group->getDescription())); $this->assertEquals($expectedRoles, $roles);
$this->assertEquals($expected, $roles);
} }
} }
\ No newline at end of file
...@@ -9,8 +9,8 @@ namespace UnicaenAuthTest\Provider\Role; ...@@ -9,8 +9,8 @@ namespace UnicaenAuthTest\Provider\Role;
*/ */
class DbServiceFactoryTest extends BaseServiceFactoryTest class DbServiceFactoryTest extends BaseServiceFactoryTest
{ {
protected $factoryClass = 'UnicaenAuth\Provider\Role\DbServiceFactory'; protected $factoryClass = 'UnicaenAuth\Provider\Role\DbRoleServiceFactory';
protected $serviceClass = 'UnicaenAuth\Provider\Role\Db'; protected $serviceClass = 'UnicaenAuth\Provider\Role\DbRole';
public function provideInvalidOptions() public function provideInvalidOptions()
{ {
...@@ -18,9 +18,9 @@ class DbServiceFactoryTest extends BaseServiceFactoryTest ...@@ -18,9 +18,9 @@ class DbServiceFactoryTest extends BaseServiceFactoryTest
'a' => array(array()), 'a' => array(array()),
'b' => array(array('role_providers')), 'b' => array(array('role_providers')),
'c' => array(array('role_providers' => array())), 'c' => array(array('role_providers' => array())),
'd' => array(array('role_providers' => array('UnicaenAuth\Provider\Role\Db' => array()))), 'd' => array(array('role_providers' => array('UnicaenAuth\Provider\Role\DbRole' => array()))),
'e' => array(array('role_providers' => array('UnicaenAuth\Provider\Role\Db' => array('role_entity_class' => null)))), 'e' => array(array('role_providers' => array('UnicaenAuth\Provider\Role\DbRole' => array('role_entity_class' => null)))),
'f' => array(array('role_providers' => array('UnicaenAuth\Provider\Role\Db' => array('role_entity_class' => 'A', 'object_manager' => null)))), 'f' => array(array('role_providers' => array('UnicaenAuth\Provider\Role\DbRole' => array('role_entity_class' => 'A', 'object_manager' => null)))),
); );
} }
...@@ -42,7 +42,7 @@ class DbServiceFactoryTest extends BaseServiceFactoryTest ...@@ -42,7 +42,7 @@ class DbServiceFactoryTest extends BaseServiceFactoryTest
{ {
$options = array( $options = array(
'role_providers' => array( 'role_providers' => array(
'UnicaenAuth\Provider\Role\Db' => array( 'UnicaenAuth\Provider\Role\DbRole' => array(
'role_entity_class' => 'Entity', 'role_entity_class' => 'Entity',
'object_manager' => 'orm_default', 'object_manager' => 'orm_default',
) )
...@@ -64,6 +64,6 @@ class DbServiceFactoryTest extends BaseServiceFactoryTest ...@@ -64,6 +64,6 @@ class DbServiceFactoryTest extends BaseServiceFactoryTest
$service = $this->factory->createService($this->serviceLocator); $service = $this->factory->createService($this->serviceLocator);
$this->assertInstanceOf('UnicaenAuth\Provider\Role\Db', $service); $this->assertInstanceOf('UnicaenAuth\Provider\Role\DbRole', $service);
} }
} }
\ No newline at end of file
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
namespace UnicaenAuthTest\Provider\Role; namespace UnicaenAuthTest\Provider\Role;
use PHPUnit_Framework_TestCase; use PHPUnit_Framework_TestCase;
use UnicaenAuth\Provider\Role\Db; use UnicaenAuth\Provider\Role\DbRole;
use BjyAuthorize\Provider\Role\ObjectRepositoryProvider; use BjyAuthorize\Provider\Role\ObjectRepositoryProvider;
/** /**
...@@ -19,7 +19,7 @@ class DbTest extends PHPUnit_Framework_TestCase ...@@ -19,7 +19,7 @@ class DbTest extends PHPUnit_Framework_TestCase
protected function setUp() protected function setUp()
{ {
$this->objectRepository = $this->getMock('Doctrine\Common\Persistence\ObjectRepository', array()); $this->objectRepository = $this->getMock('Doctrine\Common\Persistence\ObjectRepository', array());
$this->provider = new Db($this->objectRepository); $this->provider = new DbRole($this->objectRepository);
} }
public function testGettingRolesReturnsParentClassRoles() public function testGettingRolesReturnsParentClassRoles()
......
...@@ -6,7 +6,7 @@ use UnicaenAuth\View\Helper\UserCurrent; ...@@ -6,7 +6,7 @@ use UnicaenAuth\View\Helper\UserCurrent;
use Zend\I18n\Translator\Translator; use Zend\I18n\Translator\Translator;
/** /**
* Description of AppConnectionTest * Description of UserCurrentTest
* *
* @property UserCurrent $helper Description * @property UserCurrent $helper Description
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr> * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
...@@ -28,9 +28,10 @@ class UserCurrentTest extends AbstractTest ...@@ -28,9 +28,10 @@ class UserCurrentTest extends AbstractTest
{ {
parent::setUp(); parent::setUp();
$this->userStatusHelper = $userStatusHelper = $this->getMock('UnicaenAuth\View\Helper\UserStatus', array('__invoke')); $this->userStatusHelper = $userStatusHelper = $this->getMock('UnicaenAuth\View\Helper\UserStatus', array('__invoke'));
$this->userProfileHelper = $userProfileHelper = $this->getMock('UnicaenAuth\View\Helper\UserProfile', array('__toString')); $this->userProfileHelper = $userProfileHelper = $this->getMock('UnicaenAuth\View\Helper\UserProfile', array('__toString'));
$this->userInfoHelper = $userInfoHelper = $this->getMock('UnicaenAuth\View\Helper\UserInfo', array('__invoke')); $this->userInfoHelper = $userInfoHelper = $this->getMock('UnicaenAuth\View\Helper\UserInfo', array('__invoke'));
$this->inlineScriptHelper = $inlineScriptHelper = $this->getMock('Zend\View\Helper\InlineScript', array('__invoke'));
$this->userStatusHelper $this->userStatusHelper
->expects($this->any()) ->expects($this->any())
...@@ -44,11 +45,15 @@ class UserCurrentTest extends AbstractTest ...@@ -44,11 +45,15 @@ class UserCurrentTest extends AbstractTest
->expects($this->any()) ->expects($this->any())
->method('__invoke') ->method('__invoke')
->will($this->returnValue('User Info Helper Markup')); ->will($this->returnValue('User Info Helper Markup'));
$this->inlineScriptHelper
->expects($this->any())
->method('__invoke')
->will($this->returnValue('InlineScript Helper Markup'));
$this->renderer = $this->getMock('Zend\View\Renderer\PhpRenderer', array('plugin')); $this->renderer = $this->getMock('Zend\View\Renderer\PhpRenderer', array('plugin'));
$this->renderer->expects($this->any()) $this->renderer->expects($this->any())
->method('plugin') ->method('plugin')
->will($this->returnCallback(function ($helper) use ($userStatusHelper, $userProfileHelper, $userInfoHelper) { ->will($this->returnCallback(function ($helper) use ($userStatusHelper, $userProfileHelper, $userInfoHelper, $inlineScriptHelper) {
if ('userstatus' === strtolower($helper)) { if ('userstatus' === strtolower($helper)) {
return $userStatusHelper; return $userStatusHelper;
} }
...@@ -58,6 +63,9 @@ class UserCurrentTest extends AbstractTest ...@@ -58,6 +63,9 @@ class UserCurrentTest extends AbstractTest
if ('userinfo' === strtolower($helper)) { if ('userinfo' === strtolower($helper)) {
return $userInfoHelper; return $userInfoHelper;
} }
if ('inlinescript' === strtolower($helper)) {
return $inlineScriptHelper;
}
return null; return null;
})); }));
......
<script type="text/javascript">
$(function() {
$("#user-current-info").popover({ html: true, container: '#navbar' });
});
</script>
\ No newline at end of file
...@@ -5,8 +5,3 @@ ...@@ -5,8 +5,3 @@
data-toggle="popover" data-toggle="popover"
data-content="User Profile Helper MarkupUser Info Helper Markup" data-content="User Profile Helper MarkupUser Info Helper Markup"
href="#">User Status Helper Markup</a> href="#">User Status Helper Markup</a>
<script type="text/javascript">
$(function() {
$("#user-current-info").popover({ html: true, container: '#navbar' });
});
</script>
...@@ -5,8 +5,3 @@ ...@@ -5,8 +5,3 @@
data-toggle="popover" data-toggle="popover"
data-content="User Profile Helper MarkupUser Info Helper Markup" data-content="User Profile Helper MarkupUser Info Helper Markup"
href="#">User Status Helper Markup</a> href="#">User Status Helper Markup</a>
<script type="text/javascript">
$(function() {
$("#user-current-info").popover({ html: true, container: '#navbar' });
});
</script>
...@@ -5,8 +5,3 @@ ...@@ -5,8 +5,3 @@
data-toggle="popover" data-toggle="popover"
data-content="None" data-content="None"
href="#">User Status Helper Markup</a> href="#">User Status Helper Markup</a>
<script type="text/javascript">
$(function() {
$("#user-current-info").popover({ html: true, container: '#navbar' });
});
</script>
...@@ -5,8 +5,3 @@ ...@@ -5,8 +5,3 @@
data-toggle="popover" data-toggle="popover"
data-content="Aucun" data-content="Aucun"
href="#">User Status Helper Markup</a> href="#">User Status Helper Markup</a>
<script type="text/javascript">
$(function() {
$("#user-current-info").popover({ html: true, container: '#navbar' });
});
</script>
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