public function OpenIDConnectStateTokenTest::testConfirm 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::testConfirm()
Test the state tokens.
@runInSeparateProcess
File
- tests/
src/ Unit/ OpenIDConnectStateTokenTest.php, line 60
Class
- OpenIDConnectStateTokenTest
- Test the OpenIDConnectStateToken class.
Namespace
Drupal\Tests\openid_connect\UnitCode
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);
}