OpenIDConnectStateTokenTest.php in OpenID Connect / OAuth client 2.x
File
tests/src/Unit/OpenIDConnectStateTokenTest.php
View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\openid_connect\Unit;
use Drupal\openid_connect\OpenIDConnectSessionInterface;
use Drupal\Tests\UnitTestCase;
use Drupal\openid_connect\OpenIDConnectStateToken;
class OpenIDConnectStateTokenTest extends UnitTestCase {
protected $stateTokenService;
protected $session;
protected $stateToken;
protected function setUp() : void {
parent::setUp();
$this->session = $this
->createMock(OpenIDConnectSessionInterface::class);
$this->stateTokenService = new OpenIDConnectStateToken($this->session);
$this->stateToken = $this->stateTokenService
->generateToken();
}
public function testConfirm() : void {
$random = $this
->randomMachineName();
$this->session
->expects($this
->atLeast(2))
->method('retrieveStateToken')
->willReturnOnConsecutiveCalls($this->stateToken, $random, '');
$confirmResultTrue = $this->stateTokenService
->confirm($this->stateToken);
$this
->assertEquals(TRUE, $confirmResultTrue);
$this->session
->saveStateToken($random);
$confirmResultFalse = $this->stateTokenService
->confirm($this->stateToken);
$this
->assertEquals(FALSE, $confirmResultFalse);
$confirmResultEmpty = $this->stateTokenService
->confirm($this->stateToken);
$this
->assertEquals(FALSE, $confirmResultEmpty);
}
}