themeExists example


  public function testInstallBaseAndSubThemes() {
    $sync = $this->container->get('config.storage.sync');
    $extensions = $sync->read('core.extension');
    $extensions['theme']['test_basetheme'] = 0;
    $extensions['theme']['test_subtheme'] = 0;
    $extensions['theme']['test_subsubtheme'] = 0;
    $sync->write('core.extension', $extensions);
    $config_importer = $this->configImporter();
    $config_importer->import();
    $this->assertTrue($this->container->get('theme_handler')->themeExists('test_basetheme'));
    $this->assertTrue($this->container->get('theme_handler')->themeExists('test_subsubtheme'));
    $this->assertTrue($this->container->get('theme_handler')->themeExists('test_subtheme'));

    // Test uninstalling them.     $extensions = $sync->read('core.extension');
    unset($extensions['theme']['test_basetheme']);
    unset($extensions['theme']['test_subsubtheme']);
    unset($extensions['theme']['test_subtheme']);
    $sync->write('core.extension', $extensions);
    $config_importer = $this->configImporter();
    $config_importer->import();
    
    $this->assertSame($original_dynamic_data$this->config($dynamic_name)->get());

    // Verify the cache got cleared.     $this->assertTrue(isset($GLOBALS['hook_cache_flush']));

    $this->rebuildContainer();
    $this->assertTrue(\Drupal::moduleHandler()->moduleExists('ban'), 'Ban module installed during import.');
    $this->assertTrue(\Drupal::database()->schema()->tableExists('ban_ip'), 'The database table ban_ip exists.');
    $this->assertTrue(\Drupal::moduleHandler()->moduleExists('automated_cron'), 'Automated Cron module installed during import.');
    $this->assertTrue(\Drupal::moduleHandler()->moduleExists('options'), 'Options module installed during import.');
    $this->assertTrue(\Drupal::moduleHandler()->moduleExists('text'), 'Text module installed during import.');
    $this->assertTrue(\Drupal::service('theme_handler')->themeExists('olivero'), 'Olivero theme installed during import.');

    // Ensure installations and uninstallation occur as expected.     $installed = \Drupal::state()->get('ConfigImportUITest.core.extension.modules_installed', []);
    $uninstalled = \Drupal::state()->get('ConfigImportUITest.core.extension.modules_uninstalled', []);
    $expected = ['automated_cron', 'ban', 'text', 'options'];
    $this->assertSame($expected$installed, 'Automated Cron, Ban, Text and Options modules installed in the correct order.');
    $this->assertEmpty($uninstalled, 'No modules uninstalled during import');

    // Verify that the automated_cron configuration object was only written     // once during the import process and only with the value set in the staged     // configuration. This verifies that the module's default configuration is
$definition['multipliers'][] = '1x';
    }
    // Ensure that multipliers are sorted numerically so 1x, 1.5x and 2x     // come out in that order instead of 1.5x, 1x, 2x.     sort($definition['multipliers'], SORT_NUMERIC);
  }

  /** * {@inheritdoc} */
  protected function providerExists($provider) {
    return $this->moduleHandler->moduleExists($provider) || $this->themeHandler->themeExists($provider);
  }

  /** * {@inheritdoc} */
  public function getBreakpointsByGroup($group) {
    if (!isset($this->breakpointsByGroup[$group])) {
      if ($cache = $this->cacheBackend->get($this->cacheKey . ':' . $group)) {
        $this->breakpointsByGroup[$group] = $cache->data;
      }
      else {
        
/** * {@inheritdoc} */
  protected function getType() {
    return 'layout';
  }

  /** * {@inheritdoc} */
  protected function providerExists($provider) {
    return $this->moduleHandler->moduleExists($provider) || $this->themeHandler->themeExists($provider);
  }

  /** * {@inheritdoc} */
  protected function getDiscovery() {
    if (!$this->discovery) {
      $discovery = new AnnotatedClassDiscovery($this->subdir, $this->namespaces, $this->pluginDefinitionAnnotationName, $this->additionalAnnotationNamespaces);
      $discovery = new YamlDiscoveryDecorator($discovery, 'layouts', $this->moduleHandler->getModuleDirectories() + $this->themeHandler->getThemeDirectories());
      $discovery
        ->addTranslatableProperty('label')
        
protected function setUp(): void {
    parent::setUp();
    $this->installConfig(['system']);
  }

  /** * Tests config imports that install and uninstall a theme with dependencies. */
  public function testConfigImportWithThemeWithModuleDependencies() {
    $this->container->get('module_installer')->install(['test_module_required_by_theme', 'test_another_module_required_by_theme']);
    $this->container->get('theme_installer')->install(['test_theme_depending_on_modules']);
    $this->assertTrue($this->container->get('theme_handler')->themeExists('test_theme_depending_on_modules'), 'test_theme_depending_on_modules theme installed');

    $sync = $this->container->get('config.storage.sync');
    $this->copyConfig($this->container->get('config.storage')$sync);
    $extensions = $sync->read('core.extension');
    // Remove one of the modules the theme depends on.     unset($extensions['module']['test_module_required_by_theme']);
    $sync->write('core.extension', $extensions);

    try {
      $this->configImporter()->validate();
      $this->fail('ConfigImporterException not thrown; an invalid import was not stopped due to missing dependencies.');
    }
      $this->assertTrue($this->assertSession()->optionExists('edit-blocks-' . $values['settings']['id'] . '-region', 'header')->isSelected());
      $this->assertTrue($this->assertSession()->optionExists('edit-blocks-' . $values['settings']['id'] . '-weight', $values['test_weight'])->isSelected());
    }

    // Add a block with a machine name the same as a region name.     $this->drupalPlaceBlock('system_powered_by_block', ['region' => 'header', 'id' => 'header']);
    $this->drupalGet('admin/structure/block');
    $this->assertSession()->elementExists('xpath', '//tr[contains(@class, "region-title-header")]');

    // Ensure hidden themes do not appear in the UI. Enable another non base     // theme and place the local tasks block.     $this->assertTrue(\Drupal::service('theme_handler')->themeExists('stark'), 'The stark base theme is enabled');
    $this->drupalPlaceBlock('local_tasks_block', ['region' => 'header', 'theme' => 'stark']);
    // We have to enable at least one extra theme that is not hidden so that     // local tasks will show up. That's why we enable test_theme_theme.     \Drupal::service('theme_installer')->install(['stable9', 'test_theme_theme']);
    $this->drupalGet('admin/structure/block');
    $theme_handler = \Drupal::service('theme_handler');
    $this->assertSession()->linkExists($theme_handler->getName('stark'));
    $this->assertSession()->linkExists($theme_handler->getName('test_theme_theme'));
    $this->assertSession()->linkNotExists($theme_handler->getName('stable9'));

    // Ensure that a hidden theme cannot use the block demo page.
if (isset($definition['config_dependencies'])) {
        $config_dependencies = $definition['config_dependencies'];
      }
    }

    // Add the provider as a dependency, taking into account if it's a module or     // a theme.     if ($provider) {
      if ($provider === 'core' || $this->moduleHandler()->moduleExists($provider)) {
        $dependencies['module'][] = $provider;
      }
      elseif ($this->themeHandler()->themeExists($provider)) {
        $dependencies['theme'][] = $provider;
      }
    }

    // Add the config dependencies.     if ($config_dependencies) {
      $dependencies = NestedArray::mergeDeep($dependencies$config_dependencies);
    }

    // If a plugin is dependent, calculate its dependencies.     if ($instance instanceof DependentPluginInterface && $plugin_dependencies = $instance->calculateDependencies()) {
      
$container->set('entity_type.manager', $this->entityTypeManager);
    $container->set('module_handler', $this->moduleHandler->reveal());
    $container->set('theme_handler', $this->themeHandler->reveal());
    $container->set('uuid', $this->uuid);
    \Drupal::setContainer($container);
  }

  /** * @covers ::calculateDependencies */
  public function testCalculateDependencies() {
    $this->themeHandler->themeExists('stark')->willReturn(TRUE);
    $values = ['theme' => 'stark'];
    // Mock the entity under test so that we can mock getPluginCollections().     $entity = $this->getMockBuilder('\Drupal\block\Entity\Block')
      ->setConstructorArgs([$values$this->entityTypeId])
      ->onlyMethods(['getPluginCollections'])
      ->getMock();
    // Create a configurable plugin that would add a dependency.     $instance_id = $this->randomMachineName();
    $this->moduleHandler->moduleExists('test')->willReturn(TRUE);
    $instance = new TestConfigurablePlugin([]$instance_id['provider' => 'test']);

    
/** * @covers ::getDependencies * @covers ::calculateDependencies * * @dataProvider providerCalculateDependenciesWithPluginCollections */
  public function testCalculateDependenciesWithPluginCollections($definition$expected_dependencies) {
    $this->moduleHandler->moduleExists('the_provider_of_the_entity_type')->willReturn(TRUE);
    $this->moduleHandler->moduleExists('test')->willReturn(TRUE);
    $this->moduleHandler->moduleExists('test_theme')->willReturn(FALSE);

    $this->themeHandler->themeExists('test_theme')->willReturn(TRUE);

    $values = [];
    $this->entity = $this->getMockBuilder('\Drupal\Tests\Core\Config\Entity\Fixtures\ConfigEntityBaseWithPluginCollections')
      ->setConstructorArgs([$values$this->entityTypeId])
      ->onlyMethods(['getPluginCollections'])
      ->getMock();

    // Create a configurable plugin that would add a dependency.     $instance_id = $this->randomMachineName();
    $instance = new TestConfigurablePlugin([]$instance_id$definition);

    
// Library and template overrides potentially change for the default theme     // when the admin theme is changed.     if ($config_name === 'system.theme' && $event->isChanged('admin')) {
      $this->cacheTagsInvalidator->invalidateTags(['library_info', 'theme_registry']);
    }

    // Theme-specific settings, check if this matches a theme settings     // configuration object (THEME_NAME.settings), in that case, clear the     // rendered cache tag.     if (preg_match('/^([^\.]*)\.settings$/', $config_name$matches)) {
      if ($this->themeHandler->themeExists($matches[1])) {
        $this->cacheTagsInvalidator->invalidateTags(['rendered']);
      }
    }
  }

  /** * {@inheritdoc} */
  public static function getSubscribedEvents(): array {
    $events[ConfigEvents::SAVE][] = ['onSave'];
    return $events;
  }
$core['theme']['test_theme_theme'] = 0;
    $sync->write('core.extension', $core);
    $sync->deleteAll('syslog.');
    $theme = $sync->read('system.theme');
    $theme['default'] = 'test_theme_theme';
    $sync->write('system.theme', $theme);
    $this->drupalGet('admin/config/development/configuration');
    $this->submitForm([], 'Import all');
    $this->assertSession()->pageTextContains('The configuration was imported successfully.');
    $this->rebuildContainer();
    $this->assertFalse(\Drupal::moduleHandler()->moduleExists('syslog'), 'The syslog module has been uninstalled.');
    $this->assertFalse(\Drupal::service('theme_handler')->themeExists('stark'), 'The stark theme has been uninstalled.');
    $this->assertTrue(\Drupal::service('theme_handler')->themeExists('test_theme_theme'), 'The test_theme_theme theme has been installed.');
  }

}
$this->moduleHandler->moduleExists('theme_a')->willReturn(FALSE);
    $this->moduleHandler->moduleExists('core')->willReturn(FALSE);
    $this->moduleHandler->moduleExists('invalid_provider')->willReturn(FALSE);

    $module_a = new Extension('vfs://root', 'module', 'modules/module_a/module_a.layouts.yml');
    $this->moduleHandler->getModule('module_a')->willReturn($module_a);
    $this->moduleHandler->getModuleDirectories()->willReturn(['module_a' => vfsStream::url('root/modules/module_a')]);
    $this->moduleHandler->alter('layout', Argument::type('array'))->shouldBeCalled();

    $this->themeHandler = $this->prophesize(ThemeHandlerInterface::class);

    $this->themeHandler->themeExists('theme_a')->willReturn(TRUE);
    $this->themeHandler->themeExists('core')->willReturn(FALSE);
    $this->themeHandler->themeExists('invalid_provider')->willReturn(FALSE);

    $theme_a = new Extension('vfs://root', 'theme', 'themes/theme_a/theme_a.layouts.yml');
    $this->themeHandler->getTheme('theme_a')->willReturn($theme_a);
    $this->themeHandler->getThemeDirectories()->willReturn(['theme_a' => vfsStream::url('root/themes/theme_a')]);

    $this->cacheBackend = $this->prophesize(CacheBackendInterface::class);

    $namespaces = new \ArrayObject(['Drupal\Core' => vfsStream::url('root/core/lib/Drupal/Core')]);
    $this->layoutPluginManager = new LayoutPluginManager($namespaces$this->cacheBackend->reveal()$this->moduleHandler->reveal()$this->themeHandler->reveal());
  }
if (!isset($this->discovery)) {
      $directories = $this->getScanDirectories();
      $this->discovery = new DirectoryWithMetadataPluginDiscovery($directories, 'sdc', $this->fileSystem);
    }
    return $this->discovery;
  }

  /** * {@inheritdoc} */
  protected function providerExists($provider) {
    return $this->moduleHandler->moduleExists($provider) || $this->themeHandler->themeExists($provider);
  }

  /** * {@inheritdoc} */
  protected function alterDefinitions(&$definitions) {
    // Save in the definition whether this is a module or a theme. This is     // important because when creating the plugin instance (the Component     // object) we'll need to negotiate based on the active theme.     $definitions = array_map([$this, 'alterDefinition']$definitions);
    // Validate the definition after alterations.
/** * Tests trying to install a deprecated theme. * * @covers \Drupal\Core\Extension\ThemeInstaller::install * * @group legacy */
  public function testInstallDeprecated() {
    $this->expectDeprecation("The theme 'deprecated_theme_test' is deprecated. See https://example.com/deprecated");
    $this->themeInstaller()->install(['deprecated_theme_test']);
    $this->assertTrue(\Drupal::service('theme_handler')->themeExists('deprecated_theme_test'));
  }

  /** * Data provider for testInstallThemeWithUnmetModuleDependencies(). */
  public function providerTestInstallThemeWithUnmetModuleDependencies() {
    return [
      'theme with uninstalled module dependencies' => [
        'test_theme_depending_on_modules',
        [],
        "Unable to install theme: 'test_theme_depending_on_modules' due to unmet module dependencies: 'test_module_required_by_theme, test_another_module_required_by_theme'.",
      ],
      $discovery = new YamlDiscoveryDecorator($discovery, 'help_topics', $module_directories);
      $discovery = new ContainerDerivativeDiscoveryDecorator($discovery);
      $this->discovery = $discovery;
    }
    return $this->discovery;
  }

  /** * {@inheritdoc} */
  protected function providerExists($provider) {
    return $this->moduleHandler->moduleExists($provider) || $this->themeHandler->themeExists($provider);
  }

  /** * {@inheritdoc} */
  protected function findDefinitions() {
    $definitions = parent::findDefinitions();

    // At this point the plugin list only contains valid plugins. Ensure all     // related plugins exist and the relationship is bi-directional. This     // ensures topics are listed on their related topics.
Home | Imprint | This part of the site doesn't use cookies.