Completed
Push — feature/policy_unit_tests ( 0c0d69...c4da13 )
by Grant
27:23 queued 19:01
created

ApplicantPolicyTest::getManagerPolicy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
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\Policies\ApplicantPolicy;
10
use App\Policies\ManagerPolicy;
11
12
class ApplicantPolicyTest extends BasePolicyTest
13
{
14
    protected function getApplicantPolicy() {
15
        return new ApplicantPolicy();
16
    }
17
18
    protected function getManagerPolicy() {
19
        return new ManagerPolicy();
20
    }
21
22
    public function testView()
23
    {
24
        //Test 1: User is the applicant
25
        //Expect to be allowed to view
26
        $applicant = $this->makeApplicant();
27
        $userCanViewOwnApplicant = $this->getApplicantPolicy()->view($applicant->user, $applicant);
28
        $this->assertTrue($userCanViewOwnApplicant);
29
30
        //Test 2: Applicants cannot view other applicant
31
        $applicant2 = $this->makeApplicant();
32
        $user1CanViewApplicant2 = $this->getApplicantPolicy()->view($applicant->user, $applicant2);
33
        $this->assertFalse($user1CanViewApplicant2);
34
35
        //Test 3: new manager cannot view new applicant
36
        $jillManager = $this->makeManager();
0 ignored issues
show
Unused Code introduced by
The assignment to $jillManager is dead and can be removed.
Loading history...
37
        $jennyApplicant = $this->makeApplicant();
38
        $canManagerViewapplicant = $this->getApplicantPolicy()->view($applicant->user, $jennyApplicant);
39
        $this->assertFalse($canManagerViewapplicant);
40
41
        //Test 3.5: applicants can view manager
42
        $steveManager = $this->makeManager();
43
        $bobApplicant = $this->makeApplicant();
44
        $canApplicantViewManager = $this->getManagerPolicy()->view($bobApplicant->user, $steveManager);
45
        $this->assertTrue($canApplicantViewManager);
46
47
        //Test 4: applicant starts a job application but doesn't submit.
48
        //  Manager should not be able to view applicant
49
50
        //Test 5: applicant submits a job application. Job's manager should be
51
        //  able to view applicant.
52
    }
53
}
54