You are here

protected function OpenIDConnectTest::setUp in OpenID Connect / OAuth client 8

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

Overrides UnitTestCase::setUp

File

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

Class

OpenIDConnectTest
Provides tests for the OpenID Connect module.

Namespace

Drupal\Tests\openid_connect\Unit

Code

protected function setUp() {
  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 authMap open id connect service.
  $this->authMap = $this
    ->createMock(OpenIDConnectAuthmap::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);
  $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->entityTypeManager, $this->entityFieldManager, $this->currentUser, $this->userData, $this->emailValidator, $this->messenger, $this->moduleHandler, $this->logger, $this->fileSystem);
}