You are here

public function ConfigEntityDependencyCollectorTest::testConfigEntitiesDependencyCalculation in Dependency Calculation 8

Tests config entities dependency calculation.

Throws

\Drupal\Core\Entity\EntityStorageException

\Exception

File

tests/src/Kernel/EventSubscriber/DependencyCollector/ConfigEntityDependencyCollectorTest.php, line 76

Class

ConfigEntityDependencyCollectorTest
Class ConfigEntityDependencyCollector.

Namespace

Drupal\Tests\depcalc\Kernel\EventSubscriber\DependencyCollector

Code

public function testConfigEntitiesDependencyCalculation() {

  // Creating a new dependent image style.
  $style1 = $this
    ->createImageStyle('dummy_image_style_1');
  $wrapper = new DependentEntityWrapper($style1);
  $dependencies = $this->calculator
    ->calculateDependencies($wrapper, new DependencyStack());
  $this
    ->assertNotEmpty($dependencies);
  $this
    ->assertEqual(2, count($dependencies));
  $this
    ->assertArrayHasKey($style1
    ->uuid(), $dependencies);

  // Creating a one more dependent image style.
  $style2 = $this
    ->createImageStyle('dummy_image_style_2');

  // Creating a responsive image style which depends on the above styles.

  /** @var \Drupal\responsive_image\ResponsiveImageStyleInterface $responsiveImageStyle */
  $responsiveImageStyle = ResponsiveImageStyle::create([
    'id' => 'dummy_responsive_image_style_1',
    'label' => 'Dummy responsive image style 1',
  ]);
  $responsiveImageStyle
    ->addImageStyleMapping('dummy_breakpoint_1', '1x', [
    'image_mapping_type' => 'image_style',
    'image_mapping' => 'dummy_image_style_1',
  ]);
  $responsiveImageStyle
    ->addImageStyleMapping('dummy_breakpoint_2', '2x', [
    'image_mapping_type' => 'image_style',
    'image_mapping' => 'dummy_image_style_2',
  ]);
  $responsiveImageStyle
    ->save();
  $wrapper = new DependentEntityWrapper($responsiveImageStyle);
  $dependencies = $this->calculator
    ->calculateDependencies($wrapper, new DependencyStack());
  $this
    ->assertNotEmpty($dependencies);
  $this
    ->assertEqual(4, count($dependencies));
  $this
    ->assertArrayHasKey($style1
    ->uuid(), $wrapper
    ->getDependencies());
  $this
    ->assertArrayHasKey($style2
    ->uuid(), $wrapper
    ->getDependencies());
  $this
    ->assertEqual($dependencies['module'], [
    $wrapper
      ->getEntity()
      ->getEntityType()
      ->getProvider(),
  ]);
}