You are here

public function PathContextTest::testPopulateCache 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::testPopulateCache()

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

@covers ::populate

@dataProvider providerTestPopulateCache

Parameters

integer $expect_set_cache:

array $identity_settings:

array $expect_cache_context:

File

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

Class

PathContextTest
PathContextTest Test.

Namespace

Drupal\Tests\acquia_lift\Unit\Service\Context

Code

public function testPopulateCache($identity_settings, $expect_set_cache, $expect_cache_context) {
  $this->requestStack
    ->expects($this
    ->exactly($expect_set_cache))
    ->method('getCurrentRequest')
    ->willReturn($this->request);
  $this->request
    ->expects($this
    ->exactly($expect_set_cache))
    ->method('getQueryString')
    ->willReturn('querystring');
  $this->settings
    ->expects($this
    ->at(0))
    ->method('get')
    ->with('credential')
    ->willReturn([]);
  $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);
  $page = [];
  $path_context
    ->populate($page);
  $cache_context = [];
  if (isset($page['#cache']['contexts'])) {
    $cache_context = $page['#cache']['contexts'];
  }
  $this
    ->assertEquals($expect_cache_context, $cache_context);
}