Create a test (or tests) to prove Package Manager works with submodules as implemented by packages.drupal.org

Created on 21 November 2022, about 2 years ago
Updated 7 December 2023, 12 months ago

Problem/Motivation

See #3312289-34: Svelte UI for install controllers . This specific problem was caused by #3322931: OverwriteExistingPackagesValidator does not handle packages with no install path

But we should have test that proves in 1 place that it works with submodules

Drupal submodules are metadata packages that do not have file contents of their own but do have requirements. If you require a drupal submodule directly it will bring in the metapackage which will require the main project.

for instance admin_toolbar has a sub-module admin_toolbar_tools

see

➜  au-contrib git:(10.0.x) ✗ composer show drupal/admin_toolbar_tools -a  
name     : drupal/admin_toolbar_tools
descrip. : Adds menu links like Flush cache, Run cron, Run updates, and Logout under Drupal icon.
keywords : 
versions : 3.x-dev, 3.2.1, ..... // 💁‍♂️ Removed to be brief
type     : metapackage // 💁‍♂️ 
license  : GNU General Public License v2.0 or later (GPL-2.0-or-later) (OSI approved) https://spdx.org/licenses/GPL-2.0-or-later.html#licenseText
homepage : https://www.drupal.org/project/admin_toolbar
source   : []  // 💁‍♂️ Has no source of its own
dist     : []  
names    : drupal/admin_toolbar_tools

support
source : https://git.drupalcode.org/project/admin_toolbar

requires
drupal/admin_toolbar * //💁‍♂️ Requires the main project it belongs to
drupal/core ^8.8.0 || ^9.0

(emoji comments mine 😜)

So if you
composer require drupal/admin_toolbar_tools
Your installed.php would have

'drupal/admin_toolbar' => array(
            'pretty_version' => '3.2.1',
            'version' => '3.2.1.0',
            'reference' => '3.2.1',
            'type' => 'drupal-module',
            'install_path' => __DIR__ . '/../../web/modules/contrib/admin_toolbar', // 💁‍♂️ Main project has install path
            'aliases' => array(),
            'dev_requirement' => false,
        ),
        'drupal/admin_toolbar_tools' => array(
            'pretty_version' => '3.2.1',
            'version' => '3.2.1.0',
            'reference' => NULL,
            'type' => 'metapackage',
            'install_path' => NULL, // 💁‍♂️ Sub module has NO install path
            'aliases' => array(),
            'dev_requirement' => false,
        ),

Steps to reproduce

Proposed resolution

Create a test to prove we handle this issue

Since what we want to prove is that package_manager will work with how drupal.org sets up sub-modules as metapackages which require the main module it doesn't make sense to do this in kernel test where we by-pass composer.

In \Drupal\Tests\package_manager\Build\PackageInstallTest::testPackageInstall where we already install a module via package manager lets additionally install a metapackage and document that this is test/demo of how installing a sub-module would work.

We will need 2 additional repos, main_module and main_module_submodule
We can setup main_module with the existing \Drupal\Tests\package_manager\Build\TemplateProjectTestBase::addRepository
For main_module_submodule we will need a new addMetaPackageRepistory(). This will need not need a path to a source folder because metapackages don't have sources(see "Problem" above). It will be something like this

/**
   * Adds a metapackage repository to the test site.
   *
   * @param string $name
   *   An arbitrary name for the repository.
   * @param string[] $requires
   *   The names of the repository requires.
   * @param string $working_directory
   *   (optional) The Composer working directory. Defaults to 'project'.
   */
  protected function addMetaPackageRepository(string $name, array $requires, $working_directory = 'project')

In the test we should require main_module_submodule(the metapackage) and we should confirm that main_module gets installed

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Fixed

Version

3.0

Component

Package Manager

Created by

🇮🇳India narendraR Jaipur, India

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024