Completed
Push — feature/policy_unit_tests ( 8a95e1...e0fa79 )
by Tristan
07:24
created

ApplicantPolicyTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 8
dl 0
loc 18
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testView() 0 12 1
A getPolicy() 0 2 1
1
<?php
2
3
namespace Tests\Unit;
4
5
use Tests\TestCase;
6
use Illuminate\Foundation\Testing\WithFaker;
7
use Illuminate\Foundation\Testing\RefreshDatabase;
8
9
use App\Models\User;
10
use App\Models\Applicant;
11
use App\Models\UserRole;
12
use App\Policies\ApplicantPolicy;
13
14
class ApplicantPolicyTest extends BasePolicyTest
15
{
16
    protected function getPolicy() {
17
        return new ApplicantPolicy();
18
    }
19
20
    public function testView()
21
    {
22
        //Test 1: User is the applicant
23
        //Expect to be allowed to view
24
        $applicant = $this->makeApplicant(1);
25
        $userCanViewOwnApplicant = $this->getPolicy()->view($applicant->user, $applicant);
26
        $this->assertTrue($userCanViewOwnApplicant);
27
28
        //Test 2: Applicants cannot view other applicant
29
        $applicant2 = $this->makeApplicant(2);
30
        $user1CanViewApplicant2 = $this->getPolicy()->view($applicant->user, $applicant2);
31
        $this->assertFalse($user1CanViewApplicant2);
32
    }
33
}
34