ConfigEntityDependency example

if (empty($optional_config_storage->listAll()) && empty($extension_config_storage->listAll())) {
      $this->markTestSkipped("$name has no configuration to test");
    }

    // Work out any additional modules and themes that need installing to create     // an optional config.     $modules_to_install = $type !== 'theme' ? [$name] : [];
    $themes_to_install = $type === 'theme' ? [$name] : [];
    foreach ($optional_config_storage->listAll() as $config_name) {
      $data = $optional_config_storage->read($config_name);
      $dependency = new ConfigEntityDependency($config_name$data);
      $modules_to_install = array_merge($modules_to_install$dependency->getDependencies('module'));
      $themes_to_install = array_merge($themes_to_install$dependency->getDependencies('theme'));
    }
    // Remove core and standard because they cannot be installed.     $modules_to_install = array_diff(array_unique($modules_to_install)['core', 'standard']);
    $this->container->get('module_installer')->install($modules_to_install);
    $this->container->get('theme_installer')->install(array_unique($themes_to_install));

    // Test configuration in the extension's config/install directory.     $this->doTestsOnConfigStorage($extension_config_storage$name$type);

    
use Drupal\Tests\UnitTestCase;
use Drupal\Core\Config\Entity\ConfigEntityDependency;

/** * Tests the ConfigEntityDependency class. * * @group Config */
class ConfigEntityDependencyTest extends UnitTestCase {

  public function testEmptyDependencies() {
    $dep = new ConfigEntityDependency('config_test.dynamic.entity_id', []);

    $this->assertEquals('config_test.dynamic.entity_id', $dep->getConfigDependencyName());
    $this->assertEquals([]$dep->getDependencies('theme'));
    $this->assertEquals([]$dep->getDependencies('config'));
    $this->assertEquals(['config_test']$dep->getDependencies('module'));
    $this->assertTrue($dep->hasDependency('module', 'config_test'));
    $this->assertFalse($dep->hasDependency('module', 'views'));
  }

  public function testWithDependencies() {
    $values = [
      
'provider' => 'some module',
          'dependencies' => ['config' => [$dependency_name]],
        ],
      ]);
    $permission_handler = $prophecy->reveal();
    $role_storage = $this->prophesize(RoleStorageInterface::class)->reveal();
    $module_handler = $this->prophesize(ModuleHandlerInterface::class)->reveal();
    $prophecy = $this->prophesize(ConfigManagerInterface::class);
    $prophecy->getConfigEntitiesToChangeOnDependencyRemoval('config', ['node.type.article'])
      ->willReturn([
        'delete' => [
          new ConfigEntityDependency('core.entity_view_display.node.article.full'),
          new ConfigEntityDependency('field.field.node.article.body'),
        ],
      ]);
    $config_manager = $prophecy->reveal();
    $prophecy = $this->prophesize(EntityTypeInterface::class);
    $prophecy->getPermissionGranularity()
      ->willReturn('entity_type');
    $entity_type = $prophecy->reveal();
    $prophecy = $this->prophesize(EntityTypeManagerInterface::class);
    $prophecy->getDefinition('entity_type')
      ->willReturn($entity_type);
    

  public function setData(array $data) {
    array_walk($datafunction D&$config$name) {
      $config = new ConfigEntityDependency($name$config);
    });
    $this->data = $data;
    $this->graph = NULL;
    return $this;
  }

  /** * Updates one of the lightweight ConfigEntityDependency objects. * * @param $name * The configuration dependency name. * @param array $dependencies * The configuration dependencies. The array is structured like this: * @code * array( * 'config' => array( * // An array of configuration entity object names. * ), * 'content' => array( * // An array of content entity configuration dependency names. The default * // format is "ENTITY_TYPE_ID:BUNDLE:UUID". * ), * 'module' => array( * // An array of module names. * ), * 'theme' => array( * // An array of theme names. * ), * ); * @endcode * * @return $this */
Home | Imprint | This part of the site doesn't use cookies.