You are here

public function TfaContextTest::testIsReady in Two-factor Authentication (TFA) 8

@covers ::isReady

File

tests/src/Unit/TfaContextTest.php, line 193

Class

TfaContextTest
@coversDefaultClass \Drupal\tfa\TfaContext

Namespace

Drupal\Tests\tfa\Unit

Code

public function testIsReady() {

  // Not ready.
  $settings = $this
    ->prophesize(ImmutableConfig::class);
  $settings
    ->get('default_validation_plugin')
    ->willReturn(FALSE);
  $config_factory = $this
    ->prophesize(ConfigFactoryInterface::class);
  $config_factory
    ->get('tfa.settings')
    ->willReturn($settings
    ->reveal());
  $this->configFactory = $config_factory
    ->reveal();
  $fixture = $this
    ->getFixture();
  $this
    ->assertFalse($fixture
    ->isReady());

  // Is ready.
  $settings
    ->get('default_validation_plugin')
    ->willReturn('foo');
  $config_factory = $this
    ->prophesize(ConfigFactoryInterface::class);
  $config_factory
    ->get('tfa.settings')
    ->willReturn($settings
    ->reveal());
  $this->configFactory = $config_factory
    ->reveal();
  $validator = $this
    ->prophesize(TfaValidationInterface::class);
  $validator
    ->ready()
    ->willReturn(TRUE);
  $manager = $this
    ->prophesize(TfaValidationPluginManager::class);
  $manager
    ->createInstance('foo', [
    'uid' => 3,
  ])
    ->willReturn($validator
    ->reveal());
  $this->tfaValidationManager = $manager
    ->reveal();
  $fixture = $this
    ->getFixture();
  $this
    ->assertTrue($fixture
    ->isReady());

  // Plugin set, but not ready.
  $validator = $this
    ->prophesize(TfaValidationInterface::class);
  $validator
    ->ready()
    ->willReturn(FALSE);
  $manager = $this
    ->prophesize(TfaValidationPluginManager::class);
  $manager
    ->createInstance('foo', [
    'uid' => 3,
  ])
    ->willReturn($validator
    ->reveal());
  $this->tfaValidationManager = $manager
    ->reveal();
  $fixture = $this
    ->getFixture();
  $this
    ->assertFalse($fixture
    ->isReady());
}