You are here

public function ParagraphsAccessTest::testParagraphsTextFormatValidation in Paragraphs 8

Tests the Paragraph validation with filter access.

File

tests/src/Functional/WidgetStable/ParagraphsAccessTest.php, line 268

Class

ParagraphsAccessTest
Tests the access check of paragraphs.

Namespace

Drupal\Tests\paragraphs\Functional\WidgetStable

Code

public function testParagraphsTextFormatValidation() {
  $filtered_html_format = FilterFormat::create([
    'format' => 'filtered_html',
    'name' => 'Filtered HTML',
  ]);
  $filtered_html_format
    ->save();
  $permissions = [
    'create paragraphed_content_demo content',
    'edit any paragraphed_content_demo content',
    $filtered_html_format
      ->getPermissionName(),
  ];
  $this
    ->loginAsAdmin($permissions);

  // Create a node with a Text Paragraph using the filtered html format.
  $this
    ->drupalGet('node/add/paragraphed_content_demo');
  $this
    ->submitForm([], 'Add text');
  $this
    ->assertSession()
    ->pageTextContains('Text');
  $edit = [
    'title[0][value]' => 'access_validation_test',
    'field_paragraphs_demo[0][subform][field_text_demo][0][value]' => 'Test',
  ];
  $this
    ->submitForm($edit, 'Save');
  $this
    ->assertSession()
    ->pageTextContains('paragraphed_content_demo access_validation_test has been created.');
  $this
    ->drupalLogout();

  // Login as an user without the Text Format permission.
  $user = $this
    ->drupalCreateUser([
    'administer nodes',
    'edit any paragraphed_content_demo content',
  ]);
  $this
    ->drupalLogin($user);
  $node = $this
    ->getNodeByTitle('access_validation_test');
  $this
    ->drupalGet('node/' . $node
    ->id() . '/edit');
  $this
    ->submitForm([], 'Save');
  $this
    ->assertSession()
    ->pageTextContains('paragraphed_content_demo access_validation_test has been updated.');
  $this
    ->drupalGet('node/' . $node
    ->id() . '/edit');
  $this
    ->submitForm([], 'field_paragraphs_demo_0_collapse');
  $this
    ->submitForm([], 'Save');
  $this
    ->assertSession()
    ->pageTextContains('paragraphed_content_demo access_validation_test has been updated.');
  $this
    ->assertSession()
    ->pageTextNotContains('The value you selected is not a valid choice.');
}