|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace SmrTest\lib\DefaultGame; |
|
4
|
|
|
|
|
5
|
|
|
use AbstractSmrAccount; |
|
6
|
|
|
use AccountNotFoundException; |
|
7
|
|
|
use Mockery as m; |
|
8
|
|
|
use SmrTest\BaseIntegrationSpec; |
|
9
|
|
|
use SocialLogin; |
|
10
|
|
|
use SocialLogins\Facebook; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class AbstractSmrAccountTest |
|
14
|
|
|
* @covers AbstractSmrAccount |
|
15
|
|
|
*/ |
|
16
|
|
|
class AbstractSmrAccountIntegrationTest extends BaseIntegrationSpec { |
|
17
|
|
|
public function test_account_creation() { |
|
18
|
|
|
$account = AbstractSmrAccount::createAccount("test", "test", "[email protected]", 9, 0); |
|
19
|
|
|
$this->assertEquals("test", $account->getLogin()); |
|
20
|
|
|
$this->assertEquals("[email protected]", $account->getEmail()); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/* |
|
24
|
|
|
* Can easily add forcerefresh tests by asserting original == account for forcerefresh = false |
|
25
|
|
|
* then can tests force refresh true by comparing account ids since the account detauls may get populated with |
|
26
|
|
|
* other stuff on refresh |
|
27
|
|
|
*/ |
|
28
|
|
|
public function test_get_account_by_account_id() { |
|
29
|
|
|
// Given the database has been set up with a user |
|
30
|
|
|
$account = AbstractSmrAccount::createAccount("test", "test", "[email protected]", 9, 0); |
|
31
|
|
|
// And there is no force update |
|
32
|
|
|
$forceUpdate = false; |
|
33
|
|
|
// When the account is retrieved by its ID |
|
34
|
|
|
$abstractSmrAccount = AbstractSmrAccount::getAccount($account->getAccountID(), $forceUpdate); |
|
35
|
|
|
// Then the integrity of the user is correct |
|
36
|
|
|
$this->assertEquals($account, $abstractSmrAccount); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function test_get_account_by_account_id_no_account_found_throws_exception() { |
|
40
|
|
|
$this->expectException(AccountNotFoundException::class); |
|
41
|
|
|
// Given there is no account record |
|
42
|
|
|
// When performing an account lookup by id |
|
43
|
|
|
AbstractSmrAccount::getAccount(123); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function test_get_account_by_name_happy_path() { |
|
47
|
|
|
// Given the database has been set up with a user |
|
48
|
|
|
$original = AbstractSmrAccount::createAccount("test", "test", "[email protected]", 9, 0); |
|
49
|
|
|
// When retrieving account by name |
|
50
|
|
|
$account = AbstractSmrAccount::getAccountByName($original->getLogin()); |
|
51
|
|
|
// Then the record is found |
|
52
|
|
|
$this->assertEquals($original, $account); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function test_get_account_by_name_returns_null_when_no_account_name_provided() { |
|
56
|
|
|
// When retrieving account by null name |
|
57
|
|
|
$account = AbstractSmrAccount::getAccountByName(null); |
|
58
|
|
|
// Then the record is null |
|
59
|
|
|
$this->assertNull($account); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function test_get_account_by_name_returns_null_when_no_record_found() { |
|
63
|
|
|
// Given no record exists |
|
64
|
|
|
// When retrieving account by name |
|
65
|
|
|
$account = AbstractSmrAccount::getAccountByName("any"); |
|
66
|
|
|
// Then the record is null |
|
67
|
|
|
$this->assertNull($account); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function test_get_account_by_email_happy_path() { |
|
71
|
|
|
// Given a record exists |
|
72
|
|
|
$original = AbstractSmrAccount::createAccount("test", "test", "[email protected]", 9, 0); |
|
73
|
|
|
// When retrieving account by email |
|
74
|
|
|
$account = AbstractSmrAccount::getAccountByEmail($original->getEmail()); |
|
75
|
|
|
// Then the record is found |
|
76
|
|
|
$this->assertEquals($original, $account); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function test_get_account_by_email_returns_null_when_no_email_provided() { |
|
80
|
|
|
// When retrieving account by null email |
|
81
|
|
|
$account = AbstractSmrAccount::getAccountByEmail(null); |
|
82
|
|
|
// Then the record is null |
|
83
|
|
|
$this->assertNull($account); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function test_get_account_by_email_returns_null_when_no_record_found() { |
|
87
|
|
|
// Given no record exists |
|
88
|
|
|
// When retrieving account by email |
|
89
|
|
|
$account = AbstractSmrAccount::getAccountByEmail("any"); |
|
90
|
|
|
// Then the record is null |
|
91
|
|
|
$this->assertNull($account); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function test_get_account_by_discord_happy_path() { |
|
95
|
|
|
// Given a record exists |
|
96
|
|
|
// Given the database has been set up with a user |
|
97
|
|
|
$original = AbstractSmrAccount::createAccount("test", "test", "[email protected]", 9, 0); |
|
98
|
|
|
$original->setDiscordId("123"); |
|
99
|
|
|
$original->update(); |
|
100
|
|
|
// When retrieving account by discord |
|
101
|
|
|
$account = AbstractSmrAccount::getAccountByDiscordId($original->getDiscordId(), true); |
|
102
|
|
|
// Then the record is found |
|
103
|
|
|
$this->assertEquals($original->getAccountID(), $account->getAccountID()); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function test_get_account_by_discord_returns_null_when_no_discord_provided() { |
|
107
|
|
|
// When retrieving account by null discord |
|
108
|
|
|
$account = AbstractSmrAccount::getAccountByDiscordId(null); |
|
109
|
|
|
// Then the record is null |
|
110
|
|
|
$this->assertNull($account); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
public function test_get_account_by_discord_returns_null_when_no_record_found() { |
|
114
|
|
|
// Given no record exists |
|
115
|
|
|
// When retrieving account by discord |
|
116
|
|
|
$account = AbstractSmrAccount::getAccountByDiscordId("any"); |
|
117
|
|
|
// Then the record is null |
|
118
|
|
|
$this->assertNull($account); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
public function test_get_account_by_irc_happy_path() { |
|
122
|
|
|
// Given a record exists |
|
123
|
|
|
// Given the database has been set up with a user |
|
124
|
|
|
$original = AbstractSmrAccount::createAccount("test", "test", "[email protected]", 9, 0); |
|
125
|
|
|
$original->setIrcNick("nick"); |
|
126
|
|
|
$original->update(); |
|
127
|
|
|
// When retrieving account by irc |
|
128
|
|
|
$account = AbstractSmrAccount::getAccountByIrcNick($original->getIrcNick(), true); |
|
129
|
|
|
// Then the record is found |
|
130
|
|
|
$this->assertEquals($original->getAccountID(), $account->getAccountID()); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
public function test_get_account_by_irc_returns_null_when_no_irc_provided() { |
|
134
|
|
|
// When retrieving account by null irc |
|
135
|
|
|
$account = AbstractSmrAccount::getAccountByIrcNick(null); |
|
136
|
|
|
// Then the record is null |
|
137
|
|
|
$this->assertNull($account); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
public function test_get_account_by_irc_returns_null_when_no_record_found() { |
|
141
|
|
|
// Given no record exists |
|
142
|
|
|
// When retrieving account by irc |
|
143
|
|
|
$account = AbstractSmrAccount::getAccountByIrcNick("any"); |
|
144
|
|
|
// Then the record is null |
|
145
|
|
|
$this->assertNull($account); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
public function test_get_account_by_social_happy_path() { |
|
149
|
|
|
// Given a record exists |
|
150
|
|
|
$orignal = AbstractSmrAccount::createAccount("test", "test", "[email protected]", 9, 0); |
|
151
|
|
|
$orignal->addAuthMethod("facebook", $orignal->getAccountID()); |
|
152
|
|
|
// And a valid social login |
|
153
|
|
|
$socialLogin = m::mock(Facebook::class)->shouldIgnoreMissing(); |
|
154
|
|
|
$socialLogin |
|
155
|
|
|
->expects() |
|
156
|
|
|
->isValid() |
|
157
|
|
|
->andReturns(true); |
|
158
|
|
|
$socialLogin |
|
159
|
|
|
->expects() |
|
160
|
|
|
->getLoginType() |
|
161
|
|
|
->andReturns("facebook"); |
|
162
|
|
|
$socialLogin |
|
163
|
|
|
->expects() |
|
164
|
|
|
->getUserId() |
|
165
|
|
|
->andReturns($orignal->getAccountID()); |
|
166
|
|
|
// When retrieving account by social |
|
167
|
|
|
$account = AbstractSmrAccount::getAccountBySocialLogin($socialLogin, true); |
|
|
|
|
|
|
168
|
|
|
// Then the record is found |
|
169
|
|
|
$this->assertEquals($orignal->getAccountID(), $account->getAccountID()); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
public function test_get_account_by_social_returns_null_when_social_invalid() { |
|
173
|
|
|
// Given an invalid social login |
|
174
|
|
|
$socialLogin = m::mock(SocialLogin::class)->shouldIgnoreMissing(); |
|
175
|
|
|
$socialLogin |
|
176
|
|
|
->expects() |
|
177
|
|
|
->isValid() |
|
178
|
|
|
->andReturns(false); |
|
179
|
|
|
// When retrieving account by null social |
|
180
|
|
|
$account = AbstractSmrAccount::getAccountBySocialLogin($socialLogin); |
|
|
|
|
|
|
181
|
|
|
// Then the record is null |
|
182
|
|
|
$this->assertNull($account); |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
public function test_get_account_by_social_returns_null_when_no_record_found() { |
|
186
|
|
|
// Given no record exists |
|
187
|
|
|
// And a valid social login |
|
188
|
|
|
$socialLogin = m::mock(SocialLogin::class)->shouldIgnoreMissing(); |
|
189
|
|
|
$socialLogin |
|
190
|
|
|
->expects() |
|
191
|
|
|
->isValid() |
|
192
|
|
|
->andReturns(true); |
|
193
|
|
|
$socialLogin |
|
194
|
|
|
->expects() |
|
195
|
|
|
->getLoginType() |
|
196
|
|
|
->andReturns("facebook"); |
|
197
|
|
|
$socialLogin |
|
198
|
|
|
->expects() |
|
199
|
|
|
->getUserId() |
|
200
|
|
|
->andReturns(123); |
|
201
|
|
|
// When retrieving account by social |
|
202
|
|
|
$account = AbstractSmrAccount::getAccountBySocialLogin($socialLogin); |
|
|
|
|
|
|
203
|
|
|
// Then the record is null |
|
204
|
|
|
$this->assertNull($account); |
|
205
|
|
|
} |
|
206
|
|
|
} |
|
207
|
|
|
|