You are here

public function RequestSubscriberTest::testRequestSubscriberAuthenticatedWithoutContact in CRM Core 8

Same name and namespace in other branches
  1. 8.3 modules/crm_core_user_sync/tests/src/Unit/RequestSubscriberTest.php \Drupal\Tests\crm_core_user_sync\Unit\RequestSubscriberTest::testRequestSubscriberAuthenticatedWithoutContact()

Tests nothing loaded for user without related contact.

File

modules/crm_core_user_sync/tests/src/Unit/RequestSubscriberTest.php, line 60

Class

RequestSubscriberTest
Test description.

Namespace

Drupal\Tests\crm_core_user_sync\Unit

Code

public function testRequestSubscriberAuthenticatedWithoutContact() {
  $current_user = $this
    ->createMock(AccountProxyInterface::class);
  $current_user
    ->expects($this
    ->once())
    ->method('isAuthenticated')
    ->willReturn(TRUE);
  $current_user
    ->expects($this
    ->once())
    ->method('id')
    ->willReturn('101');
  $config = $this
    ->getMockBuilder(ImmutableConfig::class)
    ->disableOriginalConstructor()
    ->getMock();
  $config
    ->expects($this
    ->once())
    ->method('get')
    ->with('contact_load')
    ->willReturn(TRUE);
  $config_name = 'crm_core_user_sync.settings';
  $configFactory = $this
    ->createMock(ConfigFactoryInterface::class);
  $configFactory
    ->expects($this
    ->once())
    ->method('get')
    ->with($config_name)
    ->willReturn($config);
  $relationService = $this
    ->createMock(CrmCoreUserSyncRelationInterface::class);
  $relationService
    ->expects($this
    ->once())
    ->method('getUserIndividualId')
    ->willReturn(FALSE);
  $entityTypeManager = $this
    ->createMock(EntityTypeManagerInterface::class);
  $entityTypeManager
    ->expects($this
    ->never())
    ->method('getStorage');
  $kernel = $this
    ->prophesize(HttpKernelInterface::class);
  $request = Request::create('/', 'GET');
  $subscriber = new RequestSubscriber($current_user, $configFactory, $relationService, $entityTypeManager);
  $event = new GetResponseEvent($kernel
    ->reveal(), $request, HttpKernelInterface::MASTER_REQUEST);
  $subscriber
    ->onKernelRequest($event);

  // Nothing to assert. Entity type manager expectations will the test.
}