You are here

protected function ParagraphsTypePermissionsTest::setUp in Paragraphs 8

Overrides BrowserTestBase::setUp

File

modules/paragraphs_type_permissions/tests/src/Functional/ParagraphsTypePermissionsTest.php, line 43

Class

ParagraphsTypePermissionsTest
Tests the paragraphs type permissions.

Namespace

Drupal\Tests\paragraphs_type_permissions\Functional

Code

protected function setUp() : void {
  parent::setUp();
  $this
    ->drupalPlaceBlock('system_breadcrumb_block');
  ConfigurableLanguage::create([
    'id' => 'de',
    'label' => '1German',
  ])
    ->save();
  ConfigurableLanguage::create([
    'id' => 'fr',
    'label' => '2French',
  ])
    ->save();
  $this
    ->addParagraphedContentType('paragraphed_content_demo', 'field_paragraphs_demo');
  $admin_user = $this
    ->drupalCreateUser(array(
    'administer site configuration',
    'administer content translation',
    'administer languages',
    'administer node fields',
    'administer content types',
    'administer paragraphs types',
    'administer node form display',
    'administer paragraph fields',
    'administer paragraph form display',
  ));
  $this
    ->drupalLogin($admin_user);
  $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', [], [
    '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');
  $display_options = [
    'type' => 'image',
    'settings' => [
      'image_style' => 'medium',
      'image_link' => 'file',
    ],
  ];

  /** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */
  $display_repository = \Drupal::service('entity_display.repository');
  $display = $display_repository
    ->getViewDisplay('paragraph', 'images');
  $display
    ->setComponent('field_images_demo', $display_options)
    ->save();
  $display_options = [
    'type' => 'image',
    'settings' => [
      'image_style' => 'large',
      'image_link' => 'file',
    ],
  ];
  $display = $display_repository
    ->getViewDisplay('paragraph', 'text_image');
  $display
    ->setComponent('field_image_demo', $display_options)
    ->save();
}