You are here

protected function LazyContextRepositoryTest::setupContextAndProvider in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Plugin/Context/LazyContextRepositoryTest.php \Drupal\Tests\Core\Plugin\Context\LazyContextRepositoryTest::setupContextAndProvider()
  2. 9 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.

File

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

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;
}