You are here

public function ConfigEntityDependencyCollectorTest::testLanguageConfigEntitiesDependencyCalculation in Dependency Calculation 8

Tests language config dependencies calculation.

Throws

\Drupal\Core\Entity\EntityStorageException

\Exception

File

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

Class

ConfigEntityDependencyCollectorTest
Class ConfigEntityDependencyCollector.

Namespace

Drupal\Tests\depcalc\Kernel\EventSubscriber\DependencyCollector

Code

public function testLanguageConfigEntitiesDependencyCalculation() {
  list($csLanguage, $frLanguage) = $this
    ->getTestLanguages();
  $bundle = 'article';
  $this
    ->createContentType([
    'type' => $bundle,
    'name' => 'Article',
  ]);
  $contentLanguageSettings = ContentLanguageSettings::loadByEntityTypeBundle('node', $bundle);
  $csNode = $this
    ->createTestNode('cs');
  $csDependencies = $this->calculator
    ->calculateDependencies(new DependentEntityWrapper($csNode), new DependencyStack());
  $contentLanguageSettings
    ->setDefaultLangcode('cs')
    ->setLanguageAlterable(FALSE)
    ->save();
  $this
    ->assertArrayNotHasKey($csLanguage
    ->uuid(), $csDependencies);
  $this
    ->assertArrayNotHasKey($frLanguage
    ->uuid(), $csDependencies);
  $this
    ->assertArrayNotHasKey($contentLanguageSettings
    ->uuid(), $csDependencies);
  $contentLanguageSettings
    ->setDefaultLangcode('cs')
    ->setLanguageAlterable(TRUE)
    ->save();
  $csNode = $this
    ->createTestNode('cs');
  $frNode = $csNode
    ->addTranslation('fr');
  $frNode
    ->set('title', $this
    ->randomString());
  $frNode
    ->save();
  $csDependencies = $this->calculator
    ->calculateDependencies(new DependentEntityWrapper($csNode), new DependencyStack());
  $frDependencies = $this->calculator
    ->calculateDependencies(new DependentEntityWrapper($frNode), new DependencyStack());
  $this
    ->assertArrayHasKey('language', array_flip($csDependencies['module']));
  $this
    ->assertArrayHasKey('language', array_flip($frDependencies['module']));

  /** @var \Drupal\depcalc\DependentEntityWrapperInterface $csNodeDependency */
  $csNodeDependency = $csDependencies[$csNode
    ->uuid()];
  $this
    ->assertArrayHasKey($csLanguage
    ->uuid(), $csNodeDependency
    ->getDependencies());
  $this
    ->assertArrayHasKey($frLanguage
    ->uuid(), $csNodeDependency
    ->getDependencies());
  $this
    ->assertArrayHasKey($contentLanguageSettings
    ->uuid(), $csNodeDependency
    ->getDependencies());
  $frNodeDependency = $csDependencies[$frNode
    ->uuid()];
  $this
    ->assertArrayHasKey($csLanguage
    ->uuid(), $frNodeDependency
    ->getDependencies());
  $this
    ->assertArrayHasKey($frLanguage
    ->uuid(), $frNodeDependency
    ->getDependencies());
  $this
    ->assertArrayHasKey($contentLanguageSettings
    ->uuid(), $frNodeDependency
    ->getDependencies());
  $dependenciesWrapper = $this->calculator
    ->calculateDependencies(new DependentEntityWrapper($this
    ->createTestNode('cs')), new DependencyStack());
  $this
    ->assertArrayHasKey($csLanguage
    ->uuid(), $dependenciesWrapper);
  $this
    ->assertArrayNotHasKey($frLanguage
    ->uuid(), $dependenciesWrapper);
  $this
    ->assertArrayHasKey($contentLanguageSettings
    ->uuid(), $dependenciesWrapper);
  $dependenciesWrapper = $this->calculator
    ->calculateDependencies(new DependentEntityWrapper($this
    ->createTestNode('fr')), new DependencyStack());
  $this
    ->assertArrayHasKey($frLanguage
    ->uuid(), $dependenciesWrapper);
  $this
    ->assertArrayNotHasKey($csLanguage
    ->uuid(), $dependenciesWrapper);
  $this
    ->assertArrayHasKey($contentLanguageSettings
    ->uuid(), $dependenciesWrapper);
}