function LazyContextRepositoryTest::setupContextAndProvider

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/Tests/Core/Plugin/Context/LazyContextRepositoryTest.php \Drupal\Tests\Core\Plugin\Context\LazyContextRepositoryTest::setupContextAndProvider()
  2. 10 core/tests/Drupal/Tests/Core/Plugin/Context/LazyContextRepositoryTest.php \Drupal\Tests\Core\Plugin\Context\LazyContextRepositoryTest::setupContextAndProvider()
  3. 9 core/tests/Drupal/Tests/Core/Plugin/Context/LazyContextRepositoryTest.php \Drupal\Tests\Core\Plugin\Context\LazyContextRepositoryTest::setupContextAndProvider()
  4. 8.9.x core/tests/Drupal/Tests/Core/Plugin/Context/LazyContextRepositoryTest.php \Drupal\Tests\Core\Plugin\Context\LazyContextRepositoryTest::setupContextAndProvider()

Sets up contexts and context providers.

Parameters

string $service_id: The service ID of the service provider.

string[] $unqualified_context_ids: An array of context slot names.

string[] $expected_unqualified_context_ids: The expected unqualified context IDs passed to getRuntimeContexts.

Return value

array An array of set up contexts.

4 calls to LazyContextRepositoryTest::setupContextAndProvider()
LazyContextRepositoryTest::testGetAvailableContexts in core/tests/Drupal/Tests/Core/Plugin/Context/LazyContextRepositoryTest.php
Tests get available contexts.
LazyContextRepositoryTest::testGetRuntimeContextsSingle in core/tests/Drupal/Tests/Core/Plugin/Context/LazyContextRepositoryTest.php
Tests get runtime contexts single.
LazyContextRepositoryTest::testGetRuntimeMultipleContextProviders in core/tests/Drupal/Tests/Core/Plugin/Context/LazyContextRepositoryTest.php
Tests get runtime multiple context providers.
LazyContextRepositoryTest::testGetRuntimeMultipleContextsPerService in core/tests/Drupal/Tests/Core/Plugin/Context/LazyContextRepositoryTest.php
Tests get runtime multiple contexts per service.

File

core/tests/Drupal/Tests/Core/Plugin/Context/LazyContextRepositoryTest.php, line 150

Class

LazyContextRepositoryTest
Tests Drupal\Core\Plugin\Context\LazyContextRepository.

Namespace

Drupal\Tests\Core\Plugin\Context

Code

protected function setupContextAndProvider($service_id, array $unqualified_context_ids, array $expected_unqualified_context_ids = []) : array {
  $contexts = [];
  for ($i = 0; $i < count($unqualified_context_ids); $i++) {
    $contexts[] = new Context(new ContextDefinition('example'));
  }
  $expected_unqualified_context_ids = $expected_unqualified_context_ids ?: $unqualified_context_ids;
  $context_provider = $this->prophesize('\\Drupal\\Core\\Plugin\\Context\\ContextProviderInterface');
  $context_provider->getRuntimeContexts($expected_unqualified_context_ids)
    ->willReturn(array_combine($unqualified_context_ids, $contexts));
  $context_provider->getAvailableContexts()
    ->willReturn(array_combine($unqualified_context_ids, $contexts));
  $context_provider = $context_provider->reveal();
  $this->container
    ->set($service_id, $context_provider);
  return $contexts;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.