function EntityCreateAccessCustomCidTest::testCustomCid

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/Tests/Core/Entity/Access/EntityCreateAccessCustomCidTest.php \Drupal\Tests\Core\Entity\Access\EntityCreateAccessCustomCidTest::testCustomCid()

Tests the entity access control handler with a custom static cache ID.

@legacy-covers ::buildCreateAccessCid

Attributes

#[DataProvider('providerTestCustomCid')]

Parameters

string $bundle: The machine name of the entity bundle.

array $context: The context array.

string $cid: The static cache ID.

bool $in_cache: Whether there is already a cached createAccess() check for the cache ID.

File

core/tests/Drupal/Tests/Core/Entity/Access/EntityCreateAccessCustomCidTest.php, line 219

Class

EntityCreateAccessCustomCidTest
Tests entity access control handler custom internal cache ID.

Namespace

Drupal\Tests\Core\Entity\Access

Code

public function testCustomCid(string $bundle, array $context, string $cid, bool $in_cache) : void {
  $context['langcode'] = $this->langcode;
  // Drupal\Core\Cache is used when merging access results in
  // checkCreateAccess(), and it calls the cache context manager service.
  $cache_context_manager = $this->createMock(CacheContextsManager::class);
  $cache_context_manager->expects($this->any())
    ->method('assertValidTokens')
    ->willReturn(TRUE);
  $container = new ContainerBuilder();
  \Drupal::setContainer($container);
  $container->set('cache_contexts_manager', $cache_context_manager);
  $handler = new EntityTestAccessControlHandler($this->entityType);
  $handler->setModuleHandler($this->moduleHandler);
  $this->setUpAccessCache($handler, $in_cache, $cid);
  // The prefilled cache is set to AccessResult::allowed(), but the default
  // for EntityTestAccessControlHandler() is neutral(); so createAccess() will
  // return TRUE for a cache hit and FALSE otherwise.
  $this->assertSame($in_cache, $handler->createAccess($bundle, $this->account, $context));
}

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