function LazyContextRepositoryTest::setupContextAndProvider

Same name and namespace in other branches
  1. 8.9.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. 11.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
@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 128

Class

LazyContextRepositoryTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Plugin%21Context%21LazyContextRepository.php/class/LazyContextRepository/9" title="Provides a context repository which uses context provider services." class="local">\Drupal\Core\Plugin\Context\LazyContextRepository</a> @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;
}

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