You are here

public function EntityFormDisplayDependencyCollectorTest::testEntityFormDisplayDependencyCollection in Dependency Calculation 8

Tests dependency calculation of entity form display.

Throws

\Drupal\Core\Entity\EntityStorageException

\Exception

File

tests/src/Kernel/EventSubscriber/DependencyCollector/EntityFormDisplayDependencyCollectorTest.php, line 72

Class

EntityFormDisplayDependencyCollectorTest
Class EntityFormDisplayDependencyCollectorTest.

Namespace

Drupal\Tests\depcalc\Kernel\EventSubscriber\DependencyCollector

Code

public function testEntityFormDisplayDependencyCollection() {
  $bundle = 'depcalc_dummy_content_type';
  $entityType = 'node';
  $this
    ->createContentType([
    'type' => $bundle,
    'name' => 'Depcalc. Dummy content type',
  ])
    ->save();
  $enabledFormDisplay = $this
    ->createFormDisplay($entityType, $bundle, 'depcalc_dummy_form_mode', TRUE);
  $disabledFormDisplay = $this
    ->createFormDisplay($entityType, $bundle, 'depcalc_dummy_form_mode_disabled', FALSE);
  $node = $this
    ->createNode([
    'type' => 'depcalc_dummy_content_type',
  ]);
  $node
    ->save();
  $dependencies = $this->calculator
    ->calculateDependencies(new DependentEntityWrapper($node), new DependencyStack());
  $this
    ->assertNotEmpty($dependencies);
  $this
    ->assertArrayHasKey($enabledFormDisplay
    ->uuid(), $dependencies);
  $this
    ->assertArrayNotHasKey($disabledFormDisplay
    ->uuid(), $dependencies);

  /** @var \Drupal\depcalc\DependentEntityWrapper $formDisplayEntityWrapper */
  $formDisplayEntityWrapper = $dependencies[$enabledFormDisplay
    ->uuid()];
  $this
    ->assertEqual($formDisplayEntityWrapper
    ->getUuid(), $enabledFormDisplay
    ->uuid());
  $this
    ->assertEqual($enabledFormDisplay
    ->getEntityTypeId(), 'entity_form_display');
}