-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
ContactEditViewHelperTest.php
94 lines (83 loc) · 2.76 KB
/
ContactEditViewHelperTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
namespace Tests\Unit\Domains\Contact\ManageContact\Web\ViewHelpers;
use App\Domains\Contact\ManageContact\Web\ViewHelpers\ContactEditViewHelper;
use App\Models\Contact;
use App\Models\Gender;
use App\Models\Pronoun;
use App\Models\User;
use App\Models\Vault;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
use function env;
class ContactEditViewHelperTest extends TestCase
{
use DatabaseTransactions;
/** @test */
public function it_gets_the_data_needed_for_the_view(): void
{
$user = User::factory()->create();
$vault = Vault::factory()->create();
$gender = Gender::factory()->create([
'account_id' => $vault->account_id,
]);
$pronoun = Pronoun::factory()->create([
'account_id' => $vault->account_id,
]);
$contact = Contact::factory()->create([
'vault_id' => $vault->id,
'gender_id' => $gender->id,
]);
$array = ContactEditViewHelper::data($vault, $contact, $user);
$this->assertEquals(
4,
count($array)
);
$this->assertArrayHasKey('contact', $array);
$this->assertArrayHasKey('genders', $array);
$this->assertArrayHasKey('pronouns', $array);
$this->assertArrayHasKey('url', $array);
$this->assertEquals(
[
'id' => $contact->id,
'name' => $contact->name,
'first_name' => $contact->first_name,
'last_name' => $contact->last_name,
'middle_name' => $contact->middle_name,
'nickname' => $contact->nickname,
'maiden_name' => $contact->maiden_name,
'gender_id' => $contact->gender_id,
'pronoun_id' => $contact->pronoun_id,
'suffix' => $contact->suffix,
'prefix' => $contact->prefix,
],
$array['contact']
);
$this->assertEquals(
[
0 => [
'id' => $gender->id,
'name' => $gender->name,
'selected' => true,
],
],
$array['genders']->toArray()
);
$this->assertEquals(
[
0 => [
'id' => $pronoun->id,
'name' => $pronoun->name,
'selected' => false,
],
],
$array['pronouns']->toArray()
);
$this->assertEquals(
[
'update' => env('APP_URL').'/vaults/'.$vault->id.'/contacts/'.$contact->id,
'show' => env('APP_URL').'/vaults/'.$vault->id.'/contacts/'.$contact->id,
],
$array['url']
);
}
}