public function ParagraphsSliderPluginTest::testCreatingSliderContent

Tests creating slider content.

File

paragraphs_collection/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
    ->assertSession()
    ->pageTextContains('Saved slide_content configuration');

  // Add new content.
  $this
    ->drupalGet('node/add/paragraphed_test');
  $this
    ->submitForm([], 'field_paragraphs_slider_add_more');
  $this
    ->submitForm([], 'field_paragraphs_0_subform_field_slides_slide_content_add_more');
  $this
    ->submitForm([], '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
    ->submitForm($edit, 'Save');
  $this
    ->assertSession()
    ->pageTextContains('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
    ->xpath($xpath, [], "Slick class found");
  $this
    ->drupalGet('admin/structure/paragraphs_type/slider/fields');
  $this
    ->drupalGet('admin/structure/paragraphs_type/slider/fields/paragraph.slider.field_slides/delete');
  $this
    ->submitForm([], t('Delete'));
  $this
    ->assertSession()
    ->pageTextContains('The field Slides has been deleted from the Slider content type.');
  $node = $this
    ->getNodeByTitle('Slider');
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->drupalGet('admin/structure/paragraphs_type/slider');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $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
    ->submitForm([
    'behavior_plugins[slider][enabled]' => TRUE,
  ], t('Save'));
  $this
    ->assertSession()
    ->pageTextContains('The Slider plugin cannot be enabled if there is no field to be mapped.');
}