Example #1
0
 protected function addContent()
 {
     $faker = Faker\Factory::create();
     $role = \Distilleries\Expendable\Models\Role::create(['libelle' => $faker->text(), 'initials' => $faker->name, 'overide_permission' => false]);
     $service = \Distilleries\Expendable\Models\Service::create(['action' => $faker->name() . '@' . $faker->name()]);
     $permission = \Distilleries\Expendable\Models\Permission::create(['role_id' => $role->id, 'service_id' => $service->id]);
     return [$role, $service, $permission];
 }
Example #2
0
 public function testHasAccess()
 {
     $faker = Faker\Factory::create();
     $role = \Distilleries\Expendable\Models\Role::create(['libelle' => $faker->text(), 'initials' => $faker->name, 'overide_permission' => false]);
     $service = \Distilleries\Expendable\Models\Service::create(['action' => $faker->name() . '@' . $faker->name()]);
     $permission = \Distilleries\Expendable\Models\Permission::create(['role_id' => $role->id, 'service_id' => $service->id]);
     $user = \Distilleries\Expendable\Models\User::create(['email' => $faker->email, 'password' => \Hash::make('test'), 'status' => true, 'role_id' => $role->id]);
     $this->assertFalse($user->hasAccess('test'));
 }
Example #3
0
 protected function addContent()
 {
     $faker = Faker\Factory::create();
     $role = \Distilleries\Expendable\Models\Role::create(['libelle' => $faker->text(), 'initials' => $faker->name, 'overide_permission' => false]);
     $service = \Distilleries\Expendable\Models\Service::create(['action' => $faker->name() . '@' . $faker->name()]);
     $permission = \Distilleries\Expendable\Models\Permission::create(['role_id' => $role->id, 'service_id' => $service->id]);
     $user = \Distilleries\Expendable\Models\User::create(['email' => $faker->email, 'password' => \Hash::make('test'), 'status' => true, 'role_id' => $role->id]);
     return [$role, $service, $permission, $user];
 }
 public function testDestroy()
 {
     $faker = Faker\Factory::create();
     $data = ['libelle' => $faker->name, 'initials' => $faker->name, 'overide_permission' => true];
     $role = \Distilleries\Expendable\Models\Role::create($data);
     $this->call('PUT', action($this->controller . '@putDestroy'), ['id' => $role->id]);
     $newRole = \Distilleries\Expendable\Models\Role::find($role->id);
     $this->assertEquals(null, $newRole);
 }
Example #5
0
 public function buildForm()
 {
     $this->add($this->model->getKeyName(), 'hidden')->add('email', 'email', ['label' => trans('expendable::form.email'), 'validation' => 'required,custom[email]']);
     $id = $this->model->getKey();
     if (!empty($id)) {
         $this->add('change_password', 'checkbox', ['default_value' => 1, 'label' => trans('expendable::form.change_password_help'), 'checked' => false, 'noInEditView' => true]);
     }
     $this->add('password', 'password', ['label' => trans('expendable::form.password'), 'attr' => ['id' => 'password'], 'validation' => 'required', 'noInEditView' => true])->add('password_match', 'password', ['label' => trans('expendable::form.repeat_password'), 'validation' => 'required,equals[password]', 'noInEditView' => true])->add('status', 'choice', ['choices' => StaticLabel::status(), 'empty_value' => '-', 'validation' => 'required', 'label' => trans('expendable::form.status')])->add('role_id', 'choice', ['choices' => Role::getChoice(), 'empty_value' => '-', 'validation' => 'required', 'label' => trans('expendable::form.role')])->addDefaultActions();
 }
 public function applyFilters()
 {
     parent::applyFilters();
     if (UserUtils::isNotSuperAdmin()) {
         $super_admin = Role::where('initials', '=', '@sa')->get()->last();
         if (!empty($super_admin)) {
             $this->model = $this->model->where('role_id', '!=', $super_admin->id);
         }
     }
 }
 public function testDestroy()
 {
     $faker = Faker\Factory::create();
     $role = \Distilleries\Expendable\Models\Role::create(['libelle' => $faker->name, 'initials' => $faker->name, 'overide_permission' => true]);
     $service = \Distilleries\Expendable\Models\Service::create(['action' => $faker->name]);
     $permission = \Distilleries\Expendable\Models\Permission::create(['role_id' => $role->id, 'service_id' => $service->id]);
     $this->call('PUT', action($this->controller . '@putDestroy'), ['id' => $permission->id]);
     $newService = \Distilleries\Expendable\Models\Permission::find($permission->id);
     $this->assertEquals(null, $newService);
 }
 public function setUp()
 {
     parent::setUp();
     \Distilleries\Expendable\Models\Role::create(['libelle' => 'admin', 'initials' => '@a', 'overide_permission' => true]);
     \Distilleries\Expendable\Models\Service::create(['action' => 'test']);
     $faker = Faker\Factory::create();
     $email = $faker->email;
     $user = \Distilleries\Expendable\Models\User::create(['email' => $email, 'password' => \Hash::make('test'), 'status' => true, 'role_id' => 1]);
     \Distilleries\Expendable\Models\Permission::create(['role_id' => 1, 'service_id' => 1]);
     $this->be($user);
 }
Example #9
0
 protected function login()
 {
     $role = \Distilleries\Expendable\Models\Role::get()->last();
     if (empty($role)) {
         \Distilleries\Expendable\Models\Role::create(['libelle' => 'admin', 'initials' => '@a', 'overide_permission' => false]);
     }
     $faker = Faker\Factory::create();
     $email = $faker->email;
     \Distilleries\Expendable\Models\User::create(['email' => $email, 'password' => \Hash::make('test'), 'status' => true, 'role_id' => 1]);
     $this->app->make('Illuminate\\Contracts\\Auth\\Guard')->attempt(['email' => $email, 'password' => 'test']);
     return $email;
 }
 public function setUp()
 {
     parent::setUp();
     $this->artisan('migrate', ['--database' => 'testbench', '--realpath' => realpath(__DIR__ . '/../../../../vendor/distilleries/mailersaver/src/database/migrations')]);
     \Distilleries\Expendable\Models\Role::create(['libelle' => 'admin', 'initials' => '@a', 'overide_permission' => true]);
     \Distilleries\Expendable\Models\Service::create(['action' => 'test']);
     $faker = Faker\Factory::create();
     $email = $faker->email;
     $user = \Distilleries\Expendable\Models\User::create(['email' => $email, 'password' => \Hash::make('test'), 'status' => true, 'role_id' => 1]);
     \Distilleries\Expendable\Models\Permission::create(['role_id' => 1, 'service_id' => 1]);
     $this->be($user);
 }
Example #11
0
 public function testExceptionNoCatche()
 {
     $faker = Faker\Factory::create();
     $role = \Distilleries\Expendable\Models\Role::create(['libelle' => $faker->name, 'initials' => $faker->name, 'overide_permission' => true]);
     $service = \Distilleries\Expendable\Models\Service::create(['action' => $faker->name]);
     $email = $faker->email;
     $user = \Distilleries\Expendable\Models\User::create(['email' => str_replace('\'', '', $email), 'password' => \Hash::make('test'), 'status' => true, 'role_id' => $role->id]);
     \Distilleries\Expendable\Models\Permission::create(['role_id' => $role->id, 'service_id' => $service->id]);
     $this->be($user);
     $response = $this->call('GET', '/test');
     $this->assertEquals(404, $response->getStatusCode());
     $this->assertNotContains('page-404', $response->getContent());
     $this->assertContains('<h1>Sorry, the page you are looking for could not be found.</h1>', $response->getContent());
 }
Example #12
0
 public function testListenerDispatcherUserLoginWithRole()
 {
     \Distilleries\Expendable\Models\Role::create(['libelle' => 'admin', 'initials' => '@a', 'overide_permission' => false]);
     \Distilleries\Expendable\Models\Service::create(['action' => 'test']);
     $faker = Faker\Factory::create();
     \Distilleries\Expendable\Models\User::create(['email' => $faker->email, 'password' => \Hash::make('test'), 'status' => true, 'role_id' => 1]);
     \Distilleries\Expendable\Models\Permission::create(['role_id' => 1, 'service_id' => 1]);
     global $firedTestListener;
     $firedTestListener = false;
     $listener = new TestListener();
     $listener->listen();
     new \Distilleries\Expendable\Events\UserEvent(\Distilleries\Expendable\Events\UserEvent::LOGIN_EVENT, \Distilleries\Expendable\Models\User::find(1));
     $this->assertEquals(true, $firedTestListener);
 }
Example #13
0
 public function run()
 {
     Role::create(['libelle' => 'superadmin', 'initials' => '@sa', 'overide_permission' => true]);
     Role::create(['libelle' => 'admin', 'initials' => '@a', 'overide_permission' => false]);
 }
 public function testPostResetValid()
 {
     $token = 'bEJa3ysNqVCOv4SkGkcrJnJWqAOmh93UZrmv1IM171zAJ82WylyXh7c4CRHW';
     $faker = Faker\Factory::create();
     \Distilleries\Expendable\Models\Role::create(['libelle' => 'admin', 'initials' => '@a', 'overide_permission' => true]);
     \Distilleries\Expendable\Models\Service::create(['action' => 'test']);
     $faker = Faker\Factory::create();
     $email = $faker->email;
     $user = \Distilleries\Expendable\Models\User::create(['email' => $email, 'password' => \Hash::make('test'), 'status' => true, 'role_id' => 1]);
     \DB::table('password_resets')->insert(array('email' => $email, 'token' => $token, 'created_at' => date('Y-m-d H:i:s')));
     \Distilleries\Expendable\Models\Permission::create(['role_id' => 1, 'service_id' => 1]);
     $this->call('POST', action('Admin\\LoginController@postReset'), ['token' => $token, 'email' => $email, 'password' => 'testtesttesttest', 'password_confirmation' => 'testtesttesttest']);
     $this->assertRedirectedToAction('Admin\\LoginController@getIndex');
 }
 public function testPermissionRole()
 {
     list($role, $service, $permission) = $this->addContent();
     $expected = \Distilleries\Expendable\Models\Role::find($role->id);
     $this->assertEquals($expected, $permission->role);
 }
 public function testSearchWithRole()
 {
     $faker = Faker\Factory::create();
     $role = \Distilleries\Expendable\Models\Role::create(['libelle' => $faker->name, 'initials' => $faker->name, 'overide_permission' => true]);
     $service = \Distilleries\Expendable\Models\Service::create(['action' => $faker->name]);
     $email = $faker->email;
     $user = \Distilleries\Expendable\Models\User::create(['email' => $email, 'password' => \Hash::make('test'), 'status' => true, 'role_id' => $role->id]);
     \Distilleries\Expendable\Models\Permission::create(['role_id' => $role->id, 'service_id' => $service->id]);
     $response = $this->call('POST', action($this->controller . '@postSearchWithRole'), ['ids' => [$user->id], 'role' => $role->id]);
     $result = json_decode($response->getContent());
     $this->assertEquals($user->id, $result[0]->id);
     $this->assertEquals($user->email, $result[0]->email);
     $response = $this->call('POST', action($this->controller . '@postSearchWithRole'), ['ids' => [$user->id], 'role' => -1]);
     $result = json_decode($response->getContent());
     $this->assertEquals(0, count($result));
 }