View source
<?php
namespace Drupal\Tests\paragraphs_features\FunctionalJavascript;
class ParagraphsFeaturesSingleActionTest extends ParagraphsFeaturesJavascriptTestBase {
public function testSingleActionOption() {
$content_type = 'test_single_action';
$this
->createTestConfiguration($content_type, 1);
$this
->enableDropdownToButton();
$this
->setupParagraphSettings($content_type);
$this
->drupalGet("node/add/{$content_type}");
$this
->assertSession()
->elementExists('xpath', '//input[@name="field_paragraphs_0_remove"]');
$this
->assertSession()
->elementNotExists('xpath', '//input[@name="field_paragraphs_0_duplicate"]');
$this
->assertSession()
->elementNotExists('xpath', '//div[contains(@class, "paragraphs-dropdown")]');
$this
->enableDuplicateAction($content_type);
$this
->assertSession()
->elementExists('xpath', '//input[@name="field_paragraphs_0_remove"]');
$this
->assertSession()
->elementExists('xpath', '//input[@name="field_paragraphs_0_duplicate"]');
$this
->assertSession()
->elementExists('xpath', '//div[contains(@class, "paragraphs-dropdown")]');
$this
->disableDropdownToButton();
$this
->assertSession()
->elementExists('xpath', '//input[@name="field_paragraphs_0_remove"]');
$this
->assertSession()
->elementExists('xpath', '//input[@name="field_paragraphs_0_duplicate"]');
$this
->assertSession()
->elementExists('xpath', '//div[contains(@class, "paragraphs-dropdown")]');
$this
->disableDuplicateAction($content_type);
$this
->assertSession()
->elementExists('xpath', '//input[@name="field_paragraphs_0_remove"]');
$this
->assertSession()
->elementNotExists('xpath', '//input[@name="field_paragraphs_0_duplicate"]');
$this
->assertSession()
->elementExists('xpath', '//div[contains(@class, "paragraphs-dropdown")]');
}
public function testAddAboveSupport() {
$content_type = 'test_single_action';
$this
->createTestConfiguration($content_type, 1);
$this
->enableDropdownToButton();
$this
->setupParagraphSettings($content_type);
$this
->drupalGet("node/add/{$content_type}");
$this
->assertSession()
->elementNotExists('xpath', '//div[contains(@class, "paragraphs-dropdown")]');
$this
->setParagraphFeature($content_type, 'add_above', 'add_above');
$this
->drupalGet("node/add/{$content_type}");
$this
->assertSession()
->elementExists('xpath', '//div[contains(@class, "paragraphs-dropdown")]');
}
protected function setParagraphFeature($content_type, $feature, $value) {
$this
->config('core.entity_form_display.node.' . $content_type . '.default')
->set('content.field_paragraphs.settings.features.' . $feature, $value)
->save();
}
protected function enableDuplicateAction($content_type) {
$currentUrl = $this
->getSession()
->getCurrentUrl();
$this
->setParagraphFeature($content_type, 'duplicate', 'duplicate');
$this
->drupalGet($currentUrl);
}
protected function disableDuplicateAction($content_type) {
$currentUrl = $this
->getSession()
->getCurrentUrl();
$this
->setParagraphFeature($content_type, 'duplicate', '0');
$this
->drupalGet($currentUrl);
}
protected function setupParagraphSettings($content_type) {
$currentUrl = $this
->getSession()
->getCurrentUrl();
$this
->config('core.entity_form_display.node.' . $content_type . '.default')
->set('content.field_paragraphs.settings.default_paragraph_type', 'test_1')
->set('content.field_paragraphs.third_party_settings.paragraphs_features.show_drag_and_drop', FALSE)
->save();
$this
->setParagraphFeature($content_type, 'duplicate', '0');
$this
->setParagraphFeature($content_type, 'add_above', '0');
$this
->drupalGet($currentUrl);
}
protected function enableDropdownToButton() {
$currentUrl = $this
->getSession()
->getCurrentUrl();
$this
->config('paragraphs_features.settings')
->set('dropdown_to_button', TRUE)
->save();
$this
->drupalGet($currentUrl);
}
protected function disableDropdownToButton() {
$currentUrl = $this
->getSession()
->getCurrentUrl();
$this
->config('paragraphs_features.settings')
->set('dropdown_to_button', FALSE)
->save();
$this
->drupalGet($currentUrl);
}
}