class ParagraphsAccordionPluginTest

Tests Accordion plugin.

@group paragraphs_collection_demo

Hierarchy

Expanded class hierarchy of ParagraphsAccordionPluginTest

See also

\Drupal\paragraphs_collection_demo\Plugin\paragraphs\Behavior\ParagraphsAccordionPlugin

File

paragraphs_collection/modules/paragraphs_collection_demo/tests/src/Functional/ParagraphsAccordionPluginTest.php, line 13

Namespace

Drupal\Tests\paragraphs_collection_demo\Functional
View source
class ParagraphsAccordionPluginTest extends ParagraphsTestBase {

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'classy';

  /**
   * Modules to be enabled.
   *
   * @var array
   */
  protected static $modules = [
    'paragraphs_collection_demo',
  ];

  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
    $this
      ->loginAsAdmin([
      'administer modules',
      'edit behavior plugin settings',
    ]);
    $this
      ->addParagraphedContentType('paragraphed_accordion_test');
    $this
      ->addParagraphsType('accordion_content');
    static::fieldUIAddNewField('admin/structure/paragraphs_type/accordion_content', 'accordion_content', 'accordion_title', 'text_long', [
      'cardinality' => 'number',
      'cardinality_number' => '1',
    ], []);
  }

  /**
   * Test creating accordion content.
   */
  public function testCreatingAccordionContent() {
    $this
      ->drupalGet('node/add/paragraphed_accordion_test');
    $this
      ->submitForm([], 'field_paragraphs_accordion_add_more');
    $this
      ->submitForm([], 'field_paragraphs_0_subform_paragraphs_accordion_paragraphs_accordion_content_add_more');
    $this
      ->submitForm([], 'field_paragraphs_0_subform_paragraphs_accordion_paragraphs_accordion_content_add_more');
    $this
      ->submitForm([], 'field_paragraphs_0_subform_paragraphs_accordion_paragraphs_accordion_content_add_more');
    $this
      ->submitForm([], 'field_paragraphs_0_subform_paragraphs_accordion_paragraphs_accordion_content_add_more');
    $edit = [
      'title[0][value]' => 'Accordion',
      'field_paragraphs[0][subform][paragraphs_accordion_paragraphs][0][subform][field_accordion_content][0][value]' => 'Title',
      'field_paragraphs[0][subform][paragraphs_accordion_paragraphs][1][subform][field_accordion_content][0][value]' => 'Body text.',
      'field_paragraphs[0][subform][paragraphs_accordion_paragraphs][2][subform][field_accordion_content][0][value]' => 'Second title',
      'field_paragraphs[0][subform][paragraphs_accordion_paragraphs][3][subform][field_accordion_content][0][value]' => 'Second Body text.',
    ];
    $this
      ->submitForm($edit, 'Save');
    $node = $this
      ->getNodeByTitle('Accordion');
    $this
      ->drupalGet('node/' . $node
      ->id());

    // Ensure expected markup for an accordion.
    $elements = $this
      ->xpath('//div[contains(@class, :accordion-class)]/div[contains(@class, :items-class)]', [
      ':accordion-class' => 'accordion',
      ':items-class' => 'field__items',
    ]);
    $this
      ->assertTrue(!empty($elements), 'The proper accordion markup was found.');
    $this
      ->drupalGet('admin/structure/paragraphs_type/accordion/fields/paragraph.accordion.paragraphs_accordion_paragraphs/delete');
    $this
      ->submitForm([], t('Delete'));
    $this
      ->assertSession()
      ->pageTextContains('The field Accordion has been deleted from the Accordion content type.');
    $node = $this
      ->getNodeByTitle('Accordion');
    $this
      ->drupalGet('node/' . $node
      ->id());
    $this
      ->assertSession()
      ->statusCodeEquals(200);
    $this
      ->drupalGet('admin/structure/paragraphs_type/accordion');
    $this
      ->assertSession()
      ->statusCodeEquals(200);
    $this
      ->submitForm([
      'behavior_plugins[accordion][enabled]' => TRUE,
    ], t('Save'));
    $this
      ->assertSession()
      ->responseContains('The Accordion plugin cannot be enabled if the accordion field is missing.');
  }

  /**
   * Test accordion plugin configuration form.
   */
  public function testConfigurationForm() {
    $this
      ->drupalGet('admin/structure/paragraphs_type/accordion_content');
    $this
      ->assertSession()
      ->pageTextContains('There are no fields available with the cardinality greater than one. Please add at least one in the Manage fields page.');
    $this
      ->drupalGet('admin/structure/paragraphs_type/accordion');
    $this
      ->assertSession()
      ->responseContains('Accordion effect for paragraphs.');
    $this
      ->assertSession()
      ->optionExists('edit-behavior-plugins-accordion-settings-paragraph-accordion-field', 'paragraphs_accordion_paragraphs');
    $this
      ->assertSession()
      ->responseContains('Choose a field to be used as the accordion container.');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ParagraphsAccordionPluginTest::$defaultTheme protected property Overrides ParagraphsTestBase::$defaultTheme
ParagraphsAccordionPluginTest::$modules protected static property Modules to be enabled. Overrides ParagraphsTestBase::$modules
ParagraphsAccordionPluginTest::setUp protected function Overrides ParagraphsTestBase::setUp
ParagraphsAccordionPluginTest::testConfigurationForm public function Test accordion plugin configuration form.
ParagraphsAccordionPluginTest::testCreatingAccordionContent public function Test creating accordion content.
ParagraphsTestBase::$admin_permissions protected property List of permissions used by loginAsAdmin().
ParagraphsTestBase::$admin_user protected property Drupal user object created by loginAsAdmin(). 1
ParagraphsTestBase::loginAsAdmin function Creates an user with admin permissions and log in.
ParagraphsTestBase::removeDefaultParagraphType protected function Removes the default paragraph type. Overrides ParagraphsTestBase::removeDefaultParagraphType
ParagraphsTestBase::setAddMode protected function Sets the Paragraphs widget add mode. Overrides ParagraphsTestBase::setAddMode
ParagraphsTestBase::setAllowedParagraphsTypes protected function Sets the allowed Paragraphs types that can be added.
ParagraphsTestBase::setDefaultParagraphType protected function Sets the default paragraph type.
ParagraphsTestBase::setParagraphsTypeWeight protected function Sets the weight of a given Paragraphs type.
ParagraphsTestBase::setParagraphsWidgetMode protected function Sets the Paragraphs widget display mode.
ParagraphsTestBaseTrait::$workflow protected property The workflow entity.
ParagraphsTestBaseTrait::addFieldtoParagraphType protected function Adds a field to a given paragraph type.
ParagraphsTestBaseTrait::addParagraphedContentType protected function Adds a content type with a Paragraphs field.
ParagraphsTestBaseTrait::addParagraphsField protected function Adds a Paragraphs field to a given entity type.
ParagraphsTestBaseTrait::addParagraphsType protected function Adds a Paragraphs type.
ParagraphsTestBaseTrait::addParagraphsTypeIcon protected function Adds an icon to a paragraphs type.
ParagraphsTestBaseTrait::coreVersion protected function Checks the core version.
ParagraphsTestBaseTrait::createEditorialWorkflow protected function Creates a workflow entity.
ParagraphsTestBaseTrait::setParagraphsWidgetSettings protected function Sets some of the settings of a paragraphs field widget.