You are here

public function DependencyTest::testBundleDependency in Feeds 8.3

Tests dependency on bundle.

File

tests/src/Kernel/DependencyTest.php, line 55

Class

DependencyTest
Tests that feed type declares dependencies on fields used as target.

Namespace

Drupal\Tests\feeds\Kernel

Code

public function testBundleDependency() {

  // Create a feed type that is creating nodes of type 'article'.
  $feed_type = $this
    ->createFeedType();

  // Assert bundle dependency.
  $dependencies = $feed_type
    ->getDependencies();
  $expected = [
    'field.field.node.article.feeds_item',
    'node.type.article',
  ];
  $this
    ->assertEquals($expected, $dependencies['config']);

  // Delete the feed_item field first to avoid the error
  // "field_deleted_revision_xxx doesn't exist".
  FieldConfig::loadByName('node', 'article', 'feeds_item')
    ->delete();

  // Now delete the bundle.
  $this->container
    ->get('entity_type.manager')
    ->getStorage('node_type')
    ->load('article')
    ->delete();

  // Assert that the feed type no longer exists.
  $feed_type = $this
    ->reloadEntity($feed_type);
  $this
    ->assertNull($feed_type);
}