public function testFilterRoutesNeedRole() { $router = m::mock('Router'); $router->shouldReceive('filter')->once(); $router->shouldReceive('when')->once(); $app = array('router' => $router); $entrust = new Entrust($app); $entrust->routeNeedsRole('admin', 'Admin'); }
/** * Filters a route for the name Role. * * If the third parameter is null then return 403. * Overwise the $result is returned. * * @param string $route Route pattern. i.e: "admin/*" * @param array|string $roles The role(s) needed. * @param mixed $result i.e: Redirect::to('/') * @param bool $cumulative Must have all roles. * @return mixed * @static */ public static function routeNeedsRole($route, $roles, $result = null, $cumulative = true) { return \Zizaco\Entrust\Entrust::routeNeedsRole($route, $roles, $result, $cumulative); }
/** * Filters a route for a role or set of roles. * * If the third parameter is null then abort with status code 403. * Otherwise the $result is returned. * * @param string $route Route pattern. i.e: "admin/*" * @param array|string $roles The role(s) needed * @param mixed $result i.e: Redirect::to('/') * @param bool $requireAll User must have all roles * @return mixed * @static */ public static function routeNeedsRole($route, $roles, $result = null, $requireAll = true) { return \Zizaco\Entrust\Entrust::routeNeedsRole($route, $roles, $result, $requireAll); }
public function testRouteNeedsRole() { /* |------------------------------------------------------------ | Set |------------------------------------------------------------ */ $app = new stdClass(); $app->router = m::mock('Route'); $entrust = new Entrust($app); $route = 'route'; $oneRole = 'RoleA'; $manyRole = ['RoleA', 'RoleB', 'RoleC']; $oneRoleFilterName = $this->makeFilterName($route, [$oneRole]); $manyRoleFilterName = $this->makeFilterName($route, $manyRole); /* |------------------------------------------------------------ | Expectation |------------------------------------------------------------ */ $app->router->shouldReceive('filter')->with(m::anyOf($oneRoleFilterName, $manyRoleFilterName), m::type('Closure'))->twice()->ordered(); $app->router->shouldReceive('when')->with($route, m::anyOf($oneRoleFilterName, $manyRoleFilterName))->twice(); /* |------------------------------------------------------------ | Assertion |------------------------------------------------------------ */ $entrust->routeNeedsRole($route, $oneRole); $entrust->routeNeedsRole($route, $manyRole); }