You are here

public function RemovePathAliasFieldTest::testRemovePathAliasField in Acquia Content Hub 8.2

Tests the removal of path alias field.

@covers ::excludeContentField

Throws

\Drupal\Core\Entity\EntityStorageException

File

tests/src/Kernel/EventSubscriber/ExcludeContentField/RemovePathAliasFieldTest.php, line 76

Class

RemovePathAliasFieldTest
Tests remove path alias field serialization.

Namespace

Drupal\Tests\acquia_contenthub\Kernel\EventSubscriber\ExcludeContentField

Code

public function testRemovePathAliasField() {
  $this
    ->createContentType([
    'type' => 'article',
    'name' => 'article',
  ]);
  $node = $this
    ->createNode([
    'type' => 'article',
  ]);
  $path_alias = PathAlias::create([
    'path' => '/node/' . $node
      ->id(),
    'alias' => 'new_test_path',
  ]);
  $path_alias
    ->save();
  $remove_id_and_revision_field = new RemovePathAliasField();
  foreach ($node as $field_name => $field) {
    $event = new ExcludeEntityFieldEvent($node, $field_name, $field);
    $remove_id_and_revision_field
      ->excludeContentField($event);
    if ($event
      ->getEntity()
      ->getEntityTypeId() !== 'path_alias' && $event
      ->getFieldName() === 'path') {
      $this
        ->assertTrue($event
        ->isExcluded());
      $this
        ->assertTrue($event
        ->isPropagationStopped());
    }
    else {
      $this
        ->assertFalse($event
        ->isExcluded());
      $this
        ->assertFalse($event
        ->isPropagationStopped());
    }
  }
}