enableModules example

public function testEmptyHookHelp() {
    $all_modules = \Drupal::service('extension.list.module')->getList();
    $all_modules = array_filter($all_modulesfunction D$module) {
      // Filter contrib, hidden, already enabled modules and modules in the       // Testing package.       if ($module->origin !== 'core' || !empty($module->info['hidden']) || $module->status == TRUE || $module->info['package'] == 'Testing') {
        return FALSE;
      }
      return TRUE;
    });

    $this->enableModules(array_keys($all_modules));
    $this->installEntitySchema('menu_link_content');

    $route = \Drupal::service('router.route_provider')->getRouteByName('<front>');
    \Drupal::service('module_handler')->invokeAll('help', ['<front>', new RouteMatch('<front>', $route)]);
  }

}

  protected static $modules = ['language', 'config_events_test'];

  /** * Tests the configuration events are not fired during install of overrides. */
  public function testLanguageConfigOverrideInstall() {
    ConfigurableLanguage::createFromLangcode('de')->save();
    // Need to enable test module after creating the language otherwise saving     // the language will install the configuration.     $this->enableModules(['language_config_override_test']);
    \Drupal::state()->set('config_events_test.event', FALSE);
    $this->installConfig(['language_config_override_test']);
    $event_recorder = \Drupal::state()->get('config_events_test.event', FALSE);
    $this->assertFalse($event_recorder);
    $config = \Drupal::service('language.config_factory_override')->getOverride('de', 'language_config_override_test.settings');
    $this->assertEquals('Deutsch', $config->get('name'));
  }

}
$entities = $storage->loadMultiple();
    $this->assertEquals(['added_dependency']$entities['config_test_9']->getDependencies()['module']);
    $this->assertEquals(['added_dependency']$entities['config_test_14']->getDependencies()['module']);
    $this->assertEquals(1, $sandbox['#finished']);
    $this->assertCount(0, $sandbox['config_entity_updater']['entities']);
  }

  /** * @covers ::update */
  public function testUpdateException() {
    $this->enableModules(['entity_test']);
    $this->expectException(\InvalidArgumentException::class);
    $this->expectExceptionMessage('The provided entity type ID \'entity_test_mul_changed\' is not a configuration entity type');
    $updater = $this->container->get('class_resolver')->getInstanceFromDefinition(ConfigEntityUpdater::class);
    $sandbox = [];
    $updater->update($sandbox, 'entity_test_mul_changed');
  }

  /** * @covers ::update */
  public function testUpdateOncePerUpdateException() {
    


    // Asserts denormalizing the entity DOES yield the value we set:     // - when using the detailed representation     $core_normalization['field_test_boolean'][0]['value'] = TRUE;
    $assert_denormalization($core_normalization);
    // - and when using the shorthand representation     $core_normalization['field_test_boolean'][0] = TRUE;
    $assert_denormalization($core_normalization);

    // Install test module that contains a high-priority alternative normalizer.     $this->enableModules($test_modules);

    // Asserts normalizing the entity DOES NOT ANYMORE yield the value we set.     $core_normalization = $this->container->get('serializer')->normalize($this->entity, $format);
    $this->assertSame('👎', $core_normalization['field_test_boolean'][0]['value']);

    // Asserts denormalizing the entity DOES NOT ANYMORE yield the value we set:     // - when using the detailed representation     $core_normalization['field_test_boolean'][0]['value'] = '👍';
    $assert_denormalization($core_normalization);
    // - and when using the shorthand representation     $core_normalization['field_test_boolean'][0] = '👍';
    

      ],
    ];
  }

  /** * Tests detection of invalid CKEditor5PluginElementsSubsetInterface classes. * * @dataProvider providerProvidedElementsInvalidElementSubset */
  public function testProvidedElementsInvalidElementSubset(array $configured_subset, string $expected_exception_message): void {
    $this->enableModules(['ckeditor5_plugin_elements_subset']);

    // Configure the sneaky superset plugin.     $sneaky_plugin_id = 'ckeditor5_plugin_elements_subset_sneakySuperset';
    $text_editor = Editor::create([
      'format' => 'dummy',
      'editor' => 'ckeditor5',
      'settings' => [
        'plugins' => [
          $sneaky_plugin_id => ['configured_subset' => $configured_subset],
        ],
      ],
      
// Case 1: no text editor available:     // - listOptions() should return an empty list of options     // - getAttachments() should return an empty #attachments array (and not     // a JS settings structure that is empty)     $this->assertSame([]$this->editorManager->listOptions(), 'When no text editor is enabled, the manager works correctly.');
    $this->assertSame([]$this->editorManager->getAttachments([]), 'No attachments when no text editor is enabled and retrieving attachments for zero text formats.');
    $this->assertSame([]$this->editorManager->getAttachments(['filtered_html', 'full_html']), 'No attachments when no text editor is enabled and retrieving attachments for multiple text formats.');

    // Enable the Text Editor Test module, which has the Unicorn Editor and     // clear the editor manager's cache so it is picked up.     $this->enableModules(['editor_test']);
    $this->editorManager = $this->container->get('plugin.manager.editor');
    $this->editorManager->clearCachedDefinitions();

    // Case 2: a text editor available.     $this->assertSame('Unicorn Editor', (string) $this->editorManager->listOptions()['unicorn'], 'When some text editor is enabled, the manager works correctly.');

    // Case 3: a text editor available & associated (but associated only with     // the 'Full HTML' text format).     $unicorn_plugin = $this->editorManager->createInstance('unicorn');
    $editor = Editor::create([
      'format' => 'full_html',
      
/** * @var array */
  protected static $modules = ['system', 'path_alias'];

  /** * Tests the integrity of field plugin definitions. */
  public function testFieldPluginDefinitionIntegrity() {
    // Enable all core modules that provide field plugins, and their     // dependencies.     $this->enableModules(
      $this->modulesWithSubdirectory(
        'src' . DIRECTORY_SEPARATOR . 'Plugin' . DIRECTORY_SEPARATOR . 'Field'
      )
    );

    /** @var \Drupal\Component\Plugin\Discovery\DiscoveryInterface $field_type_manager */
    $field_type_manager = \Drupal::service('plugin.manager.field.field_type');

    /** @var \Drupal\Component\Plugin\Discovery\DiscoveryInterface $field_type_manager */
    $field_formatter_manager = \Drupal::service('plugin.manager.field.formatter');

    

  private $twigConfig = [];

  /** * Tests template inclusion extension checking. * * @see \Drupal\Core\Template\Loader\FilesystemLoader::findTemplate() */
  public function testTemplateInclusion(): void {
    $this->enableModules(['system']);
    /** @var \Drupal\Core\Render\RendererInterface $renderer */
    $renderer = \Drupal::service('renderer');

    $element['test'] = [
      '#type' => 'inline_template',
      '#template' => "{% include '@system/container.html.twig' %}",
    ];
    $this->assertSame("<div></div>\n", (string) $renderer->renderRoot($element));

    // Test that SQL files cannot be included in Twig templates by default.     $element = [];
    
// Check that the component has been removed from the entity displays.     $display = $display_repository->getViewDisplay('entity_test', 'entity_test');
    $this->assertNull($display->getComponent($field_name));
    $display = $display_repository->getViewDisplay('entity_test', 'entity_test', 'teaser');
    $this->assertNull($display->getComponent($field_name));
  }

  /** * Tests \Drupal\Core\Entity\EntityDisplayBase::onDependencyRemoval(). */
  public function testOnDependencyRemoval() {
    $this->enableModules(['field_plugins_test']);

    $field_name = 'test_field';
    // Create a field.     $field_storage = FieldStorageConfig::create([
      'field_name' => $field_name,
      'entity_type' => 'entity_test',
      'type' => 'text',
    ]);
    $field_storage->save();
    $field = FieldConfig::create([
      'field_storage' => $field_storage,
      
$this->assertSame($status$search_page->status());
    if (isset($expected_config)) {
      $configuration = $search_page->getPlugin()->getConfiguration();
      $this->assertSame($expected_config$configuration);
    }
  }

  /** * Tests migration of search status and settings to search page entity. */
  public function testSearchPage() {
    $this->enableModules(['node']);
    $this->installConfig(['search']);
    $this->executeMigration('d7_search_page');
    $configuration = [
      'rankings' => [
        'comments' => 0,
        'promote' => 0,
        'relevance' => 2,
        'sticky' => 0,
        'views' => 0,
      ],
    ];
    

    $violations = $typed_data->create($definition$value)->validate();
    $this->assertCount(0, $violations);
  }

  /** * Tests that valid keys can be inferred from the data definition. */
  public function testValidKeyInference(): void {
    // Install the System module and its config so that we can test that the     // validator infers the allowed keys from a defined schema.     $this->enableModules(['system']);
    $this->installConfig('system');

    $config = $this->container->get('config.typed')
      ->get('system.site');
    $config->getDataDefinition()
      ->addConstraint('ValidKeys', '<infer>');

    $data = $config->getValue();
    $data['invalid-key'] = "There's a snake in my boots.";
    $config->setValue($data);
    $violations = $config->validate();
    

  protected $workspaces = [];

  /** * Enables the Workspaces module and creates two workspaces. */
  protected function initializeWorkspacesModule() {
    // Enable the Workspaces module here instead of the static::$modules array     // so we can test it with default content.     $this->enableModules(['workspaces']);
    $this->container = \Drupal::getContainer();
    $this->entityTypeManager = \Drupal::entityTypeManager();
    $this->workspaceManager = \Drupal::service('workspaces.manager');

    $this->installEntitySchema('workspace');
    $this->installSchema('workspaces', ['workspace_association']);

    // Install the entity schema for supported entity types to ensure that the     // 'workspace' revision metadata field gets created.     foreach (array_keys($this->workspaceManager->getSupportedEntityTypes()) as $entity_type_id) {
      $this->installEntitySchema($entity_type_id);
    }
// Test reading the annotation. There should be two constraints, the defined     // constraint and the automatically added EntityChanged constraint.     $entity_type = $this->entityTypeManager->getDefinition('entity_test_constraints');
    $default_constraints = [
      'NotNull' => [],
      'EntityChanged' => NULL,
      'EntityUntranslatableFields' => NULL,
    ];
    $this->assertEquals($default_constraints$entity_type->getConstraints());

    // Enable our test module and test extending constraints.     $this->enableModules(['entity_test_constraints']);
    $this->container->get('module_handler')->resetImplementations();

    $extra_constraints = ['Test' => []];
    $this->state->set('entity_test_constraints.build', $extra_constraints);
    // Re-fetch the entity type manager from the new container built after the     // new modules were enabled.     $this->entityTypeManager = $this->container->get('entity_type.manager');
    $this->entityTypeManager->clearCachedDefinitions();
    $entity_type = $this->entityTypeManager->getDefinition('entity_test_constraints');
    $this->assertEquals($default_constraints + $extra_constraints$entity_type->getConstraints());

    
$form_state = new FormState();
    $form_state->set('media_library_state', $state);
    $this->expectException(\InvalidArgumentException::class);
    $this->expectExceptionMessage("The 'header_image' media type does not exist.");
    \Drupal::formBuilder()->buildForm(FileUploadForm::class$form_state);
  }

  /** * Tests overwriting of the add form. */
  public function testDifferentAddForm() {
    $this->enableModules(['media_library_form_overwrite_test']);

    $entity_type_manager = \Drupal::entityTypeManager();
    $image = $entity_type_manager->getStorage('media_type')->load('image');

    $image_source_definition = $image->getSource()->getPluginDefinition();

    // Assert the overwritten form class is set to the media source.     $this->assertSame(TestAddForm::class$image_source_definition['forms']['media_library_add']);
  }

}
// Check that the component has been removed from the entity displays.     $display = $display_repository->getFormDisplay('entity_test', 'entity_test');
    $this->assertNull($display->getComponent($field_name));
    $display = $display_repository->getFormDisplay('entity_test', 'entity_test', 'compact');
    $this->assertNull($display->getComponent($field_name));
  }

  /** * Tests \Drupal\Core\Entity\EntityDisplayBase::onDependencyRemoval(). */
  public function testOnDependencyRemoval() {
    $this->enableModules(['field_plugins_test']);

    $field_name = 'test_field';
    // Create a field.     $field_storage = FieldStorageConfig::create([
      'field_name' => $field_name,
      'entity_type' => 'entity_test',
      'type' => 'text',
    ]);
    $field_storage->save();
    $field = FieldConfig::create([
      'field_storage' => $field_storage,
      
Home | Imprint | This part of the site doesn't use cookies.