Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: ['8.2', '8.3', '8.4']
php-version: ['8.2', '8.3', '8.4', '8.5']
db-type: [sqlite, mysql, pgsql]
prefer-lowest: ['']

Expand Down
2 changes: 1 addition & 1 deletion src/Traits/RandomStringTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ trait RandomStringTrait
/**
* Generates random string
*
* @param int|string $length String size.
* @param string|int $length String size.
* @return string
*/
public function randomString($length = 10)
Expand Down
31 changes: 31 additions & 0 deletions tests/Fixture/UsersFixture.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/**
Expand Down Expand Up @@ -69,6 +70,9 @@ public function init(): void
],
],
'last_login' => '2015-06-24 17:33:54',
'login_token' => null,
'login_token_date' => null,
'token_send_requested' => false,
],
[
'id' => '00000000-0000-0000-0000-000000000002',
Expand All @@ -91,6 +95,9 @@ public function init(): void
'created' => '2015-06-24 17:33:54',
'modified' => '2015-06-24 17:33:54',
'last_login' => '2015-06-24 17:33:54',
'login_token' => null,
'login_token_date' => null,
'token_send_requested' => false,
],
[
'id' => '00000000-0000-0000-0000-000000000003',
Expand All @@ -111,6 +118,9 @@ public function init(): void
'role' => UsersTable::ROLE_ADMIN,
'created' => '2015-06-24 17:33:54',
'modified' => '2015-06-24 17:33:54',
'login_token' => null,
'login_token_date' => null,
'token_send_requested' => false,
],
[
'id' => '00000000-0000-0000-0000-000000000004',
Expand All @@ -131,6 +141,9 @@ public function init(): void
'role' => 'Lorem ipsum dolor sit amet',
'created' => '2015-06-24 17:33:54',
'modified' => '2015-06-24 17:33:54',
'login_token' => null,
'login_token_date' => null,
'token_send_requested' => false,
],
[
'id' => '00000000-0000-0000-0000-000000000005',
Expand All @@ -151,6 +164,9 @@ public function init(): void
'role' => UsersTable::ROLE_USER,
'created' => '2015-06-24 17:33:54',
'modified' => '2015-06-24 17:33:54',
'login_token' => null,
'login_token_date' => null,
'token_send_requested' => false,
],
[
'id' => '00000000-0000-0000-0000-000000000006',
Expand All @@ -171,6 +187,9 @@ public function init(): void
'role' => UsersTable::ROLE_USER,
'created' => '2015-06-24 17:33:54',
'modified' => '2015-06-24 17:33:54',
'login_token' => null,
'login_token_date' => null,
'token_send_requested' => false,
],
[
'id' => '00000000-0000-0000-0000-000000000007',
Expand All @@ -191,6 +210,9 @@ public function init(): void
'role' => 'Lorem ipsum dolor sit amet',
'created' => '2015-06-24 17:33:54',
'modified' => '2015-06-24 17:33:54',
'login_token' => null,
'login_token_date' => null,
'token_send_requested' => false,
],
[
'id' => '00000000-0000-0000-0000-000000000008',
Expand All @@ -211,6 +233,9 @@ public function init(): void
'role' => 'Lorem ipsum dolor sit amet',
'created' => '2015-06-24 17:33:54',
'modified' => '2015-06-24 17:33:54',
'login_token' => null,
'login_token_date' => null,
'token_send_requested' => false,
],
[
'id' => '00000000-0000-0000-0000-000000000009',
Expand All @@ -231,6 +256,9 @@ public function init(): void
'role' => 'Lorem ipsum dolor sit amet',
'created' => '2015-06-24 17:33:54',
'modified' => '2015-06-24 17:33:54',
'login_token' => null,
'login_token_date' => null,
'token_send_requested' => false,
],
[
'id' => '00000000-0000-0000-0000-000000000010',
Expand All @@ -251,6 +279,9 @@ public function init(): void
'role' => 'Lorem ipsum dolor sit amet',
'created' => '2015-06-24 17:33:54',
'modified' => '2015-06-24 17:33:54',
'login_token' => null,
'login_token_date' => null,
'token_send_requested' => false,
],
];

Expand Down
87 changes: 87 additions & 0 deletions tests/TestCase/Loader/AuthenticationServiceLoaderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php
declare(strict_types=1);

namespace CakeDC\Users\Test\TestCase\Loader;

use Cake\Core\Configure;
use Cake\Http\ServerRequest;
use Cake\TestSuite\TestCase;
use CakeDC\Users\Loader\AuthenticationServiceLoader;

/**
* AuthenticationServiceLoader Test Case
*/
class AuthenticationServiceLoaderTest extends TestCase
{
/**
* @var \CakeDC\Users\Loader\AuthenticationServiceLoader
*/
protected $Loader;

/**
* setUp method
*
* @return void
*/
public function setUp(): void
{
parent::setUp();
$this->Loader = new AuthenticationServiceLoader();
Configure::write('Auth.Authenticators', [
'Authentication.Session',
'Authentication.Form',
]);
Configure::write('Auth.Identifiers', [
'Authentication.Password',
]);
}

/**
* tearDown method
*
* @return void
*/
public function tearDown(): void
{
unset($this->Loader);
parent::tearDown();
}

/**
* Test loadAuthenticationService method
*
* @return void
*/
public function testInvoke(): void
{
$request = new ServerRequest();
$loader = $this->Loader;
$service = $loader($request);

$this->assertInstanceOf(\Authentication\AuthenticationServiceInterface::class, $service);
$this->assertNotEmpty($service->authenticators());
}

/**
* Test loadAuthenticationService with custom config
*
* @return void
*/
public function testInvokeWithCustomConfig(): void
{
Configure::write('Auth.Authenticators', [
'Token' => [
'className' => 'Authentication.Token',
'queryParam' => 'token',
],
]);

$request = new ServerRequest();
$loader = $this->Loader;
$service = $loader($request);

$this->assertInstanceOf(\Authentication\AuthenticationServiceInterface::class, $service);
$authenticator = $service->authenticators()->get('Token');
$this->assertInstanceOf(\Authentication\Authenticator\TokenAuthenticator::class, $authenticator);
}
}
34 changes: 34 additions & 0 deletions tests/TestCase/Model/Behavior/MockDeliveryHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
declare(strict_types=1);

namespace CakeDC\Users\Test\TestCase\Model\Behavior;

use Cake\Datasource\EntityInterface;

/**
* Mock Delivery Handler
*/
class MockDeliveryHandler
{
/**
* @var array
*/
public static $sent = [];

/**
* @param array $options Options
*/
public function __construct(array $options = [])
{
}

/**
* @param \Cake\Datasource\EntityInterface $user User
* @param string $token Token
* @return void
*/
public function send(EntityInterface $user, string $token): void
{
static::$sent[] = ['user' => $user, 'token' => $token];
}
}
Loading
Loading