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

ApplicantPolicyTest::testView()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 12
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 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\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