You are here

protected function BlockContentResourceTestBase::createEntity in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/block_content/tests/src/Functional/Rest/BlockContentResourceTestBase.php \Drupal\Tests\block_content\Functional\Rest\BlockContentResourceTestBase::createEntity()
  2. 10 core/modules/block_content/tests/src/Functional/Rest/BlockContentResourceTestBase.php \Drupal\Tests\block_content\Functional\Rest\BlockContentResourceTestBase::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_content/tests/src/Functional/Rest/BlockContentResourceTestBase.php, line 47

Class

BlockContentResourceTestBase
ResourceTestBase for BlockContent entity.

Namespace

Drupal\Tests\block_content\Functional\Rest

Code

protected function createEntity() {
  if (!BlockContentType::load('basic')) {
    $block_content_type = BlockContentType::create([
      'id' => 'basic',
      'label' => 'basic',
      'revision' => TRUE,
    ]);
    $block_content_type
      ->save();
    block_content_add_body_field($block_content_type
      ->id());
  }

  // Create a "Llama" custom block.
  $block_content = BlockContent::create([
    'info' => 'Llama',
    'type' => 'basic',
    'body' => [
      'value' => 'The name "llama" was adopted by European settlers from native Peruvians.',
      'format' => 'plain_text',
    ],
  ])
    ->setUnpublished();
  $block_content
    ->save();
  return $block_content;
}