|
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
|
|
|
|
|
11
|
|
|
class ApplicantPolicyTest extends BasePolicyTest |
|
12
|
|
|
{ |
|
13
|
|
|
protected function getApplicantPolicy() { |
|
14
|
|
|
return new ApplicantPolicy(); |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
public function testView() |
|
18
|
|
|
{ |
|
19
|
|
|
//Test 1: applicant can view applicant (self) |
|
20
|
|
|
$bobApplicant = $this->createApplicant(); |
|
21
|
|
|
$userCanViewSelf = $this->getApplicantPolicy()->view($bobApplicant->user, $bobApplicant); |
|
22
|
|
|
$this->assertTrue($userCanViewSelf); |
|
23
|
|
|
|
|
24
|
|
|
//Test 2: qpplicant cannot view other applicant |
|
25
|
|
|
$katyApplicant = $this->createApplicant(); |
|
26
|
|
|
$user1CanViewApplicant2 = $this->getApplicantPolicy()->view($katyApplicant->user, $bobApplicant); |
|
27
|
|
|
$this->assertFalse($user1CanViewApplicant2); |
|
28
|
|
|
|
|
29
|
|
|
//Test 3: manager cannot view applicant |
|
30
|
|
|
$jillManager = $this->createManager(); |
|
31
|
|
|
$jennyApplicant = $this->createApplicant(); |
|
32
|
|
|
$canManagerViewapplicant = $this->getApplicantPolicy()->view($jillManager->user, $jennyApplicant); |
|
33
|
|
|
$this->assertFalse($canManagerViewapplicant); |
|
34
|
|
|
|
|
35
|
|
|
//Test 4: applicant starts a job application but doesn't submit. |
|
36
|
|
|
// Manager should not be able to view applicant |
|
37
|
|
|
|
|
38
|
|
|
//Test 5: applicant submits a job application. Job's manager should be |
|
39
|
|
|
// able to view applicant. |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function testCreate() { |
|
43
|
|
|
//Test 1: applicant cannot create user |
|
44
|
|
|
$joeApplicant = $this->createApplicant(); |
|
45
|
|
|
$canApplicantCreateUser = $this->getApplicantPolicy()->create($joeApplicant->user); |
|
46
|
|
|
$this->assertFalse($canApplicantCreateUser); |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
// git pull origin this |
|
51
|
|
|
|
|
52
|
|
|
// Move these tests to another file? One test per file? Ask G or T. |
|
53
|
|
|
|
|
54
|
|
|
|