You are here

public function RemoveIdFieldTest::testRemoveIdField in Acquia Content Hub 8.2

Tests the removal of id field.

@covers ::excludeContentField

Throws

\Drupal\Core\Entity\EntityStorageException

File

tests/src/Kernel/EventSubscriber/ExcludeContentField/RemoveIdFieldTest.php, line 67

Class

RemoveIdFieldTest
Tests remove id field serialization.

Namespace

Drupal\Tests\acquia_contenthub\Kernel\EventSubscriber\ExcludeContentField

Code

public function testRemoveIdField() {
  $this
    ->createContentType([
    'type' => 'article',
    'name' => 'article',
  ]);
  $node = $this
    ->createNode([
    'type' => 'article',
  ]);
  $remove_id_and_revision_field = new RemoveIdField();
  foreach ($node as $field_name => $field) {
    $event = new ExcludeEntityFieldEvent($node, $field_name, $field);
    $remove_id_and_revision_field
      ->excludeContentField($event);
    if ($field_name === $event
      ->getEntity()
      ->getEntityType()
      ->getKey('id')) {
      $this
        ->assertTrue($event
        ->isExcluded());
      $this
        ->assertTrue($event
        ->isPropagationStopped());
    }
    else {
      $this
        ->assertFalse($event
        ->isExcluded());
      $this
        ->assertFalse($event
        ->isPropagationStopped());
    }
  }
}