Completed
Push — bug/accordion ( 6550f4...474aef )
by Grant
12:54 queued 07:32
created

testNotValidWhenNEmailSameAsAnotherUser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 11
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Tests\Unit\Validators;
4
5
use Tests\TestCase;
6
use Illuminate\Foundation\Testing\RefreshDatabase;
7
use App\Services\Validation\Rules\ContainsObjectWithAttributeRule;
8
use Illuminate\Support\Facades\Validator;
9
use Illuminate\Support\Facades\Hash;
10
use App\Models\Applicant;
11
use App\Models\User;
12
use App\Services\Validation\Requests\UpdateApplicationProfileValidator;
13
14
class UpdateApplicationProfileValidatorTest extends TestCase
15
{
16
17
    /**
18
     * Run parent setup and provide reusable factories.
19
     *
20
     * @return void
21
     */
22
    protected function setUp()
23
    {
24
        parent::setUp();
25
26
        $this->password = 'Testing123!';
0 ignored issues
show
Bug Best Practice introduced by
The property password does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
27
        $this->badPassword = 'WrongPassword123!';
0 ignored issues
show
Bug Best Practice introduced by
The property badPassword does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
28
        $this->user = factory(User::class)->create([
0 ignored issues
show
Bug Best Practice introduced by
The property user does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
29
            'password' => Hash::make('Testing123!')
30
        ]);
31
        $this->applicant = factory(Applicant::class)->create(['user_id' => $this->user->id]);
0 ignored issues
show
Bug Best Practice introduced by
The property applicant does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
32
33
        $this->otherApplicant = factory(Applicant::class)->create();
0 ignored issues
show
Bug Best Practice introduced by
The property otherApplicant does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
34
    }
35
36
    public function testUpdatingBasicProfileIsValid()
37
    {
38
        $data = [
39
            'profile_name' => $this->applicant->user->name,
40
            'profile_email' => $this->applicant->user->email,
41
            'twitter_username' => 'Test_person',
42
            'linkedin_url' => 'www.linkedin.com/in/test-person',
43
            'tagline' => 'GO FOR IT',
44
        ];
45
        $validator = new UpdateApplicationProfileValidator($this->applicant);
46
        $this->assertTrue($validator->isValid($data));
47
    }
48
49
    public function testNotValidWhenNameIsEmpty()
50
    {
51
        $data = [
52
            'profile_name' => '',
53
            'profile_email' => $this->applicant->user->email,
54
            'twitter_username' => 'Test_person',
55
            'linkedin_url' => 'www.linkedin.com/in/test-person',
56
            'tagline' => 'GO FOR IT',
57
        ];
58
        $validator = new UpdateApplicationProfileValidator($this->applicant);
59
        $this->assertFalse($validator->isValid($data));
60
    }
61
62
    public function testNotValidWhenNEmailIsEmpty()
63
    {
64
        $data = [
65
            'profile_name' => $this->applicant->user->name,
66
            'profile_email' => '',
67
            'twitter_username' => 'Test_person',
68
            'linkedin_url' => 'www.linkedin.com/in/test-person',
69
            'tagline' => 'GO FOR IT',
70
        ];
71
        $validator = new UpdateApplicationProfileValidator($this->applicant);
72
        $this->assertFalse($validator->isValid($data));
73
    }
74
75
    public function testNotValidWhenNEmailSameAsAnotherUser()
76
    {
77
        $data = [
78
            'profile_name' => $this->applicant->user->name,
79
            'profile_email' => $this->otherApplicant->user->email,
80
            'twitter_username' => 'Test_person',
81
            'linkedin_url' => 'www.linkedin.com/in/test-person',
82
            'tagline' => 'GO FOR IT',
83
        ];
84
        $validator = new UpdateApplicationProfileValidator($this->applicant);
85
        $this->assertFalse($validator->isValid($data));
86
    }
87
88
    public function testUpdatePasswordValidWithOldAndConfirm()
89
    {
90
        $data = [
91
            'profile_name' => $this->applicant->user->name,
92
            'profile_email' => $this->applicant->user->email,
93
            'old_password' => "Testing123!",
94
            'new_password' => 'NewPassword123!',
95
            'new_password_confirmation' => 'NewPassword123!',
96
            'twitter_username' => 'Test_person',
97
            'linkedin_url' => 'www.linkedin.com/in/test-person',
98
            'tagline' => 'GO FOR IT',
99
        ];
100
        $this->be($this->applicant->user);
101
        $validator = new UpdateApplicationProfileValidator($this->applicant);
102
        $this->assertTrue($validator->isValid($data));
103
    }
104
105
    public function testUpdatePasswordFailsWithoutConfirm()
106
    {
107
        $data = [
108
            'profile_name' => $this->applicant->user->name,
109
            'profile_email' => $this->applicant->user->email,
110
            'old_password' => $this->password,
111
            'new_password' => 'NewPassword123!',
112
            'twitter_username' => 'Test_person',
113
            'linkedin_url' => 'www.linkedin.com/in/test-person',
114
            'tagline' => 'GO FOR IT',
115
        ];
116
        $this->be($this->applicant->user);
117
        $validator = new UpdateApplicationProfileValidator($this->applicant);
118
        $this->assertFalse($validator->isValid($data));
119
    }
120
121
    public function testUpdatePasswordFailsWithBadConfirm()
122
    {
123
        $data = [
124
            'profile_name' => $this->applicant->user->name,
125
            'profile_email' => $this->applicant->user->email,
126
            'old_password' => $this->password,
127
            'new_password' => 'NewPassword123!',
128
            'new_password_confirmation' => 'DifferentPassword123!',
129
            'twitter_username' => 'Test_person',
130
            'linkedin_url' => 'www.linkedin.com/in/test-person',
131
            'tagline' => 'GO FOR IT',
132
        ];
133
        $this->be($this->applicant->user);
134
        $validator = new UpdateApplicationProfileValidator($this->applicant);
135
        $this->assertFalse($validator->isValid($data));
136
    }
137
138
    public function testUpdatePasswordFailsWithIllegalPassword()
139
    {
140
        $data = [
141
            'profile_name' => $this->applicant->user->name,
142
            'profile_email' => $this->applicant->user->email,
143
            'old_password' => $this->password,
144
            'new_password' => 'NewPassword',
145
            'new_password_confirmation' => 'NewPassword',
146
            'twitter_username' => 'Test_person',
147
            'linkedin_url' => 'www.linkedin.com/in/test-person',
148
            'tagline' => 'GO FOR IT',
149
        ];
150
        $this->be($this->applicant->user);
151
        $validator = new UpdateApplicationProfileValidator($this->applicant);
152
        $this->assertFalse($validator->isValid($data));
153
    }
154
155
    public function testUpdatePasswordFailsWithBadOldPassword()
156
    {
157
        $data = [
158
            'profile_name' => $this->applicant->user->name,
159
            'profile_email' => $this->applicant->user->email,
160
            'old_password' => 'NotTheRightPassword123!',
161
            'new_password' => 'NewPassword123!',
162
            'new_password_confirmation' => 'NewPassword123!',
163
            'twitter_username' => 'Test_person',
164
            'linkedin_url' => 'www.linkedin.com/in/test-person',
165
            'tagline' => 'GO FOR IT',
166
        ];
167
        $this->be($this->applicant->user);
168
        $validator = new UpdateApplicationProfileValidator($this->applicant);
169
        $this->assertFalse($validator->isValid($data));
170
    }
171
}
172