You are here

public function ParagraphsSliderPluginTest::testCreatingSliderContent in Paragraphs Collection 8

Tests creating slider content.

File

modules/paragraphs_collection_demo/tests/src/Functional/ParagraphsSliderPluginTest.php, line 43

Class

ParagraphsSliderPluginTest
Tests Slider plugin.

Namespace

Drupal\Tests\paragraphs_collection_demo\Functional

Code

public function testCreatingSliderContent() {
  $this
    ->fieldUIAddExistingField('admin/structure/paragraphs_type/slide_content', 'paragraphs_text', 'slide_content');
  $this
    ->assertText('Saved slide_content configuration');

  // Add new content.
  $this
    ->drupalGet('node/add/paragraphed_test');
  $this
    ->drupalPostForm(NULL, NULL, 'field_paragraphs_slider_add_more');
  $this
    ->drupalPostForm(NULL, NULL, 'field_paragraphs_0_subform_field_slides_slide_content_add_more');
  $this
    ->drupalPostForm(NULL, NULL, 'field_paragraphs_0_subform_field_slides_text_add_more');
  $edit = [
    'title[0][value]' => 'Slider',
    'field_paragraphs[0][subform][field_slides][0][subform][paragraphs_text][0][value]' => 'First slide.',
    'field_paragraphs[0][subform][field_slides][1][subform][paragraphs_text][0][value]' => 'Second slide.',
    'field_paragraphs[0][behavior_plugins][slider][slick_slider]' => 'default',
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'Save');
  $this
    ->assertText('paragraphed_test Slider has been created.');
  $this
    ->drupalGet('node/1');
  $xpath = '//div[@class = "paragraph paragraph--type--slider paragraph--view-mode--default"]//div[contains(@class, "slick")]';
  $this
    ->assertFieldByXPath($xpath, NULL, "Slick class found");
  $this
    ->drupalGet('admin/structure/paragraphs_type/slider/fields');
  $this
    ->drupalPostForm('admin/structure/paragraphs_type/slider/fields/paragraph.slider.field_slides/delete', [], t('Delete'));
  $this
    ->assertText('The field Slides has been deleted from the Slider content type.');
  $node = $this
    ->getNodeByTitle('Slider');
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->assertResponse(200);
  $this
    ->drupalGet('admin/structure/paragraphs_type/slider');
  $this
    ->assertResponse(200);
  $this
    ->assertText('There are no fields available with the cardinality greater than one. Please add at least one in the Manage fields page.');
  $this
    ->drupalPostForm(NULL, [
    'behavior_plugins[slider][enabled]' => TRUE,
  ], t('Save'));
  $this
    ->assertText('The Slider plugin cannot be enabled if there is no field to be mapped.');
}