faker = \Faker\Factory::create(); $account = Account::factory()->create([ 'hosted_client_count' => 1000, 'hosted_company_count' => 1000, ]); $account->num_users = 3; $account->save(); $this->company = Company::factory()->create([ 'account_id' => $account->id, ]); $this->user = User::factory()->create([ 'account_id' => $account->id, 'confirmation_code' => '123', 'email' => $this->faker->safeEmail(), ]); $this->cu = CompanyUserFactory::create($this->user->id, $this->company->id, $account->id); $this->cu->is_owner = false; $this->cu->is_admin = false; $this->cu->is_locked = false; $this->cu->permissions = '["view_client"]'; $this->cu->save(); $this->token = \Illuminate\Support\Str::random(64); $company_token = new CompanyToken; $company_token->user_id = $this->user->id; $company_token->company_id = $this->company->id; $company_token->account_id = $account->id; $company_token->name = 'test token'; $company_token->token = $this->token; $company_token->is_system = true; $company_token->save(); } public function testExactPermissions() { $this->assertTrue($this->user->hasExactPermission("view_client")); $this->assertFalse($this->user->hasExactPermission("view_all")); } public function testMissingPermissions() { $low_cu = CompanyUser::where(['company_id' => $this->company->id, 'user_id' => $this->user->id])->first(); $low_cu->permissions = '[""]'; $low_cu->save(); $this->assertFalse($this->user->hasExactPermission("view_client")); $this->assertFalse($this->user->hasExactPermission("view_all")); } public function testViewAllValidPermissions() { $low_cu = CompanyUser::where(['company_id' => $this->company->id, 'user_id' => $this->user->id])->first(); $low_cu->permissions = '["view_all"]'; $low_cu->save(); $this->assertTrue($this->user->hasExactPermission("view_client")); $this->assertTrue($this->user->hasExactPermission("view_all")); } public function testViewClientPermission() { $low_cu = CompanyUser::where(['company_id' => $this->company->id, 'user_id' => $this->user->id])->first(); $low_cu->permissions = '["view_client"]'; $low_cu->save(); //this is aberrant $this->assertTrue($this->user->hasPermission("viewclient")); } }