public function ParagraphsLockablePluginTest::testLockedSettingsSummary

Tests Lockable plugin summary for paragraphs closed mode.

File

paragraphs_collection/tests/src/Functional/ParagraphsLockablePluginTest.php, line 96

Class

ParagraphsLockablePluginTest
Tests the lockable plugin.

Namespace

Drupal\Tests\paragraphs_collection\Functional

Code

public function testLockedSettingsSummary() {

  // Create an article with paragraphs field.
  $content_type_id = 'paragraphed_lock_test';
  $this
    ->addParagraphedContentType($content_type_id, 'paragraphs');
  $this
    ->loginAsAdmin([
    'administer site configuration',
    'administer lockable paragraph',
    'bypass node access',
    'administer content types',
    'edit behavior plugin settings',
    'create ' . $content_type_id . ' content',
    'edit any ' . $content_type_id . ' content',
  ]);

  // Add a text paragraph type.
  $paragraph_type = 'text_test';
  $field_name = 'text';
  $this
    ->addParagraphsType($paragraph_type);
  $this
    ->fieldUIAddExistingField('admin/structure/paragraphs_type/' . $paragraph_type, 'paragraphs_text');
  $this
    ->setParagraphsWidgetMode($content_type_id, 'paragraphs', 'closed');

  // Enable Lockable plugin for this text paragraph type.
  $edit = [
    'behavior_plugins[lockable][enabled]' => TRUE,
  ];
  $this
    ->drupalGet('admin/structure/paragraphs_type/' . $paragraph_type);
  $this
    ->submitForm($edit, t('Save'));

  // Node edit: add two text paragraph type, set the second text as locked.
  $this
    ->drupalGet('node/add/' . $content_type_id);
  $this
    ->submitForm([], 'paragraphs_' . $paragraph_type . '_add_more');
  $this
    ->submitForm([], 'paragraphs_' . $paragraph_type . '_add_more');
  $edit = [
    'title[0][value]' => 'Lockable plugin summary',
    'paragraphs[0][subform][paragraphs_' . $field_name . '][0][value]' => 'Text 1',
    'paragraphs[1][subform][paragraphs_' . $field_name . '][0][value]' => 'Text 2',
    'paragraphs[1][behavior_plugins][lockable][locked]' => TRUE,
  ];
  $this
    ->submitForm($edit, 'Save');

  // Assert the paragraph item summaries include the plugin summaries.
  $this
    ->clickLink('Edit');
  $this
    ->assertSession()
    ->responseContains('<span class="summary-content">Text 1<');
  $this
    ->assertSession()
    ->responseContains('<span class="summary-content">Text 2</span></div><div class="paragraphs-plugin-wrapper"><span class="summary-plugin">Locked<');
}