You are here

protected function OpenIDConnectTest::setUp in OpenID Connect / OAuth client 2.x

Same name and namespace in other branches
  1. 8 tests/src/Unit/OpenIDConnectTest.php \Drupal\Tests\openid_connect\Unit\OpenIDConnectTest::setUp()

Overrides UnitTestCase::setUp

File

tests/src/Unit/OpenIDConnectTest.php, line 159

Class

OpenIDConnectTest
Provides tests for the OpenID Connect module.

Namespace

Drupal\Tests\openid_connect\Unit

Code

protected function setUp() : void {
  parent::setUp();
  $oldFileMock = $this
    ->createMock(File::class);
  $oldFileMock
    ->expects($this
    ->any())
    ->method('id')
    ->willReturn(123);

  // Add this mock to the globals for the file_save_data fixture.
  $GLOBALS['oldFileMock'] = $oldFileMock;
  require_once 'UserPasswordFixture.php';

  // Mock the config_factory service.
  $this->configFactory = $this
    ->createMock(ConfigFactoryInterface::class);

  // Mock the external authMap service.
  $this->authmap = $this
    ->createMock(AuthmapInterface::class);

  // Mock the externalAuth connect service.
  $this->externalAuth = $this
    ->createMock(ExternalAuthInterface::class);
  $this->userStorage = $this
    ->createMock(EntityStorageInterface::class);

  // Mock the entity type manager service.
  $this->entityTypeManager = $this
    ->createMock(EntityTypeManagerInterface::class);
  $this->entityTypeManager
    ->expects($this
    ->atLeastOnce())
    ->method('getStorage')
    ->with('user')
    ->willReturn($this->userStorage);
  $this->entityFieldManager = $this
    ->createMock(EntityFieldManagerInterface::class);
  $this->currentUser = $this
    ->createMock(AccountProxyInterface::class);
  $this->userData = $this
    ->createMock(UserDataInterface::class);
  $emailValidator = $this
    ->getMockBuilder('\\Drupal\\Component\\Utility\\EmailValidator')
    ->setMethods(NULL);
  $this->emailValidator = $emailValidator
    ->getMock();
  $this->messenger = $this
    ->createMock(MessengerInterface::class);
  $this->moduleHandler = $this
    ->createMock(ModuleHandler::class);
  $this->logger = $this
    ->createMock(LoggerChannelFactoryInterface::class);
  $this->oidcLogger = $this
    ->createMock(LoggerChannelInterface::class);
  $this->logger
    ->expects($this
    ->atLeastOnce())
    ->method('get')
    ->with('openid_connect')
    ->willReturn($this->oidcLogger);
  $this->fileSystem = $this
    ->createMock(FileSystemInterface::class);
  $this->session = $this
    ->createMock(OpenIDConnectSessionInterface::class);
  $container = new ContainerBuilder();
  $container
    ->set('string_translation', $this
    ->getStringTranslationStub());
  $container
    ->set('entity_type.repository', $this
    ->createMock(EntityTypeRepositoryInterface::class));
  $container
    ->set('entity_type.manager', $this
    ->createMock(EntityTypeManagerInterface::class));
  \Drupal::setContainer($container);
  $this->openIdConnect = new OpenIDConnect($this->configFactory, $this->authmap, $this->externalAuth, $this->entityTypeManager, $this->entityFieldManager, $this->currentUser, $this->userData, $this->emailValidator, $this->messenger, $this->moduleHandler, $this->logger, $this->fileSystem, $this->session);
}