You are here

public function PathContextTest::testPopulateHtmlHeadIdentities in Acquia Lift Connector 8.4

Same name and namespace in other branches
  1. 8.3 tests/src/Unit/Service/Context/PathContextTest.php \Drupal\Tests\acquia_lift\Unit\Service\Context\PathContextTest::testPopulateHtmlHeadIdentities()

Tests the populate() method, populateHtmlHead() sub method, "set identity and identity type" sub routine.

@covers ::setContextIdentityByUser @covers ::populate

@dataProvider providerTestPopulateHtmlHeadIdentities

Parameters

string $query_parameter_string:

boolean $capture_identity:

boolean $do_set_user:

array $expect_cache:

array $expect_html_head:

File

tests/src/Unit/Service/Context/PathContextTest.php, line 170

Class

PathContextTest
PathContextTest Test.

Namespace

Drupal\Tests\acquia_lift\Unit\Service\Context

Code

public function testPopulateHtmlHeadIdentities($query_parameter_string, $capture_identity, $do_set_user, $expect_cache, $expect_html_head) {
  $this->requestStack
    ->expects($this
    ->once())
    ->method('getCurrentRequest')
    ->willReturn($this->request);
  $this->request
    ->expects($this
    ->once())
    ->method('getQueryString')
    ->willReturn($query_parameter_string);
  $credential_settings = $this
    ->getValidCredentialSettings();
  $identity_settings = $this
    ->getValidIdentitySettings();
  $identity_settings['capture_identity'] = $capture_identity;
  $this->settings
    ->expects($this
    ->at(0))
    ->method('get')
    ->with('credential')
    ->willReturn($credential_settings);
  $this->settings
    ->expects($this
    ->at(1))
    ->method('get')
    ->with('identity')
    ->willReturn($identity_settings);
  $path_context = new PathContext($this->configFactory, $this->currentPathStack, $this->requestStack, $this->pathMatcher);
  if ($do_set_user) {
    $user = $this
      ->createMock('Drupal\\user\\UserInterface');
    $user
      ->expects($this
      ->exactly((int) $capture_identity))
      ->method('getEmail')
      ->willReturn('a_user_email');
    $path_context
      ->setContextIdentityByUser($user);
  }
  $page = [];
  $path_context
    ->populate($page);
  $this
    ->assertEquals($expect_cache, $page['#cache']['contexts']);
  $this
    ->assertEquals($expect_html_head, $page['#attached']['html_head']);
}