View source
<?php
namespace Drupal\Tests\paragraphs_collection\Functional;
use Drupal\Tests\paragraphs\Functional\WidgetStable\ParagraphsTestBase;
class ParagraphsLockablePluginTest extends ParagraphsTestBase {
use \Drupal\Tests\field_ui\Traits\FieldUiTestTrait;
public static $modules = [
'paragraphs_collection',
];
public function testLockedParagraphInstance() {
$contentTypeId = 'paragraphed_lock_test';
$this
->addParagraphedContentType($contentTypeId, 'paragraphs');
$permissions = [
'administer site configuration',
'administer lockable paragraph',
'bypass node access',
'administer content types',
'edit behavior plugin settings',
];
$this
->loginAsAdmin($permissions);
$paragraphType = 'text_test';
$fieldName = 'text';
$this
->addParagraphsType($paragraphType);
$bundlePath = 'admin/structure/paragraphs_type/' . $paragraphType;
$this
->fieldUIAddExistingField('admin/structure/paragraphs_type/' . $paragraphType, 'paragraphs_text');
$this
->drupalGet($bundlePath);
$this
->assertFieldByName('behavior_plugins[lockable][enabled]');
$edit = [
'behavior_plugins[lockable][enabled]' => TRUE,
];
$this
->drupalPostForm(NULL, $edit, t('Save'));
$this
->drupalGet($bundlePath);
$this
->assertFieldChecked('edit-behavior-plugins-lockable-enabled');
$this
->drupalGet('node/add/' . $contentTypeId);
$this
->drupalPostForm(NULL, [], 'paragraphs_' . $paragraphType . '_add_more');
$edit = [
'title[0][value]' => 'Test article',
'paragraphs[0][subform][paragraphs_' . $fieldName . '][0][value]' => 'This is some text',
'paragraphs[0][behavior_plugins][lockable][locked]' => TRUE,
];
$this
->drupalPostForm(NULL, $edit, 'Save');
$nodeUrl = $this
->getUrl();
$this
->drupalGet($nodeUrl . '/edit');
$this
->assertNoText('You are not allowed to edit or remove this Paragraph.');
$account = $this
->drupalCreateUser([
'bypass node access',
]);
$this
->drupalLogin($account);
$this
->drupalGet($nodeUrl . '/edit');
$this
->assertText('You are not allowed to edit or remove this Paragraph.');
$account = $this
->drupalCreateUser([
'bypass node access',
'administer lockable paragraph',
]);
$this
->drupalLogin($account);
$this
->drupalGet($nodeUrl . '/edit');
$this
->assertNoText('You are not allowed to edit or remove this Paragraph.');
}
public function testLockedSettingsSummary() {
$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',
]);
$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');
$edit = [
'behavior_plugins[lockable][enabled]' => TRUE,
];
$this
->drupalPostForm('admin/structure/paragraphs_type/' . $paragraph_type, $edit, t('Save'));
$this
->drupalGet('node/add/' . $content_type_id);
$this
->drupalPostForm(NULL, [], 'paragraphs_' . $paragraph_type . '_add_more');
$this
->drupalPostForm(NULL, [], '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
->drupalPostForm(NULL, $edit, 'Save');
$this
->clickLink('Edit');
$this
->assertRaw('<span class="summary-content">Text 1<');
$this
->assertRaw('<span class="summary-content">Text 2</span></div><div class="paragraphs-plugin-wrapper"><span class="summary-plugin">Locked<');
}
}