Skip to content
This repository has been archived by the owner on Jul 3, 2020. It is now read-only.

Commit

Permalink
[373] Cannot get a name and parameters for RoleProviderPluginManager …
Browse files Browse the repository at this point in the history
…(Tests)
  • Loading branch information
ashatrov committed May 4, 2017
1 parent cf1c8ec commit 6dea80b
Showing 1 changed file with 78 additions and 12 deletions.
90 changes: 78 additions & 12 deletions tests/ZfcRbacTest/Factory/RoleServiceFactoryTest.php
Expand Up @@ -40,29 +40,95 @@ public function testFactory()
]
]);

$serviceManager = new ServiceManager();
$serviceManager->setService('ZfcRbac\Options\ModuleOptions', $options);
$serviceManager->setService('ZfcRbac\Role\RoleProviderPluginManager', new RoleProviderPluginManager($serviceManager));
$serviceManager->setService(
'ZfcRbac\Identity\AuthenticationProvider',
$this->getMock('ZfcRbac\Identity\IdentityProviderInterface')
);

$traversalStrategy = $this->getMock('Rbac\Traversal\Strategy\TraversalStrategyInterface');
$rbac = $this->getMock('Rbac\Rbac', [], [], '', false);
$roleProvider = $this->getMock('\ZfcRbac\Role\RoleProviderInterface');

$rbac->expects($this->once())->method('getTraversalStrategy')->will($this->returnValue($traversalStrategy));
$rbac = $this
->getMockBuilder('Rbac\Rbac')
->disableOriginalConstructor()
->getMock();
$rbac->expects($this->once())
->method('getTraversalStrategy')
->will($this->returnValue(
$traversalStrategy
));

$pluginManager = $this
->getMockBuilder('\ZfcRbac\Role\RoleProviderPluginManager')
->disableOriginalConstructor()
->getMock();
$pluginManager->expects($this->once())
->method('get')
->with('ZfcRbac\Role\InMemoryRoleProvider', ['foo'])
->will($this->returnValue(
$roleProvider
));

$serviceManager = new ServiceManager();
$serviceManager->setService('ZfcRbac\Options\ModuleOptions', $options);
$serviceManager->setService('Rbac\Rbac', $rbac);
$serviceManager->setService('ZfcRbac\Role\RoleProviderPluginManager', $pluginManager);
$serviceManager->setService('ZfcRbac\Identity\AuthenticationProvider', $this->getMock('ZfcRbac\Identity\IdentityProviderInterface'));

$factory = new RoleServiceFactory();
$factory = new RoleServiceFactory();
$roleService = $factory->createService($serviceManager);

$this->assertInstanceOf('ZfcRbac\Service\RoleService', $roleService);
$this->assertEquals('guest', $roleService->getGuestRole());
$this->assertAttributeSame($traversalStrategy, 'traversalStrategy', $roleService);
}

public function testIfRoleArrayPointerBeyondArrayEnd()
{
$options = new ModuleOptions([
'identity_provider' => 'ZfcRbac\Identity\AuthenticationProvider',
'guest_role' => 'guest',
'role_provider' => [
'ZfcRbac\Role\InMemoryRoleProvider' => [
'foo'
]
]
]);

// Simulate if array pointer beyond end of array. E.g after 'while(next($roleProvider)) { //do }'
$roleProvider = $options->getRoleProvider();
next($roleProvider);
$options->setRoleProvider($roleProvider);

$traversalStrategy = $this->getMock('Rbac\Traversal\Strategy\TraversalStrategyInterface');
$roleProvider = $this->getMock('\ZfcRbac\Role\RoleProviderInterface');

$rbac = $this
->getMockBuilder('Rbac\Rbac')
->disableOriginalConstructor()
->getMock();
$rbac->expects($this->once())
->method('getTraversalStrategy')
->will($this->returnValue(
$traversalStrategy
));

$pluginManager = $this
->getMockBuilder('\ZfcRbac\Role\RoleProviderPluginManager')
->disableOriginalConstructor()
->getMock();
$pluginManager->expects($this->once())
->method('get')
->with('ZfcRbac\Role\InMemoryRoleProvider', ['foo'])
->will($this->returnValue(
$roleProvider
));

$serviceManager = new ServiceManager();
$serviceManager->setService('ZfcRbac\Options\ModuleOptions', $options);
$serviceManager->setService('Rbac\Rbac', $rbac);
$serviceManager->setService('ZfcRbac\Role\RoleProviderPluginManager', $pluginManager);
$serviceManager->setService('ZfcRbac\Identity\AuthenticationProvider', $this->getMock('ZfcRbac\Identity\IdentityProviderInterface'));

$factory = new RoleServiceFactory();
$factory->createService($serviceManager);
}

public function testThrowExceptionIfNoRoleProvider()
{
$this->setExpectedException('ZfcRbac\Exception\RuntimeException');
Expand All @@ -81,6 +147,6 @@ public function testThrowExceptionIfNoRoleProvider()
);

$factory = new RoleServiceFactory();
$roleService = $factory->createService($serviceManager);
$factory->createService($serviceManager);
}
}

0 comments on commit 6dea80b

Please sign in to comment.