You are here

protected function AccessTest::setUp in Search API Autocomplete 8

Overrides UnitTestCase::setUp

File

tests/src/Unit/AccessTest.php, line 42

Class

AccessTest
Tests access to the autocomplete path.

Namespace

Drupal\Tests\search_api_autocomplete\Unit

Code

protected function setUp() {
  parent::setUp();
  $element_info = $this
    ->createMock(ElementInfoManagerInterface::class);
  $this->autocompleteHelper = new AutocompleteHelper($element_info);
  $this->search = $this
    ->createMock(SearchInterface::class);
  $this->search
    ->method('id')
    ->willReturn('test');
  $this->search
    ->method('getCacheContexts')
    ->willReturn([
    'test',
  ]);
  $this->search
    ->method('getCacheTags')
    ->willReturn([
    'test',
  ]);
  $this->search
    ->method('getCacheMaxAge')
    ->willReturn(1337);

  // \Drupal\Core\Access\AccessResult::addCacheContexts() will need the cache
  // contexts manager service for validation.
  $container = new ContainerBuilder();
  $contexts = [
    'test',
    'user.permissions',
  ];
  $cacheContextsManager = new CacheContextsManager($container, $contexts);
  $container
    ->set('cache_contexts_manager', $cacheContextsManager);
  \Drupal::setContainer($container);
}