You are here

protected function LazyContextRepositoryTest::setupContextAndProvider in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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
@covers ::getAvailableContexts
LazyContextRepositoryTest::testGetRuntimeContextsSingle in core/tests/Drupal/Tests/Core/Plugin/Context/LazyContextRepositoryTest.php
@covers ::getRuntimeContexts
LazyContextRepositoryTest::testGetRuntimeMultipleContextProviders in core/tests/Drupal/Tests/Core/Plugin/Context/LazyContextRepositoryTest.php
@covers ::getRuntimeContexts
LazyContextRepositoryTest::testGetRuntimeMultipleContextsPerService in core/tests/Drupal/Tests/Core/Plugin/Context/LazyContextRepositoryTest.php
@covers ::getRuntimeContexts

File

core/tests/Drupal/Tests/Core/Plugin/Context/LazyContextRepositoryTest.php, line 133
Contains \Drupal\Tests\Core\Plugin\Context\LazyContextRepositoryTest.

Class

LazyContextRepositoryTest
@coversDefaultClass \Drupal\Core\Plugin\Context\LazyContextRepository @group context

Namespace

Drupal\Tests\Core\Plugin\Context

Code

protected function setupContextAndProvider($service_id, array $unqualified_context_ids, array $expected_unqualified_context_ids = []) {
  $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;
}