You are here

public function EntityViewDisplayDependencyCollectorTest::testEntityViewDisplaysWereAdded in Dependency Calculation 8

@covers ::onCalculateDependencies

Throws

\Exception

File

tests/src/Kernel/EventSubscriber/DependencyCollector/EntityViewDisplayDependencyCollectorTest.php, line 77

Class

EntityViewDisplayDependencyCollectorTest
Class EntityViewDisplayDependencyCollectorTest.

Namespace

Drupal\Tests\depcalc\Kernel\EventSubscriber\DependencyCollector

Code

public function testEntityViewDisplaysWereAdded() {
  EntityViewMode::create([
    'id' => 'node.foobar1',
    'targetEntityType' => 'node',
    'status' => TRUE,
    'enabled' => TRUE,
    'label' => 'My view mode',
  ])
    ->save();
  EntityViewMode::create([
    'id' => 'node.foobar2',
    'targetEntityType' => 'node',
    'status' => TRUE,
    'enabled' => TRUE,
    'label' => 'My view mode',
  ])
    ->save();
  NodeType::create([
    'type' => 'entity_view_display',
  ])
    ->save();
  $entity = $this
    ->createNode([
    'type' => 'entity_view_display',
    'title' => 'Title Test',
  ]);
  $display1 = EntityViewDisplay::create([
    'targetEntityType' => 'node',
    'bundle' => 'entity_view_display',
    'mode' => 'foobar1',
    'label' => 'My view mode 1',
    'status' => TRUE,
  ]);
  $display1
    ->save();
  $display2 = EntityViewDisplay::create([
    'targetEntityType' => 'node',
    'bundle' => 'entity_view_display',
    'mode' => 'foobar2',
    'label' => 'My view mode 2',
    'status' => TRUE,
  ]);
  $display2
    ->save();
  $event = $this
    ->dispatchCalculateDependencies($entity);
  $dependencies = $event
    ->getDependencies();
  $this
    ->assertArrayHasKey($display1
    ->uuid(), $dependencies);
  $this
    ->assertArrayHasKey($display2
    ->uuid(), $dependencies);
}