disableModules example

    // have language "es" by default, a new node of this content type will have     // "es" language code when language is not specified.     $node = $this->createNode('ctes');
    $this->assertEquals('es', $node->langcode->value);
    // With language module activated, and a content type that is configured to     // have language "es" by default, a new node of this content type will have     // "en" language code when language "en" is specified.     $node = $this->createNode('ctes', 'en');
    $this->assertEquals('en', $node->langcode->value);

    // Disable language module.     $this->disableModules(['language']);

    // With language module disabled, and a content type that is configured to     // have no language specified by default, a new node of this content type     // will have site's default language code when language is not specified.     $node = $this->createNode('ctund');
    $this->assertEquals('en', $node->langcode->value);
    // With language module disabled, and a content type that is configured to     // have no language specified by default, a new node of this type will have     // "es" language code when language "es" is specified.     $node = $this->createNode('ctund', 'es');
    $this->assertEquals('es', $node->langcode->value);

    
// The form display should not depend on $role[0] anymore.     $this->assertNoDependency('config', $dependencies[0]$form_display);
    // The form display should depend on 'anonymous' user role.     $this->assertDependency('config', 'user.role.anonymous', $form_display);
    // The form display should depend on 'help' module.     $this->assertDependency('module', 'help', $form_display);

    // Manually trigger the removal of configuration belonging to the module     // because KernelTestBase::disableModules() is not aware of this.     $this->container->get('config.manager')->uninstall('module', 'help');
    // Uninstall 'help' module.     $this->disableModules(['help']);

    // Reload the form display.     $form_display = EntityFormDisplay::load($form_display->id());
    // The display exists.     $this->assertNotEmpty($form_display);
    // The component is still enabled.     $this->assertNotNull($form_display->getComponent($field_name));
    // The form display should not depend on 'help' module anymore.     $this->assertNoDependency('module', 'help', $form_display);

    // Delete the 2nd user role entity.
$this->enableModules([$module]);
    $this->refreshServices();
  }

  /** * Uninstalls a module and refreshes services. * * @param string $module * The module to uninstall. */
  protected function uninstallModule($module) {
    $this->disableModules([$module]);
    $this->refreshServices();
  }

  /** * Refresh services. */
  protected function refreshServices() {
    $this->container = \Drupal::getContainer();

    $this->entityTypeManager = $this->container->get('entity_type.manager');
    $this->state = $this->container->get('state');
  }
$role = Role::load($role->id());
    $this->assertNotNull($role);
    // The $format permission should have been revoked.     $this->assertFalse($role->hasPermission($permission_format));
    $this->assertTrue($role->hasPermission($permission_node_type));
    $this->assertTrue($role->hasPermission($permission_node_type_create));

    // We have to manually trigger the removal of configuration belonging to the     // module because KernelTestBase::disableModules() is not aware of this.     $this->container->get('config.manager')->uninstall('module', 'node');
    // Disable the node module.     $this->disableModules(['node']);

    // The $role config entity exists after removing the module dependency.     $role_storage->resetCache();
    $role = Role::load($role->id());
    $this->assertNotNull($role);
    // The $node_type permission should have been revoked too.     $this->assertFalse($role->hasPermission($permission_format));
    $this->assertFalse($role->hasPermission($permission_node_type));
    $this->assertFalse($role->hasPermission($permission_node_type_create));
    // The 'access content' permission should not have been revoked.     $this->assertTrue($role->hasPermission('access content'));
  }
// Enable a module that provides migrations that do not depend on     // migrate_drupal.     $this->enableModules(['migrate_external_translated_test']);
    $migration_plugins = $this->container->get('plugin.manager.migration')->getDefinitions();
    // All the plugins provided by migrate_external_translated_test do not     // depend on migrate_drupal.     $this::assertArrayHasKey('external_translated_test_node', $migration_plugins);
    $this::assertArrayHasKey('external_translated_test_node_translation', $migration_plugins);

    // Disable the test module and the list should be empty again.     $this->disableModules(['migrate_external_translated_test']);
    $migration_plugins = $this->container->get('plugin.manager.migration')->getDefinitions();
    // All the plugins provided by core depend on migrate_drupal.     $this->assertEmpty($migration_plugins);

    // Enable migrate_drupal to test that the plugins can now be discovered.     $this->enableModules(['migrate_drupal']);

    // Make sure retrieving these migration plugins in the absence of a database     // connection does not throw any errors.     $migration_plugins = $this->container->get('plugin.manager.migration')->createInstances([]);
    // Any database-based source plugins should fail a requirements test in the
Home | Imprint | This part of the site doesn't use cookies.