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