public function ContentEntityUpdateParagraphTest::setUp

Install an Article node bundle and a Text paragraph type. Install a translatable text field on the paragraph and an untranslatable entity_reference_revision field on the Article bundle with the text paragraph as its target.

Overrides ContentEntityTestBase::setUp

File

sources/content/tests/src/Kernel/ContentEntityUpdateParagraphTest.php, line 39

Class

ContentEntityUpdateParagraphTest
Content entity update paragraphs test.

Namespace

Drupal\Tests\tmgmt_content\Kernel

Code

public function setUp() : void {
  parent::setUp();
  $this
    ->installSchema('node', [
    'node_access',
  ]);

  // Create article content type.
  NodeType::create([
    'type' => 'article',
    'name' => 'Article',
  ])
    ->save();
  $this
    ->installEntitySchema('paragraph');
  \Drupal::moduleHandler()
    ->loadInclude('paragraphs', 'install');

  // Create a paragraph type.
  $paragraph_type = ParagraphsType::create([
    'label' => 'Text',
    'id' => 'text',
  ]);
  $paragraph_type
    ->save();

  // Add a text field to the paragraph.
  $field_storage = FieldStorageConfig::create([
    'field_name' => 'text',
    'entity_type' => 'paragraph',
    'type' => 'string',
    'cardinality' => '-1',
    'settings' => [],
  ]);
  $field_storage
    ->save();
  $field = FieldConfig::create([
    'field_storage' => $field_storage,
    'bundle' => 'text',
    'translatable' => TRUE,
    'settings' => [
      'handler' => 'default:paragraph',
      'handler_settings' => [
        'target_bundles' => NULL,
      ],
    ],
  ]);
  $field
    ->save();

  // Create the reference to the paragraph test.
  $field_storage = FieldStorageConfig::create([
    'field_name' => 'paragraph_reference',
    'entity_type' => 'node',
    'type' => 'entity_reference_revisions',
    'cardinality' => '-1',
    'settings' => [
      'target_type' => 'paragraph',
    ],
  ]);
  $field_storage
    ->save();
  $field = FieldConfig::create([
    'field_storage' => $field_storage,
    'bundle' => 'article',
    'translatable' => FALSE,
  ]);
  $field
    ->save();
  $content_translation_manager = \Drupal::service('content_translation.manager');
  $content_translation_manager
    ->setEnabled('node', 'article', TRUE);
  $content_translation_manager
    ->setEnabled('paragraph', 'text', TRUE);
}