/** * @dataProvider controllersRulesProvider * * @covers \BjyAuthorize\Guard\Controller::__construct * @covers \BjyAuthorize\Guard\Controller::getResources * @covers \BjyAuthorize\Guard\Controller::getRules * * @param array $rule * @param int $expectedCount * @param string $resource * @param array $roles */ public function testGetResourcesGetRules($rule, $expectedCount, $resource, $roles) { $controller = new Controller(array($rule), $this->serviceLocator); $resources = $controller->getResources(); $this->assertCount($expectedCount, $resources); $this->assertContains($resource, $resources); $rules = $controller->getRules(); $this->assertCount($expectedCount, $rules['allow']); $this->assertContains(array($roles, $resource), $rules['allow']); }
/** * @covers \BjyAuthorize\Guard\Controller::__construct * @covers \BjyAuthorize\Guard\Controller::getResources * @covers \BjyAuthorize\Guard\Controller::getRules */ public function testGetResourcesGetRules() { $controller = new Controller(array(array('controller' => 'test-controller', 'action' => 'test-action', 'roles' => array('admin', 'user')), array('controller' => 'test2-controller', 'roles' => array('admin2', 'user2')), array('controller' => 'test3-controller', 'action' => 'test3-action', 'roles' => 'admin3')), $this->serviceLocator); $resources = $controller->getResources(); $this->assertCount(3, $resources); $this->assertContains('controller/test-controller:test-action', $resources); $this->assertContains('controller/test2-controller', $resources); $this->assertContains('controller/test3-controller:test3-action', $resources); $rules = $controller->getRules(); $this->assertCount(3, $rules['allow']); $this->assertContains(array(array('admin', 'user'), 'controller/test-controller:test-action'), $rules['allow']); $this->assertContains(array(array('admin2', 'user2'), 'controller/test2-controller'), $rules['allow']); $this->assertContains(array(array('admin3'), 'controller/test3-controller:test3-action'), $rules['allow']); }