Skip to content

Commit f0c954c

Browse files
authored
Merge pull request #1162 from CakeDC/add-tests
Add tests
2 parents 72fcaa2 + 3bf8802 commit f0c954c

File tree

8 files changed

+453
-2
lines changed

8 files changed

+453
-2
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
php-version: ['8.2', '8.3', '8.4']
16+
php-version: ['8.2', '8.3', '8.4', '8.5']
1717
db-type: [sqlite, mysql, pgsql]
1818
prefer-lowest: ['']
1919

src/Traits/RandomStringTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ trait RandomStringTrait
1818
/**
1919
* Generates random string
2020
*
21-
* @param int|string $length String size.
21+
* @param string|int $length String size.
2222
* @return string
2323
*/
2424
public function randomString($length = 10)

tests/Fixture/UsersFixture.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
/**
@@ -69,6 +70,9 @@ public function init(): void
6970
],
7071
],
7172
'last_login' => '2015-06-24 17:33:54',
73+
'login_token' => null,
74+
'login_token_date' => null,
75+
'token_send_requested' => false,
7276
],
7377
[
7478
'id' => '00000000-0000-0000-0000-000000000002',
@@ -91,6 +95,9 @@ public function init(): void
9195
'created' => '2015-06-24 17:33:54',
9296
'modified' => '2015-06-24 17:33:54',
9397
'last_login' => '2015-06-24 17:33:54',
98+
'login_token' => null,
99+
'login_token_date' => null,
100+
'token_send_requested' => false,
94101
],
95102
[
96103
'id' => '00000000-0000-0000-0000-000000000003',
@@ -111,6 +118,9 @@ public function init(): void
111118
'role' => UsersTable::ROLE_ADMIN,
112119
'created' => '2015-06-24 17:33:54',
113120
'modified' => '2015-06-24 17:33:54',
121+
'login_token' => null,
122+
'login_token_date' => null,
123+
'token_send_requested' => false,
114124
],
115125
[
116126
'id' => '00000000-0000-0000-0000-000000000004',
@@ -131,6 +141,9 @@ public function init(): void
131141
'role' => 'Lorem ipsum dolor sit amet',
132142
'created' => '2015-06-24 17:33:54',
133143
'modified' => '2015-06-24 17:33:54',
144+
'login_token' => null,
145+
'login_token_date' => null,
146+
'token_send_requested' => false,
134147
],
135148
[
136149
'id' => '00000000-0000-0000-0000-000000000005',
@@ -151,6 +164,9 @@ public function init(): void
151164
'role' => UsersTable::ROLE_USER,
152165
'created' => '2015-06-24 17:33:54',
153166
'modified' => '2015-06-24 17:33:54',
167+
'login_token' => null,
168+
'login_token_date' => null,
169+
'token_send_requested' => false,
154170
],
155171
[
156172
'id' => '00000000-0000-0000-0000-000000000006',
@@ -171,6 +187,9 @@ public function init(): void
171187
'role' => UsersTable::ROLE_USER,
172188
'created' => '2015-06-24 17:33:54',
173189
'modified' => '2015-06-24 17:33:54',
190+
'login_token' => null,
191+
'login_token_date' => null,
192+
'token_send_requested' => false,
174193
],
175194
[
176195
'id' => '00000000-0000-0000-0000-000000000007',
@@ -191,6 +210,9 @@ public function init(): void
191210
'role' => 'Lorem ipsum dolor sit amet',
192211
'created' => '2015-06-24 17:33:54',
193212
'modified' => '2015-06-24 17:33:54',
213+
'login_token' => null,
214+
'login_token_date' => null,
215+
'token_send_requested' => false,
194216
],
195217
[
196218
'id' => '00000000-0000-0000-0000-000000000008',
@@ -211,6 +233,9 @@ public function init(): void
211233
'role' => 'Lorem ipsum dolor sit amet',
212234
'created' => '2015-06-24 17:33:54',
213235
'modified' => '2015-06-24 17:33:54',
236+
'login_token' => null,
237+
'login_token_date' => null,
238+
'token_send_requested' => false,
214239
],
215240
[
216241
'id' => '00000000-0000-0000-0000-000000000009',
@@ -231,6 +256,9 @@ public function init(): void
231256
'role' => 'Lorem ipsum dolor sit amet',
232257
'created' => '2015-06-24 17:33:54',
233258
'modified' => '2015-06-24 17:33:54',
259+
'login_token' => null,
260+
'login_token_date' => null,
261+
'token_send_requested' => false,
234262
],
235263
[
236264
'id' => '00000000-0000-0000-0000-000000000010',
@@ -251,6 +279,9 @@ public function init(): void
251279
'role' => 'Lorem ipsum dolor sit amet',
252280
'created' => '2015-06-24 17:33:54',
253281
'modified' => '2015-06-24 17:33:54',
282+
'login_token' => null,
283+
'login_token_date' => null,
284+
'token_send_requested' => false,
254285
],
255286
];
256287

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace CakeDC\Users\Test\TestCase\Loader;
5+
6+
use Cake\Core\Configure;
7+
use Cake\Http\ServerRequest;
8+
use Cake\TestSuite\TestCase;
9+
use CakeDC\Users\Loader\AuthenticationServiceLoader;
10+
11+
/**
12+
* AuthenticationServiceLoader Test Case
13+
*/
14+
class AuthenticationServiceLoaderTest extends TestCase
15+
{
16+
/**
17+
* @var \CakeDC\Users\Loader\AuthenticationServiceLoader
18+
*/
19+
protected $Loader;
20+
21+
/**
22+
* setUp method
23+
*
24+
* @return void
25+
*/
26+
public function setUp(): void
27+
{
28+
parent::setUp();
29+
$this->Loader = new AuthenticationServiceLoader();
30+
Configure::write('Auth.Authenticators', [
31+
'Authentication.Session',
32+
'Authentication.Form',
33+
]);
34+
Configure::write('Auth.Identifiers', [
35+
'Authentication.Password',
36+
]);
37+
}
38+
39+
/**
40+
* tearDown method
41+
*
42+
* @return void
43+
*/
44+
public function tearDown(): void
45+
{
46+
unset($this->Loader);
47+
parent::tearDown();
48+
}
49+
50+
/**
51+
* Test loadAuthenticationService method
52+
*
53+
* @return void
54+
*/
55+
public function testInvoke(): void
56+
{
57+
$request = new ServerRequest();
58+
$loader = $this->Loader;
59+
$service = $loader($request);
60+
61+
$this->assertInstanceOf(\Authentication\AuthenticationServiceInterface::class, $service);
62+
$this->assertNotEmpty($service->authenticators());
63+
}
64+
65+
/**
66+
* Test loadAuthenticationService with custom config
67+
*
68+
* @return void
69+
*/
70+
public function testInvokeWithCustomConfig(): void
71+
{
72+
Configure::write('Auth.Authenticators', [
73+
'Token' => [
74+
'className' => 'Authentication.Token',
75+
'queryParam' => 'token',
76+
],
77+
]);
78+
79+
$request = new ServerRequest();
80+
$loader = $this->Loader;
81+
$service = $loader($request);
82+
83+
$this->assertInstanceOf(\Authentication\AuthenticationServiceInterface::class, $service);
84+
$authenticator = $service->authenticators()->get('Token');
85+
$this->assertInstanceOf(\Authentication\Authenticator\TokenAuthenticator::class, $authenticator);
86+
}
87+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace CakeDC\Users\Test\TestCase\Model\Behavior;
5+
6+
use Cake\Datasource\EntityInterface;
7+
8+
/**
9+
* Mock Delivery Handler
10+
*/
11+
class MockDeliveryHandler
12+
{
13+
/**
14+
* @var array
15+
*/
16+
public static $sent = [];
17+
18+
/**
19+
* @param array $options Options
20+
*/
21+
public function __construct(array $options = [])
22+
{
23+
}
24+
25+
/**
26+
* @param \Cake\Datasource\EntityInterface $user User
27+
* @param string $token Token
28+
* @return void
29+
*/
30+
public function send(EntityInterface $user, string $token): void
31+
{
32+
static::$sent[] = ['user' => $user, 'token' => $token];
33+
}
34+
}

0 commit comments

Comments
 (0)