-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathUserSpec.php
More file actions
202 lines (171 loc) · 5.69 KB
/
UserSpec.php
File metadata and controls
202 lines (171 loc) · 5.69 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<?php
namespace spec\Scriptotek\Alma\Users;
use PhpSpec\ObjectBehavior;
use Scriptotek\Alma\Client as AlmaClient;
use Scriptotek\Alma\Users\Fees;
use Scriptotek\Alma\Users\Loans;
use Scriptotek\Alma\Users\Requests;
use Scriptotek\Alma\Users\User;
use spec\Scriptotek\Alma\SpecHelper;
class UserSpec extends ObjectBehavior
{
public function let(AlmaClient $client)
{
$this->beConstructedWith($client, '12345');
$client->getJSON('/users/12345')
->willReturn(SpecHelper::getDummyData('user_response.json'));
}
public function it_is_initializable()
{
$this->shouldHaveType(User::class);
}
public function it_has_primary_id()
{
$this->primaryId->shouldBe('12345');
}
public function it_has_barcode()
{
$this->barcode->shouldBe('ub54321');
}
public function it_has_barcodes()
{
$this->barcodes->shouldBe(['ub54321', 'ntb12897787']);
}
public function it_has_university_id()
{
$this->universityId->shouldBe('test@uio.no');
}
public function it_has_university_ids()
{
$this->universityIds->shouldBe(['test@uio.no']);
}
public function it_has_identifiers()
{
$this->identifiers->all()->shouldBe(['12345', 'ub54321', 'ntb12897787', 'test@uio.no']);
}
public function it_has_loans(AlmaClient $client)
{
SpecHelper::expectNoRequests($client);
$this->loans->shouldHaveType(Loans::class);
}
public function it_has_fees(AlmaClient $client)
{
SpecHelper::expectNoRequests($client);
$this->fees->shouldHaveType(Fees::class);
}
public function it_has_requests()
{
$this->requests->shouldHaveType(Requests::class);
}
public function it_has_sms()
{
$this->contactInfo->getSmsNumber()->phone_number->shouldBe('87654321');
}
public function it_can_change_sms()
{
$this->contactInfo->setSmsNumber('12345678');
$this->contactInfo->getSmsNumber()->phone_number->shouldBe('12345678');
}
public function it_can_add_sms()
{
$this->contactInfo->setSmsNumber('9999999');
$this->contactInfo->getSmsNumber()->phone_number->shouldBe('9999999');
}
public function it_can_remove_sms()
{
$this->contactInfo->unsetSmsNumber();
$this->contactInfo->getSmsNumber()->shouldBe(null);
}
public function it_can_add_email()
{
$this->contactInfo->addEmail('example@example.com', 'work', true);
$this->contactInfo->getEmail()->email_address->shouldBe('example@example.com');
}
public function it_can_unset_email()
{
$this->contactInfo->unsetEmail();
$this->contactInfo->getEmail()->shouldBe(null);
}
public function it_can_remove_email()
{
$this->contactInfo->removeEmail('dan@banan.com');
$this->contactInfo->allEmails()->shouldBe([]);
}
public function it_can_add_address()
{
$this->contactInfo->addAddress([
'line1' => '123 Something Blvd.',
'city' => 'Somewhere',
'state_province' => 'IL',
'postal_code' => '12345',
'country' => 'USA',
'address_type' => 'home'
])->shouldBeAnInstanceOf('Scriptotek\Alma\Users\Address');
$this->contactInfo->address[1]->shouldBeLike((object) [
'line1' => '123 Something Blvd.',
'city' => 'Somewhere',
'state_province' => 'IL',
'postal_code' => '12345',
'country' => (object) ['value' => 'USA'],
'address_type' => [(object) ['value' => 'home']]
]);
}
public function it_can_remove_address()
{
$address = $this->contactInfo->addresses[0];
$this->contactInfo->removeAddress($address);
$this->contactInfo->addresses->shouldBe([]);
}
public function it_can_set_preferred_address()
{
$address = $this->contactInfo->addresses[0];
$address->preferred = true;
$address->preferred->shouldBe(true);
$address->preferred = false;
$address->preferred->shouldBe(false);
}
public function it_can_unset_preferred_address()
{
$this->contactInfo->unsetPreferredAddress();
$this->contactInfo->getPreferredAddress()->shouldBe(null);
}
public function it_can_set_address_type()
{
$address = $this->contactInfo->addresses[0];
$address->setAddressType('work', 'Work');
$address->data->address_type[0]->shouldBeLike((object)[
'value' => 'work',
'desc' => 'Work'
]);
$address->address_type = 'home';
$address->data->address_type[0]->shouldBeLike((object)[
'value' => 'home'
]);
}
public function it_can_add_phone_number()
{
$this->contactInfo->addPhone('8675309', 'home', true);
$this->contactInfo->getPreferredPhone()->phone_number->shouldBe('8675309');
}
public function it_can_remove_phone_number()
{
$this->contactInfo->removePhone('12345678');
$this->contactInfo->getPreferredPhone()->shouldBe(null);
}
public function it_can_set_preferred_phone()
{
$this->contactInfo->setPreferredPhone('87654321');
$this->contactInfo->getPreferredPhone()->phone_number->shouldBe('87654321');
}
public function it_can_unset_preferred_phone()
{
$this->contactInfo->unsetPreferredPhone();
$this->contactInfo->getPreferredPhone()->shouldBe(null);
}
public function it_can_get_all_phone_numbers()
{
$phones = $this->contactInfo->allPhones();
$phones[0]->phone_number->shouldBe('12345678');
$phones[1]->phone_number->shouldBe('87654321');
}
}