You are here

public function CommentAlterNodeReferenceTest::testEntityReferenceFieldMultiple in Comment Alter 8

Tests for multi-valued node reference field comment altering.

File

tests/src/Functional/CommentAlterNodeReferenceTest.php, line 83

Class

CommentAlterNodeReferenceTest
Tests the comment alter module functions for node reference fields.

Namespace

Drupal\Tests\comment_alter\Functional

Code

public function testEntityReferenceFieldMultiple() {
  $field_name = $this
    ->addNodeReferenceField(-1);
  $this
    ->createEntityObject([
    $field_name => [
      'target_id' => $this->targetNode
        ->id(),
    ],
  ]);
  $new_node = $this
    ->randomMachineName();
  $this
    ->postComment([
    "comment_alter_fields[{$field_name}][1][target_id]" => $new_node,
  ]);
  $this
    ->assertCommentDiff([
    $field_name => [
      [
        $this->targetNode
          ->getTitle(),
        $this->targetNode
          ->getTitle(),
      ],
      [
        NULL,
        $new_node,
      ],
    ],
  ]);
  $this
    ->assertCommentSettings($field_name);
  $this
    ->assertRevisionDelete();
  $this
    ->assertAlterableField($field_name);
}