public function ParagraphsGridLayoutPluginTest::testEmptyGridPlugin

Tests creation of empty grid.

File

paragraphs_collection/tests/src/Functional/ParagraphsGridLayoutPluginTest.php, line 167

Class

ParagraphsGridLayoutPluginTest
Tests the grid layout plugin.

Namespace

Drupal\Tests\paragraphs_collection\Functional

Code

public function testEmptyGridPlugin() {
  $this
    ->addParagraphedContentType('paragraphed_test', 'paragraphs_container');
  $this
    ->loginAsAdmin([
    'create paragraphed_test content',
    'edit any paragraphed_test content',
    'edit behavior plugin settings',
  ]);

  // Set an empty grid layout in a node.
  $this
    ->drupalGet('node/add/paragraphed_test');
  $this
    ->submitForm([], 'paragraphs_container_grid_add_more');
  $edit = [
    'title[0][value]' => 'Grid plugin summary',
    'paragraphs_container[0][behavior_plugins][grid_layout][layout_wrapper][layout]' => 'paragraphs_collection_test_two_column',
  ];
  $this
    ->submitForm($edit, 'Save');

  // Ensure that not selecting layouts will not save any into configuration.
  $this
    ->drupalGet('admin/structure/paragraphs_type/grid');
  $edit = [
    'behavior_plugins[grid_layout][enabled]' => TRUE,
    'behavior_plugins[grid_layout][settings][paragraph_reference_field]' => 'paragraphs_container_paragraphs',
    'behavior_plugins[grid_layout][settings][available_grid_layouts][paragraphs_collection_test_two_column]' => FALSE,
    'behavior_plugins[grid_layout][settings][available_grid_layouts][paragraphs_collection_test_three_column]' => FALSE,
  ];
  $this
    ->submitForm($edit, 'Save');
  $saved_grid_layouts = \Drupal::config('paragraphs.paragraphs_type.grid')
    ->get('behavior_plugins.grid_layout.available_grid_layouts');
  $this
    ->assertEquals($saved_grid_layouts, []);

  // Ensure that only selected grid layouts are saved into configuration.
  $this
    ->drupalGet('admin/structure/paragraphs_type/grid');
  $edit = [
    'behavior_plugins[grid_layout][enabled]' => TRUE,
    'behavior_plugins[grid_layout][settings][paragraph_reference_field]' => 'paragraphs_container_paragraphs',
    'behavior_plugins[grid_layout][settings][available_grid_layouts][paragraphs_collection_test_two_column]' => TRUE,
  ];
  $this
    ->submitForm($edit, 'Save');
  $saved_grid_layouts = \Drupal::config('paragraphs.paragraphs_type.grid')
    ->get('behavior_plugins.grid_layout.available_grid_layouts');
  $this
    ->assertEquals($saved_grid_layouts, [
    'paragraphs_collection_test_two_column',
  ]);
}