You are here

public function ConfigSelectorTest::testConfigSelectorIndirectDependency in Configuration selector 8

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/ConfigSelectorTest.php \Drupal\Tests\config_selector\Kernel\ConfigSelectorTest::testConfigSelectorIndirectDependency()

Tests \Drupal\config_selector\ConfigSelector().

Checks indirect module uninstall dependencies.

File

tests/src/Kernel/ConfigSelectorTest.php, line 250

Class

ConfigSelectorTest
Tests the ConfigSelector.

Namespace

Drupal\Tests\config_selector\Kernel

Code

public function testConfigSelectorIndirectDependency() {

  /** @var \Drupal\Core\Extension\ModuleInstallerInterface $module_installer */
  $module_installer = $this->container
    ->get('module_installer');

  // Install two modules at start, 3 configurations should be imported, where
  // only one is enabled and that one depends on
  // "config_selector_test_depends_on_test_two", where that module depends on
  // "config_selector_test_two".
  $module_installer
    ->install([
    'config_selector_test_one',
    'config_selector_test_depends_on_test_two',
  ]);

  /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface[] $configs */
  $configs = \Drupal::entityTypeManager()
    ->getStorage('config_test')
    ->loadMultiple();
  $this
    ->assertFalse($configs['feature_a_one']
    ->status());
  $this
    ->assertFalse($configs['feature_a_two']
    ->status());
  $this
    ->assertTrue($configs['feature_a_depends_on_test_two']
    ->status());
  $this
    ->assertArrayNotHasKey('feature_a_three', $configs);
  $this
    ->assertLogMessages([
    '<em class="placeholder">config_selector_test_two</em> module installed.',
    '<em class="placeholder">config_selector_test_depends_on_test_two</em> module installed.',
    '<em class="placeholder">config_selector_test_one</em> module installed.',
    'Configuration <a href="/admin/structure/config_test/manage/feature_a_one">Feature A version 1</a> has been disabled in favor of <a href="/admin/structure/config_test/manage/feature_a_depends_on_test_two">Feature A indirect depending on Test Two</a>.',
    'Configuration <a href="/admin/structure/config_test/manage/feature_a_two">Feature A version 2</a> has been disabled in favor of <a href="/admin/structure/config_test/manage/feature_a_depends_on_test_two">Feature A indirect depending on Test Two</a>.',
  ]);
  $this
    ->assertMessages([
    'Configuration <a href="/admin/structure/config_test/manage/feature_a_one">Feature A version 1</a> has been disabled in favor of <a href="/admin/structure/config_test/manage/feature_a_depends_on_test_two">Feature A indirect depending on Test Two</a>.',
    'Configuration <a href="/admin/structure/config_test/manage/feature_a_two">Feature A version 2</a> has been disabled in favor of <a href="/admin/structure/config_test/manage/feature_a_depends_on_test_two">Feature A indirect depending on Test Two</a>.',
  ]);
  $this
    ->clearLogger();

  // Uninstall "config_selector_test_two", that will indirectly uninstall also
  // "config_selector_test_depends_on_test_two", where all dependency are
  // removed and only requirements for "feature_a_one" are fulfilled.
  $module_installer
    ->uninstall([
    'config_selector_test_two',
  ]);
  $configs = \Drupal::entityTypeManager()
    ->getStorage('config_test')
    ->loadMultiple();
  $this
    ->assertTrue($configs['feature_a_one']
    ->status(), "Configuration: Feature A version 1 - should be enabled.");
  $this
    ->assertArrayNotHasKey('feature_a_two', $configs);
  $this
    ->assertArrayNotHasKey('feature_a_depends_on_test_two', $configs);
  $this
    ->assertArrayNotHasKey('feature_a_three', $configs);
  $this
    ->assertLogMessages([
    '<em class="placeholder">config_selector_test_depends_on_test_two</em> module uninstalled.',
    '<em class="placeholder">config_selector_test_two</em> module uninstalled.',
    'Configuration <a href="/admin/structure/config_test/manage/feature_a_one">Feature A version 1</a> has been enabled.',
  ]);
  $this
    ->assertMessages([
    'Configuration <a href="/admin/structure/config_test/manage/feature_a_one">Feature A version 1</a> has been enabled.',
  ]);
  $this
    ->clearLogger();
}