public function testFilterRoutesNeedPermission()
 {
     $router = m::mock('Router');
     $router->shouldReceive('filter')->once();
     $router->shouldReceive('when')->once();
     $app = array('router' => $router);
     $entrust = new Entrust($app);
     $entrust->routeNeedsPermission('admin', 'manage_users');
 }
Example #2
0
 /**
  * Filters a route for the permission.
  * 
  * 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 array|string $permissions The permission needed.
  * @param mixed $result i.e: Redirect::to('/')
  * @param bool $cumulative Must have all permissions
  * @return void 
  * @static 
  */
 public static function routeNeedsRoleOrPermission($route, $roles, $permissions, $result = null, $cumulative = false)
 {
     \Zizaco\Entrust\Entrust::routeNeedsRoleOrPermission($route, $roles, $permissions, $result, $cumulative);
 }
Example #3
0
 public function testRouteNeedsRoleOrPermission()
 {
     /*
     |------------------------------------------------------------
     | Set
     |------------------------------------------------------------
     */
     $app = new stdClass();
     $app->router = m::mock('Route');
     $entrust = new Entrust($app);
     $route = 'route';
     $oneRole = 'RoleA';
     $manyRole = ['RoleA', 'RoleB', 'RoleC'];
     $onePerm = 'can_a';
     $manyPerm = ['can_a', 'can_b', 'can_c'];
     $oneRoleOnePermFilterName = $this->makeFilterName($route, [$oneRole], [$onePerm]);
     $oneRoleManyPermFilterName = $this->makeFilterName($route, [$oneRole], $manyPerm);
     $manyRoleOnePermFilterName = $this->makeFilterName($route, $manyRole, [$onePerm]);
     $manyRoleManyPermFilterName = $this->makeFilterName($route, $manyRole, $manyPerm);
     /*
     |------------------------------------------------------------
     | Expectation
     |------------------------------------------------------------
     */
     $app->router->shouldReceive('filter')->with(m::anyOf($oneRoleOnePermFilterName, $oneRoleManyPermFilterName, $manyRoleOnePermFilterName, $manyRoleManyPermFilterName), m::type('Closure'))->times(4)->ordered();
     $app->router->shouldReceive('when')->with($route, m::anyOf($oneRoleOnePermFilterName, $oneRoleManyPermFilterName, $manyRoleOnePermFilterName, $manyRoleManyPermFilterName))->times(4);
     /*
     |------------------------------------------------------------
     | Assertion
     |------------------------------------------------------------
     */
     $entrust->routeNeedsRoleOrPermission($route, $oneRole, $onePerm);
     $entrust->routeNeedsRoleOrPermission($route, $oneRole, $manyPerm);
     $entrust->routeNeedsRoleOrPermission($route, $manyRole, $onePerm);
     $entrust->routeNeedsRoleOrPermission($route, $manyRole, $manyPerm);
 }