You are here

protected function EditorFileUsageTest::setUp in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/editor/tests/src/Kernel/EditorFileUsageTest.php \Drupal\Tests\editor\Kernel\EditorFileUsageTest::setUp()
  2. 10 core/modules/editor/tests/src/Kernel/EditorFileUsageTest.php \Drupal\Tests\editor\Kernel\EditorFileUsageTest::setUp()

Overrides EntityKernelTestBase::setUp

File

core/modules/editor/tests/src/Kernel/EditorFileUsageTest.php, line 29

Class

EditorFileUsageTest
Tests tracking of file usage by the Text Editor module.

Namespace

Drupal\Tests\editor\Kernel

Code

protected function setUp() : void {
  parent::setUp();
  $this
    ->installEntitySchema('file');
  $this
    ->installSchema('node', [
    'node_access',
  ]);
  $this
    ->installSchema('file', [
    'file_usage',
  ]);
  $this
    ->installConfig([
    'node',
  ]);

  // Add text formats.
  $filtered_html_format = FilterFormat::create([
    'format' => 'filtered_html',
    'name' => 'Filtered HTML',
    'weight' => 0,
    'filters' => [],
  ]);
  $filtered_html_format
    ->save();

  // Set cardinality for body field.
  FieldStorageConfig::loadByName('node', 'body')
    ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
    ->save();

  // Set up text editor.
  $editor = Editor::create([
    'format' => 'filtered_html',
    'editor' => 'unicorn',
  ]);
  $editor
    ->save();

  // Create a node type for testing.
  $type = NodeType::create([
    'type' => 'page',
    'name' => 'page',
  ]);
  $type
    ->save();
  node_add_body_field($type);
  FieldStorageConfig::create([
    'field_name' => 'description',
    'entity_type' => 'node',
    'type' => 'editor_test_text_long',
    'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
  ])
    ->save();
  FieldConfig::create([
    'field_name' => 'description',
    'entity_type' => 'node',
    'bundle' => 'page',
    'label' => 'Description',
  ])
    ->save();
}