View source
<?php
namespace Drupal\Tests\paragraphs_collection\Functional;
use Drupal\Tests\paragraphs\Functional\WidgetStable\ParagraphsTestBase;
class ParagraphsGridLayoutPluginTest extends ParagraphsTestBase {
public static $modules = [
'paragraphs_collection',
'paragraphs_collection_test',
];
public function testGridLayoutPlugin() {
$this
->loginAsAdmin([
'edit behavior plugin settings',
]);
$this
->drupalGet('admin/structure/paragraphs_type/add');
$this
->assertText('Grid layout');
$this
->drupalGet('admin/structure/paragraphs_type/grid');
$this
->assertFieldChecked('edit-behavior-plugins-grid-layout-enabled');
$this
->assertText('Grid field');
$this
->assertOptionSelected('edit-behavior-plugins-grid-layout-settings-paragraph-reference-field', 'paragraphs_container_paragraphs');
$this
->assertText('Grid layouts');
$this
->assertText('Two columns');
static::fieldUIAddNewField('admin/structure/paragraphs_type/grid', 'user_reference', 'User', 'entity_reference', [
'settings[target_type]' => 'user',
], []);
$this
->drupalGet('admin/structure/paragraphs_type/grid');
$this
->assertNoOption('edit-behavior-plugins-grid-layout-settings-paragraph-reference-field', 'field_user_reference');
$this
->drupalGet('admin/structure/paragraphs_type/grid/fields/paragraph.grid.field_user_reference/storage');
$edit = [
'cardinality' => '-1',
];
$this
->drupalPostForm(NULL, $edit, t('Save field settings'));
$this
->drupalGet('admin/structure/paragraphs_type/grid');
$this
->assertOption('edit-behavior-plugins-grid-layout-settings-paragraph-reference-field', 'field_user_reference');
$this
->drupalPostForm('admin/structure/paragraphs_type/grid/fields/paragraph.grid.field_user_reference/delete', [], t('Delete'));
$this
->assertText('The field User has been deleted from the Grid content type.');
$this
->addParagraphedContentType('paragraphed_test', 'paragraphs_container');
$this
->drupalGet('node/add/paragraphed_test');
$this
->drupalPostForm(NULL, [], 'paragraphs_container_grid_add_more');
$options = $this
->xpath('//select[contains(@id, :id)]/option', [
':id' => 'edit-paragraphs-container-0-behavior-plugins-grid-layout-layout',
]);
$this
->assertEquals('- None -', $options[0]
->getText());
$this
->assertEquals('Three columns', $options[1]
->getText());
$this
->assertEquals('Two columns', $options[2]
->getText());
$this
->drupalPostForm(NULL, [], 'paragraphs_container_0_subform_paragraphs_container_paragraphs_container_add_more');
$this
->drupalPostForm(NULL, [], 'paragraphs_container_0_subform_paragraphs_container_paragraphs_container_add_more');
$this
->drupalPostForm(NULL, [], 'paragraphs_container_0_subform_paragraphs_container_paragraphs_container_add_more');
$edit = [
'title[0][value]' => 'Grid',
'paragraphs_container[0][behavior_plugins][grid_layout][layout_wrapper][layout]' => 'paragraphs_collection_test_two_column',
];
$this
->drupalPostForm(NULL, $edit, 'Save');
$this
->assertText('paragraphed_test Grid has been created.');
$this
->assertRaw('paragraphs_collection_test/css/grid-layout.css');
$this
->drupalGet('node/1');
$grid_columns[] = '//div[contains(@class, "paragraphs-behavior-grid-layout-row")]/div[1][contains(@class, "paragraphs-behavior-grid-layout-col-8")]';
$grid_columns[] = '//div[contains(@class, "paragraphs-behavior-grid-layout-row")]/div[2][contains(@class, "paragraphs-behavior-grid-layout-col-4")]';
$grid_columns[] = '//div[contains(@class, "paragraphs-behavior-grid-layout-row")]/div[3][contains(@class, "paragraphs-behavior-grid-layout-col-8")]';
foreach ($grid_columns as $key => $column) {
$this
->assertFieldByXPath($column, NULL, "Grid structure found for column {$key}");
}
$this
->drupalPostForm('admin/structure/paragraphs_type/grid/fields/paragraph.grid.paragraphs_container_paragraphs/delete', [], t('Delete'));
$this
->assertText('The field Paragraphs has been deleted from the Grid content type.');
$node = $this
->getNodeByTitle('Grid');
$this
->drupalGet('node/' . $node
->id());
$this
->assertResponse(200);
$this
->drupalGet('admin/structure/paragraphs_type/grid');
$this
->assertResponse(200);
$this
->assertText('No paragraph reference field type available. Please add at least one in the Manage fields page.');
$this
->drupalPostForm(NULL, [
'behavior_plugins[grid_layout][enabled]' => TRUE,
], t('Save'));
$this
->assertText('The grid layout plugin cannot be enabled if the paragraph reference field is missing.');
}
public function testGridSettingsSummary() {
$this
->addParagraphedContentType('paragraphed_test', 'paragraphs_container');
$this
->loginAsAdmin([
'create paragraphed_test content',
'edit any paragraphed_test content',
'edit behavior plugin settings',
]);
$paragraph_type = 'text_paragraph';
$this
->addParagraphsType($paragraph_type);
$this
->fieldUIAddExistingField('admin/structure/paragraphs_type/' . $paragraph_type, 'paragraphs_text');
$this
->setParagraphsWidgetMode('paragraphed_test', 'paragraphs_container', 'closed');
$this
->drupalGet('node/add/paragraphed_test');
$this
->drupalPostForm(NULL, [], 'paragraphs_container_grid_add_more');
$this
->drupalPostForm(NULL, [], 'paragraphs_container_0_subform_paragraphs_container_paragraphs_text_paragraph_add_more');
$this
->drupalPostForm(NULL, [], 'paragraphs_container_0_subform_paragraphs_container_paragraphs_text_paragraph_add_more');
$this
->drupalPostForm(NULL, [], 'paragraphs_container_0_subform_paragraphs_container_paragraphs_text_paragraph_add_more');
$edit = [
'title[0][value]' => 'Grid plugin summary',
'paragraphs_container[0][subform][paragraphs_container_paragraphs][0][subform][paragraphs_text][0][value]' => 'Text 1',
'paragraphs_container[0][subform][paragraphs_container_paragraphs][1][subform][paragraphs_text][0][value]' => 'Text 2',
'paragraphs_container[0][subform][paragraphs_container_paragraphs][2][subform][paragraphs_text][0][value]' => 'Text 3',
'paragraphs_container[0][behavior_plugins][grid_layout][layout_wrapper][layout]' => 'paragraphs_collection_test_two_column',
];
$this
->drupalPostForm(NULL, $edit, 'Save');
$this
->assertText('paragraphed_test Grid plugin summary has been created.');
$this
->clickLink('Edit');
$this
->assertRaw('<span class="summary-content">Text 1</span>, <span class="summary-content">Text 2</span>, <span class="summary-content">Text 3</span></div><div class="paragraphs-plugin-wrapper"><span class="summary-plugin"><span class="summary-plugin-label">Layout</span>Two columns');
$this
->assertFieldByXPath('//*[@id="edit-paragraphs-container-0-top-icons"]/span[@class="paragraphs-badge" and @title="3 children"]');
}
public function testEmptyGridPlugin() {
$this
->addParagraphedContentType('paragraphed_test', 'paragraphs_container');
$this
->loginAsAdmin([
'create paragraphed_test content',
'edit any paragraphed_test content',
'edit behavior plugin settings',
]);
$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');
$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, []);
$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',
]);
}
}