You are here

public function ParagraphsGridLayoutPluginTest::testEmptyGridPlugin in Paragraphs Collection 8

Tests creation of empty grid.

File

tests/src/Functional/ParagraphsGridLayoutPluginTest.php, line 145

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
    ->drupalPostForm(NULL, [], '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
    ->drupalPostForm(NULL, $edit, 'Save');

  // Ensure that not selecting layouts will not save any into configuration.
  $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
    ->drupalPostForm('admin/structure/paragraphs_type/grid', $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.
  $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
    ->drupalPostForm('admin/structure/paragraphs_type/grid', $edit, 'Save');
  $saved_grid_layouts = \Drupal::config('paragraphs.paragraphs_type.grid')
    ->get('behavior_plugins.grid_layout.available_grid_layouts');
  $this
    ->assertEqual($saved_grid_layouts, [
    'paragraphs_collection_test_two_column',
  ]);
}