class OpenIDConnectStateTokenTest in OpenID Connect / OAuth client 2.x
Same name and namespace in other branches
- 8 tests/src/Unit/OpenIDConnectStateTokenTest.php \Drupal\Tests\openid_connect\Unit\OpenIDConnectStateTokenTest
Test the OpenIDConnectStateToken class.
@coversDefaultClass \Drupal\openid_connect\OpenIDConnectStateToken @group openid_connect
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, PhpUnitCompatibilityTrait, PhpUnitWarnings
- class \Drupal\Tests\openid_connect\Unit\OpenIDConnectStateTokenTest
Expanded class hierarchy of OpenIDConnectStateTokenTest
File
- tests/
src/ Unit/ OpenIDConnectStateTokenTest.php, line 17
Namespace
Drupal\Tests\openid_connect\UnitView source
class OpenIDConnectStateTokenTest extends UnitTestCase {
/**
* Mock of the openid_connect.state_token service.
*
* @var \Drupal\openid_connect\OpenIDConnectStateToken
*/
protected $stateTokenService;
/**
* A mock of the openid_connect.session service.
*
* @var \PHPUnit\Framework\MockObject\MockObject
*/
protected $session;
/**
* The state token created for these tests.
*
* @var string
*/
protected $stateToken;
/**
* {@inheritDoc}
*/
protected function setUp() : void {
parent::setUp();
// Mock the 'openid_connect.session' service.
$this->session = $this
->createMock(OpenIDConnectSessionInterface::class);
$this->stateTokenService = new OpenIDConnectStateToken($this->session);
// Set the state token and save the results.
$this->stateToken = $this->stateTokenService
->generateToken();
}
/**
* Test the state tokens.
*
* @runInSeparateProcess
*/
public function testConfirm() : void {
$random = $this
->randomMachineName();
$this->session
->expects($this
->atLeast(2))
->method('retrieveStateToken')
->willReturnOnConsecutiveCalls($this->stateToken, $random, '');
// Confirm the session matches the state token variable.
$confirmResultTrue = $this->stateTokenService
->confirm($this->stateToken);
$this
->assertEquals(TRUE, $confirmResultTrue);
// Change the session variable.
$this->session
->saveStateToken($random);
$confirmResultFalse = $this->stateTokenService
->confirm($this->stateToken);
// Assert the expected value no longer matches the session.
$this
->assertEquals(FALSE, $confirmResultFalse);
// Check the state token.
$confirmResultEmpty = $this->stateTokenService
->confirm($this->stateToken);
// Assert the session global does not contain the state token.
$this
->assertEquals(FALSE, $confirmResultEmpty);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
OpenIDConnectStateTokenTest:: |
protected | property | A mock of the openid_connect.session service. | |
OpenIDConnectStateTokenTest:: |
protected | property | The state token created for these tests. | |
OpenIDConnectStateTokenTest:: |
protected | property | Mock of the openid_connect.state_token service. | |
OpenIDConnectStateTokenTest:: |
protected | function |
Overrides UnitTestCase:: |
|
OpenIDConnectStateTokenTest:: |
public | function | Test the state tokens. | |
PhpUnitWarnings:: |
private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |
PhpUnitWarnings:: |
public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
public static | function |