uninstall example


  public function testRouteRebuild() {
    // Remove the routing table manually to ensure it can be created lazily     // properly.     Database::getConnection()->schema()->dropTable('router');

    $this->container->get('module_installer')->install(['router_test']);
    $route = $this->container->get('router.route_provider')->getRouteByName('router_test.1');
    $this->assertEquals('/router_test/test1', $route->getPath());

    $this->container->get('module_installer')->uninstall(['router_test']);
    $this->expectException(RouteNotFoundException::class);
    $this->container->get('router.route_provider')->getRouteByName('router_test.1');
  }

  /** * Tests config changes by hook_install() are saved for dependent modules. * * @covers ::install */
  public function testConfigChangeOnInstall() {
    // Install the child module so the parent is installed automatically.
$this->assertFalse(isset($GLOBALS['hook_config_test']['delete']));

    // Install the schema test module.     $this->enableModules(['config_schema_test']);
    $this->installConfig(['config_schema_test']);

    // After module installation the new schema should exist.     $this->assertTrue(\Drupal::service('config.typed')->hasConfigSchema('config_schema_test.someschema'), 'Configuration schema for config_schema_test.someschema exists.');

    // Test that uninstalling configuration removes configuration schema.     $this->config('core.extension')->set('module', [])->save();
    \Drupal::service('config.manager')->uninstall('module', 'config_test');
    $this->assertFalse(\Drupal::service('config.typed')->hasConfigSchema('config_schema_test.someschema'), 'Configuration schema for config_schema_test.someschema does not exist.');
  }

  /** * Tests that collections are ignored if the event does not return anything. */
  public function testCollectionInstallationNoCollections() {
    // Install the test module.     $this->enableModules(['config_collection_install_test']);
    $this->installConfig(['config_collection_install_test']);
    /** @var \Drupal\Core\Config\StorageInterface $active_storage */
    
Node::load(56)->uuid(),
      Node::load(57)->uuid(),
      Node::load(58)->uuid(),
      Node::load(59)->uuid(),
      Node::load(60)->uuid(),
    ]$output_uuids);
    // 25. Test collection count.     $this->container->get('module_installer')->install(['jsonapi_test_collection_count']);
    $collection_output = Json::decode($this->drupalGet('/jsonapi/node/article'));
    $this->assertSession()->statusCodeEquals(200);
    $this->assertEquals(61, $collection_output['meta']['count']);
    $this->container->get('module_installer')->uninstall(['jsonapi_test_collection_count']);

    // Test documentation filtering examples.     // 1. Only get published nodes.     $filter = [
      'status-filter' => [
        'condition' => [
          'path' => 'status',
          'value' => 1,
        ],
      ],
    ];
    
    // placeholder and previews are not replaced and we can reliably test their     // presence.     $this->assertSession()->elementExists('css', '#placeholder-preview-twig-container [data-big-pipe-placeholder-id] > .i-am-taking-up-space');
    $this->assertSession()->elementTextEquals('css', '#placeholder-preview-twig-container [data-big-pipe-placeholder-id] > .i-am-taking-up-space', 'LOOK AT ME I AM CONSUMING SPACE FOR LATER');
    $this->assertSession()->elementTextNotContains('css', '#placeholder-preview-twig-container', $display_name);

    $this->assertSession()->pageTextContains('There is a lamb and there is a puppy');
    $this->assertSession()->elementTextEquals('css', '#placeholder-render-array-container [data-big-pipe-placeholder-id] > #render-array-preview', 'There is a lamb and there is a puppy');
    $this->assertSession()->elementTextNotContains('css', '#placeholder-render-array-container', 'Yarhar llamas forever!');

    // Uninstall big_pipe_bypass_js.     \Drupal::service('module_installer')->uninstall(['big_pipe_bypass_js']);
    $this->rebuildAll();
    $this->drupalGet('big_pipe_test_preview');
    $this->assertSession()->waitForElementRemoved('css', '[data-big-pipe-placeholder-id]', 20000);
    $this->assertSession()->elementTextContains('css', '#placeholder-preview-twig-container', $display_name);
    $this->assertSession()->pageTextNotContains('LOOK AT ME I AM CONSUMING SPACE FOR LATER');

    $this->assertSession()->elementTextContains('css', '#placeholder-render-array-container marquee', 'Yarhar llamas forever!');
    $this->assertSession()->pageTextNotContains('There is a lamb and there is a puppy');
  }

}
return $path;
    }

    public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
    {
        $installPath = $this->getPackageBasePath($package);
        $io = $this->io;
        $outputStatus = function D) use ($io$installPath) {
            $io->write(sprintf('Deleting %s - %s', $installPath, !file_exists($installPath) ? '<comment>deleted</comment>' : '<error>not deleted</error>'));
        };

        $promise = parent::uninstall($repo$package);

        // Composer v2 might return a promise here         if ($promise instanceof PromiseInterface) {
            return $promise->then($outputStatus);
        }

        // If not, execute the code right away as parent::uninstall executed synchronously (composer v1, or v2 without async)         $outputStatus();

        return null;
    }

    
'entity_type' => 'taxonomy_term',
      'bundle' => $vocabulary->id(),
      'label' => $this->randomMachineName() . '_label',
    ];
    FieldConfig::create($field_definition)->save();

    // Remove the third party setting from the memory copy of the vocabulary.     // We keep this invalid copy around while the taxonomy module is not even     // installed for testing below.     $vocabulary->unsetThirdPartySetting('taxonomy_crud', 'foo');

    $this->container->get('module_installer')->uninstall(['taxonomy']);
    $this->container->get('module_installer')->install(['taxonomy']);

    // Now create a vocabulary with the same name. All fields connected to this     // vocabulary name should have been removed when the module was uninstalled.     // Creating a new field with the same name and an instance of this field on     // the same bundle name should be successful.     $vocabulary->enforceIsNew()->save();
    FieldStorageConfig::create($storage_definition)->save();
    FieldConfig::create($field_definition)->save();
  }

}
foreach (array_keys($schema) as $storage_definition_name) {
      [$entity_type_id] = explode('.', $storage_definition_name);
      if (in_array($entity_type_id$entity_type_ids)) {
        $entity_type_id_count++;
      }
    }

    // Ensure that there are storage definitions from the entity_test module.     $this->assertNotEquals(0, $entity_type_id_count, 'There are storage definitions provided by the entity_test module in the schema.');

    // Uninstall the entity_test module.     $this->container->get('module_installer')->uninstall(['entity_test']);

    // Get a list of all the entities in the schema.     $key_value_store = \Drupal::keyValue('entity.storage_schema.sql');
    $schema = $key_value_store->getAll();

    // Count the storage definitions that come from entity types provided by     // the entity_test module.     $entity_type_id_count = 0;

    foreach (array_keys($schema) as $storage_definition_name) {
      [$entity_type_id] = explode('.', $storage_definition_name);
      
// Check language negotiation results.     $this->drupalGet('');
    $last = $this->container->get('state')->get('language_test.language_negotiation_last');
    foreach ($this->languageManager()->getDefinedLanguageTypes() as $type) {
      $langcode = $last[$type];
      $value = $type == LanguageInterface::TYPE_CONTENT || str_contains($type, 'test') ? 'it' : 'en';
      $this->assertEquals($langcode$valuenew FormattableMarkup('The negotiated language for %type is %language', ['%type' => $type, '%language' => $value]));
    }

    // Uninstall language_test and check that everything is set back to the     // original status.     $this->container->get('module_installer')->uninstall(['language_test']);
    $this->rebuildContainer();

    // Check that only the core language types are available.     foreach ($this->languageManager()->getDefinedLanguageTypes() as $type) {
      $this->assertStringNotContainsString('test', $typenew FormattableMarkup('The %type language is still available', ['%type' => $type]));
    }

    // Check that fixed language types are properly configured, even those     // previously set to configurable.     $this->checkFixedLanguageTypes();

    
$keyvalue_update->set('key', 'some value');
    $keyvalue_update_available_release = $this->container->get('keyvalue.expirable')->get('update_available_release');
    $keyvalue_update_available_release->set('key', 'some value');
    $this->container->get('module_installer')->install(['help']);
    $this->assertNull($keyvalue_update->get('key'));
    $this->assertNull($keyvalue_update_available_release->get('key'));

    // Setting new values in both key stores, then uninstalling the module and     // testing if these new key values are cleared.     $keyvalue_update->set('another_key', 'some value');
    $keyvalue_update_available_release->set('another_key', 'some value');
    $this->container->get('module_installer')->uninstall(['help']);
    $this->assertNull($keyvalue_update->get('another_key'));
    $this->assertNull($keyvalue_update_available_release->get('another_key'));
  }

}
'id' => 'entity2',
        'dependencies' => [
          'enforced' => [
            'config' => [$entity1->getConfigDependencyName()],
          ],
        ],
      ]
    );
    $entity2->save();
    // Test that doing a config uninstall of the node module deletes entity2     // since it is dependent on entity1 which is dependent on the node module.     $config_manager->uninstall('module', 'node');
    $this->assertNull($storage->load('entity1'), 'Entity 1 deleted');
    $this->assertNull($storage->load('entity2'), 'Entity 2 deleted');
  }

  /** * Data provider for self::testConfigEntityUninstallComplex(). */
  public function providerConfigEntityUninstallComplex() {
    // Ensure that alphabetical order has no influence on dependency fixing and     // removal.     return [
      [[
'user.permissions',
    ];
    $this->assertResourceErrorResponse(403, $message$collection_filter_url$response, FALSE, $expected_cache_tags$expected_cache_contexts, FALSE, 'MISS');
    // And ensure the it is allowed when the proper permission is granted.     $this->grantPermissionsToTestedRole(['filter by spotlight field']);
    $response = $this->request('GET', $collection_filter_url$request_options);
    $doc = Json::decode((string) $response->getBody());
    $this->assertCount(1, $doc['data']);
    $this->assertSame($referencing_entity->uuid()$doc['data'][0]['id']);
    $this->revokePermissionsFromTestedRole(['filter by spotlight field']);

    $this->assertTrue($this->container->get('module_installer')->uninstall(['jsonapi_test_field_filter_access'], TRUE), 'Uninstalled modules.');

    return $referencing_entity;
  }

  /** * Implements ::testCollectionFilterAccess() for permission + status access. * * @param string $label_field_name * The entity type's label field name. * @param string $view_permission * The entity type's permission that grants 'view' access (for published * entities of this type). * @param string $admin_permission * The entity type's permission that grants 'view' access (for unpublished * entities of this type). * * @return \Drupal\Core\Entity\EntityInterface * The referencing entity. */
$this->createMigrationCollection($pluginBaseClass),
            $keepUserData
        );
        $uninstallContext->setAutoMigrate(false);

        $this->eventDispatcher->dispatch(new PluginPreUninstallEvent($plugin$uninstallContext));

        if (!$shopwareContext->hasState(self::STATE_SKIP_ASSET_BUILDING)) {
            $this->assetInstaller->removeAssetsOfBundle($pluginBaseClassString);
        }

        $pluginBaseClass->uninstall($uninstallContext);

        if (!$uninstallContext->keepUserData()) {
            $pluginBaseClass->removeMigrations();
            $this->systemConfigService->deletePluginConfiguration($pluginBaseClass);
        }

        $pluginId = $plugin->getId();
        $this->updatePluginData(
            [
                'id' => $pluginId,
                'active' => false,
                
    $module_data = \Drupal::service('extension.list.module')->getList();
    $this->assertFalse(isset($module_data['book']->info['required']), 'The book module is not required.');

    $node = Node::create(['title' => $this->randomString(), 'type' => $content_type->id()]);
    $node->save();
    // One node exists but is not part of a book therefore the book module is     // not required.     $validation_reasons = \Drupal::service('module_installer')->validateUninstall(['book']);
    $this->assertEquals([]$validation_reasons, 'The book module is not required.');

    // Uninstall the Book module and check the node type is deleted.     \Drupal::service('module_installer')->uninstall(['book']);
    $this->assertNull(NodeType::load('book'), "The book node type does not exist.");
  }

}
protected static $modules = ['menu_ui'];

  /** * {@inheritdoc} */
  protected $defaultTheme = 'stark';

  /** * Tests Menu uninstall. */
  public function testMenuUninstall() {
    \Drupal::service('module_installer')->uninstall(['menu_ui']);

    \Drupal::entityTypeManager()->getStorage('menu')->resetCache(['admin']);

    $this->assertNotEmpty(Menu::load('admin'), 'The \'admin\' menu still exists after uninstalling Menu UI module.');
  }

}
/** * Tests if comment module uninstall fails if the field exists. */
  public function testCommentUninstallWithField() {
    // Ensure that the field exists before uninstalling.     $field_storage = FieldStorageConfig::loadByName('comment', 'comment_body');
    $this->assertNotNull($field_storage);

    // Uninstall the comment module which should trigger an exception.     $this->expectException(ModuleUninstallValidatorException::class);
    $this->expectExceptionMessage('The following reasons prevent the modules from being uninstalled: The <em class="placeholder">Comments</em> field type is used in the following field: node.comment');
    $this->container->get('module_installer')->uninstall(['comment']);
  }

  /** * Tests if uninstallation succeeds if the field has been deleted beforehand. */
  public function testCommentUninstallWithoutField() {
    // Tests if uninstall succeeds if the field has been deleted beforehand.     // Manually delete the comment_body field before module uninstall.     FieldStorageConfig::loadByName('comment', 'comment_body')->delete();

    // Check that the field is now deleted.
Home | Imprint | This part of the site doesn't use cookies.