You are here

public function CommentAlterTextTest::testTextFieldMultiple in Comment Alter 8

Tests for multi-valued text field comment altering.

File

tests/src/Functional/CommentAlterTextTest.php, line 62

Class

CommentAlterTextTest
Tests the comment alter module functions for text fields.

Namespace

Drupal\Tests\comment_alter\Functional

Code

public function testTextFieldMultiple() {
  $field_name = $this
    ->addTextField(-1);

  // Create two random values of different length so that they may never be
  // equal.
  $old_value = $this
    ->randomMachineName(5);
  $new_value = $this
    ->randomMachineName(6);
  $this
    ->createEntityObject([
    $field_name => [
      0 => [
        'value' => $old_value,
      ],
    ],
  ]);
  $this
    ->assertAlterableField($field_name);

  // The alterable fields on comment form have a wrapper of alterable_fields
  // over them because of the #parent property specified in the
  // comment_form_alter.
  $this
    ->postComment([
    "comment_alter_fields[{$field_name}][1][value]" => $new_value,
  ]);
  $this
    ->assertCommentDiff([
    $field_name => [
      [
        $old_value,
        $old_value,
      ],
      [
        NULL,
        $new_value,
      ],
    ],
  ]);
  $this
    ->assertCommentSettings($field_name);
  $this
    ->assertRevisionDelete();
}