<?php
namespace Drupal\Tests\paragraphs\Functional\WidgetStable;
use Drupal\language\Entity\ConfigurableLanguage;
use Symfony\Component\CssSelector\CssSelectorConverter;
class ParagraphsHeaderActionsTest extends ParagraphsTestBase {
protected static $modules = array(
'content_translation',
);
public function testHeaderActions() {
\Drupal::state()
->set('paragraphs_test_dragdrop_force_show', TRUE);
$this
->addParagraphedContentType('paragraphed_test');
$this
->loginAsAdmin([
'create paragraphed_test content',
'edit any paragraphed_test content',
]);
$paragraph_type = 'text_paragraph';
$this
->addParagraphsType($paragraph_type);
static::fieldUIAddNewField('admin/structure/paragraphs_type/' . $paragraph_type, 'text', 'Text', 'text_long', [], []);
$this
->drupalGet('node/add/paragraphed_test');
$this
->assertSession()
->responseNotContains('field_paragraphs_collapse_all');
$this
->assertSession()
->responseNotContains('field_paragraphs_edit_all');
$this
->assertSession()
->responseContains('field_paragraphs_dragdrop_mode');
$table_rows = $this
->xpath('//table[contains(@class, :class)]/tbody/tr', [
':class' => 'field-multiple-table',
]);
$this
->assertEquals(1, count($table_rows));
$this
->submitForm([], 'field_paragraphs_text_paragraph_add_more');
$this
->assertSession()
->responseContains('field_paragraphs_collapse_all');
$this
->assertSession()
->responseContains('field_paragraphs_edit_all');
$edit = [
'field_paragraphs[0][subform][field_text][0][value]' => 'First text',
'field_paragraphs[1][subform][field_text][0][value]' => 'Second text',
];
$this
->submitForm($edit, 'Collapse all');
$this
->assertSession()
->responseContains('field_paragraphs_0_edit');
$this
->assertSession()
->responseContains('field_paragraphs_1_edit');
$this
->submitForm([], 'field_paragraphs_edit_all');
$this
->assertSession()
->responseContains('field_paragraphs_0_collapse');
$this
->assertSession()
->responseContains('field_paragraphs_1_collapse');
$edit = [
'title[0][value]' => 'Test',
];
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('paragraphed_test Test has been created.');
$node = $this
->getNodeByTitle('Test');
$this
->drupalGet('node/' . $node
->id());
$this
->clickLink('Edit');
$this
->assertSession()
->pageTextNotContains('No Paragraph added yet.');
$this
->submitForm([], 'field_paragraphs_text_paragraph_add_more');
$edit = [
'field_paragraphs[2][subform][field_text][0][value]' => 'Third text',
];
$this
->submitForm($edit, 'field_paragraphs_2_remove');
$this
->submitForm([], 'field_paragraphs_edit_all');
$this
->assertSession()
->pageTextContains('First text');
$this
->assertSession()
->pageTextContains('Second text');
$this
->assertSession()
->pageTextNotContains('Third text');
$this
->submitForm([], 'field_paragraphs_collapse_all');
$this
->assertSession()
->pageTextContains('First text');
$this
->assertSession()
->pageTextContains('Second text');
$this
->assertSession()
->pageTextNotContains('Third text');
$this
->assertSession()
->buttonExists('field_paragraphs_collapse_all');
$this
->assertSession()
->buttonExists('field_paragraphs_edit_all');
$this
->submitForm([], 'Save');
$this
->drupalGet('node/add/paragraphed_test');
$this
->assertSession()
->responseContains('name="field_paragraphs_dragdrop_mode"');
$this
->submitForm([], 'field_paragraphs_0_remove');
$this
->assertSession()
->responseNotContains('name="field_paragraphs_dragdrop_mode"');
$this
->drupalGet('admin/structure/types/manage/paragraphed_test/form-display');
$this
->submitForm([], 'field_paragraphs_settings_edit');
$this
->submitForm([
'fields[field_paragraphs][settings_edit_form][settings][features][collapse_edit_all]' => FALSE,
], 'Update');
$this
->submitForm([], 'Save');
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->assertSession()
->buttonNotExists('field_paragraphs_collapse_all');
$this
->assertSession()
->buttonNotExists('field_paragraphs_edit_all');
$this
->assertSession()
->fieldValueEquals('field_paragraphs[0][subform][field_text][0][value]', 'First text');
$this
->drupalGet('admin/structure/types/manage/paragraphed_test/form-display');
$this
->submitForm([], 'field_paragraphs_settings_edit');
$this
->submitForm([
'fields[field_paragraphs][settings_edit_form][settings][features][collapse_edit_all]' => TRUE,
], 'Update');
$this
->submitForm([], 'Save');
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->assertSession()
->buttonExists('field_paragraphs_collapse_all');
$this
->assertSession()
->buttonExists('field_paragraphs_edit_all');
$this
->assertSession()
->fieldValueEquals('field_paragraphs[0][subform][field_text][0][value]', 'First text');
}
public function testHeaderActionsWithNesting() {
$this
->addParagraphedContentType('paragraphed_test');
$this
->loginAsAdmin([
'create paragraphed_test content',
'edit any paragraphed_test content',
]);
$nested_paragraph_type = 'nested_paragraph';
$this
->addParagraphsType($nested_paragraph_type);
$paragraph_type = 'text';
$this
->addParagraphsType($paragraph_type);
static::fieldUIAddNewField('admin/structure/paragraphs_type/' . $paragraph_type, 'text', 'Text', 'text_long', [], []);
static::fieldUIAddNewField('admin/structure/paragraphs_type/' . $nested_paragraph_type, 'nested', 'Nested', 'field_ui:entity_reference_revisions:paragraph', [
'settings[target_type]' => 'paragraph',
'cardinality' => '-1',
], []);
$this
->drupalGet('admin/structure/paragraphs_type/nested_paragraph/form-display');
$this
->submitForm([
'fields[field_nested][type]' => 'paragraphs',
], 'Save');
$this
->setParagraphsWidgetSettings($nested_paragraph_type, 'nested', [
'edit_mode' => 'closed',
], 'paragraphs', 'paragraph');
$this
->drupalGet('node/add/paragraphed_test');
$this
->submitForm([], 'field_paragraphs_nested_paragraph_add_more');
$this
->submitForm([], 'field_paragraphs_text_add_more');
$this
->assertSession()
->responseContains('field_paragraphs_collapse_all');
$this
->assertSession()
->responseContains('field_paragraphs_edit_all');
$this
->submitForm([], 'field_paragraphs_text_add_more');
$this
->submitForm([], 'field_paragraphs_0_subform_field_nested_text_add_more');
$this
->assertSession()
->responseNotContains('field_paragraphs_0_collapse_all');
$this
->assertSession()
->responseNotContains('field_paragraphs_0_edit_all');
$edit = [
'field_paragraphs[0][subform][field_nested][0][subform][field_text][0][value]' => 'Nested text',
'field_paragraphs[1][subform][field_text][0][value]' => 'Second text paragraph',
];
$this
->submitForm($edit, 'Collapse all');
$this
->assertSession()
->responseContains('field-paragraphs-0-edit');
$this
->assertSession()
->elementExists('css', '[name="field_paragraphs_1_edit"] + .paragraphs-dropdown');
$this
->submitForm([], 'field_paragraphs_edit_all');
$this
->assertSession()
->responseContains('field-paragraphs-0-collapse');
$edit = [
'title[0][value]' => 'Test',
];
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('paragraphed_test Test has been created.');
$node = $this
->getNodeByTitle('Test');
$this
->drupalGet('node/' . $node
->id());
$this
->clickLink('Edit');
$this
->assertSession()
->pageTextNotContains('No Paragraph added yet.');
$this
->submitForm([], 'field_paragraphs_0_subform_field_nested_text_add_more');
$edit = [
'field_paragraphs[0][subform][field_nested][1][subform][field_text][0][value]' => 'Second nested text',
];
$this
->submitForm($edit, 'field_paragraphs_0_collapse');
$this
->submitForm([], 'field_paragraphs_0_edit');
$this
->assertSession()
->responseContains('field_paragraphs_0_subform_field_nested_collapse_all');
$this
->assertSession()
->responseContains('field_paragraphs_0_subform_field_nested_edit_all');
}
public function testHeaderActionsWithMultiFields() {
$this
->addParagraphedContentType('paragraphed_test');
$this
->loginAsAdmin([
'create paragraphed_test content',
'edit any paragraphed_test content',
]);
$this
->drupalGet('/admin/structure/types/manage/paragraphed_test/fields/add-field');
$paragraph_type = 'text_paragraph';
$this
->addParagraphsType($paragraph_type);
static::fieldUIAddNewField('admin/structure/types/manage/paragraphed_test', 'second', 'Second paragraph', 'field_ui:entity_reference_revisions:paragraph', [], []);
static::fieldUIAddNewField('admin/structure/paragraphs_type/' . $paragraph_type, 'text', 'Text', 'text_long', [], []);
$this
->drupalGet('node/add/paragraphed_test');
$this
->submitForm([], 'field_paragraphs_text_paragraph_add_more');
$this
->submitForm([], 'field_second_text_paragraph_add_more');
$this
->assertSession()
->responseContains('field_paragraphs_collapse_all');
$this
->assertSession()
->responseContains('field_paragraphs_edit_all');
$this
->assertSession()
->responseContains('field_second_collapse_all');
$this
->assertSession()
->responseContains('field_second_edit_all');
$edit = [
'field_second[0][subform][field_text][0][value]' => 'Second field',
];
$this
->submitForm($edit, 'field_second_collapse_all');
$this
->assertSession()
->responseNotContains('field_paragraphs_0_edit');
$this
->assertSession()
->responseContains('field_second_0_edit');
$this
->submitForm([], 'field_paragraphs_collapse_all');
$this
->assertSession()
->responseContains('field_paragraphs_0_edit');
$this
->assertSession()
->responseContains('field_second_0_edit');
$this
->submitForm([], 'field_second_edit_all');
$this
->assertSession()
->responseContains('field_second_0_collapse');
$edit = [
'title[0][value]' => 'Test',
];
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('paragraphed_test Test has been created.');
$node = $this
->getNodeByTitle('Test');
$this
->drupalGet('node/' . $node
->id());
$this
->clickLink('Edit');
$this
->assertSession()
->pageTextNotContains('No Paragraph added yet.');
}
function testHeaderActionsWhileTranslating() {
$this
->addParagraphedContentType('paragraphed_test');
\Drupal::state()
->set('paragraphs_test_dragdrop_force_show', TRUE);
$this
->loginAsAdmin([
'administer site configuration',
'create paragraphed_test content',
'edit any paragraphed_test content',
'delete any paragraphed_test content',
'administer content translation',
'translate any entity',
'create content translations',
'administer languages',
]);
ConfigurableLanguage::createFromLangcode('es')
->save();
$this
->drupalGet('admin/config/regional/content-language');
$edit = [
'entity_types[node]' => TRUE,
'settings[node][paragraphed_test][translatable]' => TRUE,
];
$this
->submitForm($edit, 'Save configuration');
$paragraph_type = 'text_paragraph';
$this
->addParagraphsType($paragraph_type);
static::fieldUIAddNewField('admin/structure/paragraphs_type/' . $paragraph_type, 'text', 'Text', 'text_long', [], []);
$this
->drupalGet('node/add/paragraphed_test');
$this
->assertSession()
->responseContains('name="field_paragraphs_dragdrop_mode"');
$edit = [
'title[0][value]' => 'Title',
'field_paragraphs[0][subform][field_text][0][value]' => 'First',
];
$this
->submitForm($edit, 'Save');
$this
->clickLink('Translate');
$this
->clickLink('Add');
$this
->assertSession()
->responseNotContains('name="field_paragraphs_dragdrop_mode"');
$this
->assertSession()
->pageTextContains('First');
}
}