Files
Chamilo/vendor/packbackbooks/lti-1p3-tool/tests/LtiOidcLoginTest.php
T
Xes 73154ae174
Behat tests 1.11.x 🐞 / PHP 7.4 Test on ubuntu-latest (push) Canceled after 0s
PHP-CS-Fixer / composer_install (7.4) (push) Canceled after 0s
Chamilo 1.11.40 (ZIP oficial v1.11.40)
Fuente: https://github.com/chamilo/chamilo-lms/releases/download/v1.11.40/chamilo-1.11.40.zip
sha256: 1cf4bf2cc7bae1ef1a1eff643235db1d552f78ddf4b6dd1e2d2dac9868679439
Snapshot independiente (rama huerfana); diffable vs 1.11.38. vendor incluido.
2026-08-06 17:59:45 +02:00

106 lines
2.7 KiB
PHP

<?php namespace Tests;
use Mockery;
use PHPUnit\Framework\TestCase;
use Packback\Lti1p3\Interfaces\Cache;
use Packback\Lti1p3\Interfaces\Cookie;
use Packback\Lti1p3\Interfaces\Database;
use Packback\Lti1p3\LtiOidcLogin;
use Packback\Lti1p3\OidcException;
class LtiOidcLoginTest extends TestCase
{
public function setUp(): void
{
$this->cache = Mockery::mock(Cache::class);
$this->cookie = Mockery::mock(Cookie::class);
$this->database = Mockery::mock(Database::class);
$this->oidcLogin = new LtiOidcLogin(
$this->database,
$this->cache,
$this->cookie
);
}
public function testItInstantiates()
{
$this->assertInstanceOf(LtiOidcLogin::class, $this->oidcLogin);
}
public function testItCreatesANewInstance()
{
$oidcLogin = LtiOidcLogin::new(
$this->database,
$this->cache,
$this->cookie
);
$this->assertInstanceOf(LtiOidcLogin::class, $this->oidcLogin);
}
public function testItValidatesARequest()
{
$expected = 'expected';
$request = [
'iss' => 'Issuer',
'login_hint' => 'LoginHint',
'client_id' => 'ClientId'
];
$this->database->shouldReceive('findRegistrationByIssuer')
->once()->with($request['iss'], $request['client_id'])
->andReturn($expected);
$result = $this->oidcLogin->validateOidcLogin($request);
$this->assertEquals($expected, $result);
}
public function testValidatesFailsIfIssuerIsNotSet()
{
$request = [
'login_hint' => 'LoginHint',
'client_id' => 'ClientId'
];
$this->expectException(OidcException::class);
$this->expectExceptionMessage(LtiOidcLogin::ERROR_MSG_ISSUER);
$this->oidcLogin->validateOidcLogin($request);
}
public function testValidatesFailsIfLoginHintIsNotSet()
{
$request = [
'iss' => 'Issuer',
'client_id' => 'ClientId'
];
$this->expectException(OidcException::class);
$this->expectExceptionMessage(LtiOidcLogin::ERROR_MSG_LOGIN_HINT);
$this->oidcLogin->validateOidcLogin($request);
}
public function testValidatesFailsIfRegistrationNotFound()
{
$request = [
'iss' => 'Issuer',
'login_hint' => 'LoginHint',
];
$this->database->shouldReceive('findRegistrationByIssuer')
->once()->andReturn(null);
$this->expectException(OidcException::class);
$this->expectExceptionMessage(LtiOidcLogin::ERROR_MSG_REGISTRATION);
$this->oidcLogin->validateOidcLogin($request);
}
/**
* @todo Finish testing
*/
}