You are here

protected function ParagraphsTranslationTest::setUp in Paragraphs 8

Same name in this branch
  1. 8 tests/src/Functional/WidgetLegacy/ParagraphsTranslationTest.php \Drupal\Tests\paragraphs\Functional\WidgetLegacy\ParagraphsTranslationTest::setUp()
  2. 8 tests/src/Functional/WidgetStable/ParagraphsTranslationTest.php \Drupal\Tests\paragraphs\Functional\WidgetStable\ParagraphsTranslationTest::setUp()

Overrides ParagraphsTestBase::setUp

File

tests/src/Functional/WidgetLegacy/ParagraphsTranslationTest.php, line 46

Class

ParagraphsTranslationTest
Tests the configuration of paragraphs.

Namespace

Drupal\Tests\paragraphs\Functional\WidgetLegacy

Code

protected function setUp() : void {
  parent::setUp();
  ConfigurableLanguage::create([
    'id' => 'de',
    'label' => '1German',
  ])
    ->save();
  ConfigurableLanguage::create([
    'id' => 'fr',
    'label' => '2French',
  ])
    ->save();
  $this
    ->addParagraphedContentType('paragraphed_content_demo', 'field_paragraphs_demo');
  $this
    ->loginAsAdmin([
    'administer site configuration',
    'create paragraphed_content_demo content',
    'edit any paragraphed_content_demo content',
    'delete any paragraphed_content_demo content',
    'administer content translation',
    'translate any entity',
    'create content translations',
    'administer languages',
  ]);
  $this
    ->addParagraphsType('nested_paragraph');
  $this
    ->addParagraphsField('nested_paragraph', 'field_paragraphs_demo', 'paragraph');
  $this
    ->addParagraphsType('images');
  static::fieldUIAddNewField('admin/structure/paragraphs_type/images', 'images_demo', 'Images', 'image', [
    'cardinality' => -1,
  ], [
    'settings[alt_field]' => FALSE,
  ]);
  $this
    ->addParagraphsType('text_image');
  static::fieldUIAddNewField('admin/structure/paragraphs_type/text_image', 'image_demo', 'Images', 'image', [
    'cardinality' => -1,
  ], [
    'settings[alt_field]' => FALSE,
  ]);
  static::fieldUIAddNewField('admin/structure/paragraphs_type/text_image', 'text_demo', 'Text', 'text_long', [], []);
  $this
    ->addParagraphsType('text');
  static::fieldUIAddExistingField('admin/structure/paragraphs_type/text', 'field_text_demo', 'Text', []);
  $edit = [
    'entity_types[node]' => TRUE,
    'entity_types[paragraph]' => TRUE,
    'settings[node][paragraphed_content_demo][translatable]' => TRUE,
    'settings[node][paragraphed_content_demo][fields][field_paragraphs_demo]' => FALSE,
    'settings[paragraph][images][translatable]' => TRUE,
    'settings[paragraph][text_image][translatable]' => TRUE,
    'settings[paragraph][text][translatable]' => TRUE,
    'settings[paragraph][nested_paragraph][translatable]' => TRUE,
    'settings[paragraph][nested_paragraph][fields][field_paragraphs_demo]' => FALSE,
    'settings[paragraph][nested_paragraph][settings][language][language_alterable]' => TRUE,
    'settings[paragraph][images][fields][field_images_demo]' => TRUE,
    'settings[paragraph][text_image][fields][field_image_demo]' => TRUE,
    'settings[paragraph][text_image][fields][field_text_demo]' => TRUE,
    'settings[node][paragraphed_content_demo][settings][language][language_alterable]' => TRUE,
  ];
  $this
    ->drupalGet('admin/config/regional/content-language');
  $this
    ->submitForm($edit, 'Save configuration');

  // Set the form display to legacy.
  EntityFormDisplay::load('node.paragraphed_content_demo.default')
    ->setComponent('field_paragraphs_demo', [
    'type' => 'entity_reference_paragraphs',
  ])
    ->save();
  EntityFormDisplay::load('paragraph.nested_paragraph.default')
    ->setComponent('field_paragraphs_demo', [
    'type' => 'entity_reference_paragraphs',
  ])
    ->save();
  if (version_compare(\Drupal::VERSION, '8.4', '>=')) {

    // @todo Workaround for file usage/unable to save the node with no usages.
    //   Remove when https://www.drupal.org/node/2801777 is fixed.
    \Drupal::configFactory()
      ->getEditable('file.settings')
      ->set('make_unused_managed_files_temporary', TRUE)
      ->save();
  }
}