Skip to content
Open
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
21 changes: 6 additions & 15 deletions tests/AbstractUsernamePasswordAuthenticationStrategyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@
use Joomla\Authentication\AbstractUsernamePasswordAuthenticationStrategy;
use Joomla\Authentication\Authentication;
use Joomla\Authentication\Password\HandlerInterface;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\TestCase;

/**
* Test class for \Joomla\Authentication\AbstractUsernamePasswordAuthenticationStrategy
*/
#[CoversClass(AbstractUsernamePasswordAuthenticationStrategy::class)]
class AbstractUsernamePasswordAuthenticationStrategyTest extends TestCase
{
/**
* @testdox A user can be successfully authenticated
*
* @covers Joomla\Authentication\AbstractUsernamePasswordAuthenticationStrategy
*/
#[TestDox('A user can be successfully authenticated')]
public function testAuthenticateSuccess()
{
$handler = $this->createMock(HandlerInterface::class);
Expand All @@ -45,11 +44,7 @@ protected function getHashedPassword($username)
$this->assertSame(Authentication::SUCCESS, $strategy->getResult(), 'The correct result status is set');
}

/**
* @testdox A user cannot be authenticated when a password cannot be found for the username
*
* @covers Joomla\Authentication\AbstractUsernamePasswordAuthenticationStrategy
*/
#[TestDox('A user cannot be authenticated when a password cannot be found for the username')]
public function testAuthenticateNoUser()
{
$handler = $this->createMock(HandlerInterface::class);
Expand All @@ -72,11 +67,7 @@ protected function getHashedPassword($username)
$this->assertSame(Authentication::NO_SUCH_USER, $strategy->getResult(), 'The correct result status is set');
}

/**
* @testdox A user cannot be authenticated when the password cannot be validated
*
* @covers Joomla\Authentication\AbstractUsernamePasswordAuthenticationStrategy
*/
#[TestDox('A user cannot be authenticated when the password cannot be validated')]
public function testAuthenticateInvalidPassword()
{
$handler = $this->createMock(HandlerInterface::class);
Expand Down
12 changes: 2 additions & 10 deletions tests/AuthenticationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@

use Joomla\Authentication\Authentication;
use Joomla\Authentication\AuthenticationStrategyInterface;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

/**
* Test class for \Joomla\Authentication\Authentication
*/
#[CoversClass(Authentication::class)]
class AuthenticationTest extends TestCase
{
/**
Expand All @@ -35,8 +37,6 @@ protected function setUp(): void

/**
* Tests the authenticate method, specifying the strategy by name.
*
* @covers Joomla\Authentication\Authentication
*/
public function testSingleStrategy()
{
Expand All @@ -53,8 +53,6 @@ public function testSingleStrategy()

/**
* Tests the authenticate method, using all strategies
*
* @covers Joomla\Authentication\Authentication
*/
public function testSingleStrategyEmptyArray()
{
Expand All @@ -71,8 +69,6 @@ public function testSingleStrategyEmptyArray()

/**
* Tests the authenticate method, using some strategies.
*
* @covers Joomla\Authentication\Authentication
*/
public function testSomeStrategies()
{
Expand Down Expand Up @@ -101,8 +97,6 @@ public function testSomeStrategies()

/**
* Tests the authenticate method, using a non registered strategy
*
* @covers Joomla\Authentication\Authentication
*/
public function testStrategiesException()
{
Expand All @@ -113,8 +107,6 @@ public function testStrategiesException()

/**
* Tests getting the result back.
*
* @covers Joomla\Authentication\Authentication
*/
public function testGetResults()
{
Expand Down
9 changes: 4 additions & 5 deletions tests/Password/Argon2iHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
namespace Joomla\Authentication\Tests\Password;

use Joomla\Authentication\Password\Argon2iHandler;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\TestCase;

/**
* Test class for \Joomla\Authentication\Password\Argon2iHandler
*/
#[CoversClass(Argon2iHandler::class)]
class Argon2iHandlerTest extends TestCase
{
/**
Expand All @@ -27,11 +30,7 @@ public static function setUpBeforeClass(): void
parent::setUpBeforeClass();
}

/**
* @testdox A password is hashed and validated
*
* @covers Joomla\Authentication\Password\Argon2iHandler
*/
#[TestDox('A password is hashed and validated')]
public function testAPasswordIsHashedAndValidated()
{
$handler = new Argon2iHandler();
Expand Down
9 changes: 4 additions & 5 deletions tests/Password/Argon2idHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
namespace Joomla\Authentication\Tests\Password;

use Joomla\Authentication\Password\Argon2idHandler;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\TestCase;

/**
* Test class for \Joomla\Authentication\Password\Argon2idHandler
*/
#[CoversClass(Argon2idHandler::class)]
class Argon2idHandlerTest extends TestCase
{
/**
Expand All @@ -27,11 +30,7 @@ public static function setUpBeforeClass(): void
parent::setUpBeforeClass();
}

/**
* @testdox A password is hashed and validated
*
* @covers Joomla\Authentication\Password\Argon2idHandler
*/
#[TestDox('A password is hashed and validated')]
public function testAPasswordIsHashedAndValidated()
{
$handler = new Argon2idHandler();
Expand Down
9 changes: 4 additions & 5 deletions tests/Password/BCryptHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@
namespace Joomla\Authentication\Tests\Password;

use Joomla\Authentication\Password\BCryptHandler;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\TestCase;

/**
* Test class for \Joomla\Authentication\Password\BCryptHandler
*/
#[CoversClass(BCryptHandler::class)]
class BCryptHandlerTest extends TestCase
{
/**
* @testdox A password is hashed and validated
*
* @covers Joomla\Authentication\Password\BCryptHandler
*/
#[TestDox('A password is hashed and validated')]
public function testAPasswordIsHashedAndValidated()
{
$handler = new BCryptHandler();
Expand Down
59 changes: 26 additions & 33 deletions tests/Strategies/DatabaseStrategyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,24 @@

namespace Joomla\Authentication\Tests\Strategies;

use Joomla\Authentication\AbstractUsernamePasswordAuthenticationStrategy;
use Joomla\Authentication\Authentication;
use Joomla\Authentication\Password\HandlerInterface;
use Joomla\Authentication\Strategies\DatabaseStrategy;
use Joomla\Database\DatabaseDriver;
use Joomla\Database\DatabaseInterface;
use Joomla\Database\QueryInterface;
use Joomla\Input\Input;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

/**
* Test class for \Joomla\Authentication\Strategies\DatabaseStrategy
*/
#[CoversClass(DatabaseStrategy::class)]
#[UsesClass(AbstractUsernamePasswordAuthenticationStrategy::class)]
class DatabaseStrategyTest extends TestCase
{
/**
Expand Down Expand Up @@ -51,30 +56,27 @@ protected function setUp(): void

/**
* Tests the authenticate method with valid credentials.
*
* @covers Joomla\Authentication\Strategies\DatabaseStrategy
* @uses Joomla\Authentication\AbstractUsernamePasswordAuthenticationStrategy
*/
public function testValidPassword()
{
$query = $this->createMock(QueryInterface::class);
$query->expects($this->any())
$query->expects($this->once())
->method('select')
->willReturnSelf();

$query->expects($this->any())
$query->expects($this->once())
->method('from')
->willReturnSelf();

$query->expects($this->any())
$query->expects($this->once())
->method('where')
->willReturnSelf();

$query->expects($this->any())
$query->expects($this->once())
->method('bind')
->willReturnSelf();

$this->db->expects($this->any())
$this->db->expects($this->once())
->method('createQuery')
->willReturn($query);

Expand All @@ -87,11 +89,11 @@ public function testValidPassword()
->method('loadResult')
->willReturn('$2y$10$.vpEGa99w.WUetDFJXjMn.RiKRhZ/ImzxtOjtoJ0VFDV8S7ua0uJG');

$this->input->expects($this->any())
$this->input->expects($this->exactly(2))
->method('get')
->willReturnArgument(0);

$this->passwordHandler->expects($this->any())
$this->passwordHandler->expects($this->once())
->method('validatePassword')
->willReturn(true);

Expand All @@ -103,30 +105,27 @@ public function testValidPassword()

/**
* Tests the authenticate method with invalid credentials.
*
* @covers Joomla\Authentication\Strategies\DatabaseStrategy
* @uses Joomla\Authentication\AbstractUsernamePasswordAuthenticationStrategy
*/
public function testInvalidPassword()
{
$query = $this->createMock(QueryInterface::class);
$query->expects($this->any())
$query->expects($this->once())
->method('select')
->willReturnSelf();

$query->expects($this->any())
$query->expects($this->once())
->method('from')
->willReturnSelf();

$query->expects($this->any())
$query->expects($this->once())
->method('where')
->willReturnSelf();

$query->expects($this->any())
$query->expects($this->once())
->method('bind')
->willReturnSelf();

$this->db->expects($this->any())
$this->db->expects($this->once())
->method('createQuery')
->willReturn($query);

Expand All @@ -139,11 +138,11 @@ public function testInvalidPassword()
->method('loadResult')
->willReturn('$2y$10$.vpEGa99w.WUetDFJXjMn.RiKRhZ/ImzxtOjtoJ0VFDV8S7ua0uJH');

$this->input->expects($this->any())
$this->input->expects($this->exactly(2))
->method('get')
->willReturnArgument(0);

$this->passwordHandler->expects($this->any())
$this->passwordHandler->expects($this->once())
->method('validatePassword')
->willReturn(false);

Expand All @@ -155,16 +154,13 @@ public function testInvalidPassword()

/**
* Tests the authenticate method with no credentials provided.
*
* @covers Joomla\Authentication\Strategies\DatabaseStrategy
* @uses Joomla\Authentication\AbstractUsernamePasswordAuthenticationStrategy
*/
public function testNoPassword()
{
$this->db->expects($this->never())
->method('setQuery');

$this->input->expects($this->any())
$this->input->expects($this->exactly(2))
->method('get')
->willReturn(false);

Expand All @@ -179,30 +175,27 @@ public function testNoPassword()

/**
* Tests the authenticate method with credentials for an unknown user.
*
* @covers Joomla\Authentication\Strategies\DatabaseStrategy
* @uses Joomla\Authentication\AbstractUsernamePasswordAuthenticationStrategy
*/
public function testUserNotExist()
{
$query = $this->createMock(QueryInterface::class);
$query->expects($this->any())
$query->expects($this->once())
->method('select')
->willReturnSelf();

$query->expects($this->any())
$query->expects($this->once())
->method('from')
->willReturnSelf();

$query->expects($this->any())
$query->expects($this->once())
->method('where')
->willReturnSelf();

$query->expects($this->any())
$query->expects($this->once())
->method('bind')
->willReturnSelf();

$this->db->expects($this->any())
$this->db->expects($this->once())
->method('createQuery')
->willReturn($query);

Expand All @@ -215,7 +208,7 @@ public function testUserNotExist()
->method('loadResult')
->willReturn(null);

$this->input->expects($this->any())
$this->input->expects($this->exactly(2))
->method('get')
->willReturnArgument(0);

Expand Down
Loading