You are here

public function BlockContentTest::createEntity in JSON:API 8

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/BlockContentTest.php \Drupal\Tests\jsonapi\Functional\BlockContentTest::createEntity()

Creates the entity to be tested.

Return value

\Drupal\Core\Entity\EntityInterface The entity to be tested.

Overrides ResourceTestBase::createEntity

File

tests/src/Functional/BlockContentTest.php, line 66

Class

BlockContentTest
JSON API integration test for the "BlockContent" content entity type.

Namespace

Drupal\Tests\jsonapi\Functional

Code

public function createEntity() {

  // @todo Remove when JSON API requires Drupal 8.5 or newer.
  // @see https://www.drupal.org/project/drupal/issues/2835845#comment-12265016
  if (floatval(\Drupal::VERSION) < 8.5) {
    return;
  }
  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',
    ],
  ])
    ->setPublished(FALSE);
  $block_content
    ->save();
  return $block_content;
}