class OpenIDConnectStateTokenTest in OpenID Connect / OAuth client 8
Same name and namespace in other branches
- 2.x 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 PhpunitCompatibilityTrait
- class \Drupal\Tests\openid_connect\Unit\OpenIDConnectStateTokenTest
Expanded class hierarchy of OpenIDConnectStateTokenTest
File
- tests/
src/ Unit/ OpenIDConnectStateTokenTest.php, line 16
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;
/**
* The state token created for these tests.
*
* @var string
*/
protected $stateToken;
/**
* {@inheritDoc}
*/
protected function setUp() : void {
parent::setUp();
$this->stateTokenService = new OpenIDConnectStateToken();
// Set the state token and save the results.
$this->stateToken = $this->stateTokenService
->create();
}
/**
* Test the state tokens.
*
* @runInSeparateProcess
*/
public function testConfirm() : void {
// Confirm the session matches the state token variable.
$confirmResultTrue = $this->stateTokenService
->confirm($this->stateToken);
$this
->assertEquals(TRUE, $confirmResultTrue);
// Assert the state token key in the session global.
$this
->assertArrayHasKey('openid_connect_state', $_SESSION);
// Change the session variable.
$_SESSION['openid_connect_state'] = $this
->randomMachineName();
$confirmResultFalse = $this->stateTokenService
->confirm($this->stateToken);
// Assert the expected value no longer matches the session.
$this
->assertEquals(FALSE, $confirmResultFalse);
// Remove the session variable altogether.
unset($_SESSION['openid_connect_state']);
// 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 | 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. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
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 | Mocks a block with a block plugin. | 1 |
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. |