protected function BlockResourceTestBase::createEntity in Drupal 8
Same name and namespace in other branches
- 9 core/modules/block/tests/src/Functional/Rest/BlockResourceTestBase.php \Drupal\Tests\block\Functional\Rest\BlockResourceTestBase::createEntity()
Creates the entity to be tested.
Return value
\Drupal\Core\Entity\EntityInterface The entity to be tested.
Overrides EntityResourceTestBase::createEntity
File
- core/
modules/ block/ tests/ src/ Functional/ Rest/ BlockResourceTestBase.php, line 48
Class
Namespace
Drupal\Tests\block\Functional\RestCode
protected function createEntity() {
$block = Block::create([
'plugin' => 'llama_block',
'region' => 'header',
'id' => 'llama',
'theme' => 'classy',
]);
// All blocks can be viewed by the anonymous user by default. An interesting
// side effect of this is that any anonymous user is also able to read the
// corresponding block config entity via REST, even if an authentication
// provider is configured for the block config entity REST resource! In
// other words: Block entities do not distinguish between 'view' as in
// "render on a page" and 'view' as in "read the configuration".
// This prevents that.
// @todo Fix this in https://www.drupal.org/node/2820315.
$block
->setVisibilityConfig('user_role', [
'id' => 'user_role',
'roles' => [
'non-existing-role' => 'non-existing-role',
],
'negate' => FALSE,
'context_mapping' => [
'user' => '@user.current_user_context:current_user',
],
]);
$block
->save();
return $block;
}