diff --git a/package_manager/tests/modules/package_manager_test_api/src/SystemChangeRecorder.php b/package_manager/tests/modules/package_manager_test_api/src/SystemChangeRecorder.php index de50090860736b29ff4169003e73a0571f7594d2..7944040ce6da97556bc6180d03fd38f1423c1ab2 100644 --- a/package_manager/tests/modules/package_manager_test_api/src/SystemChangeRecorder.php +++ b/package_manager/tests/modules/package_manager_test_api/src/SystemChangeRecorder.php @@ -82,6 +82,12 @@ class SystemChangeRecorder implements EventSubscriberInterface { * The stage event. */ public function recordSystemState(StageEvent $event): void { + // The rest of this method is strongly coupled to updated_module, so if it + // isn't installed, bail out now. + if (!\Drupal::moduleHandler()->moduleExists('updated_module')) { + return; + } + $results = []; // Call a function in a loaded file to ensure it doesn't get reloaded after diff --git a/package_manager/tests/src/Build/PackageInstallTest.php b/package_manager/tests/src/Build/PackageInstallTest.php new file mode 100644 index 0000000000000000000000000000000000000000..831e62375955f8205c83a1f10b25b6f99eb3b841 --- /dev/null +++ b/package_manager/tests/src/Build/PackageInstallTest.php @@ -0,0 +1,46 @@ +<?php + +namespace Drupal\Tests\package_manager\Build; + +/** + * Tests installing packages in a staging area. + * + * @group package_manager + */ +class PackageInstallTest extends TemplateProjectTestBase { + + /** + * Tests installing packages in a staging area. + */ + public function testPackageInstall(): void { + $this->createTestProject('RecommendedProject'); + + $this->addRepository('alpha', __DIR__ . '/../../fixtures/alpha/1.0.0'); + + $this->installQuickStart('minimal'); + $this->formLogin($this->adminUsername, $this->adminPassword); + $this->installModules(['package_manager_test_api']); + + // Use the API endpoint to create a stage and install alpha 1.0.0. We ask + // the API to return the contents of composer.json file of installed module, + // so we can assert that the module was installed with the expected version. + // @see \Drupal\package_manager_test_api\ApiController::run() + $query = http_build_query([ + 'runtime' => [ + 'drupal/alpha:1.0.0', + ], + 'files_to_return' => [ + 'web/modules/contrib/alpha/composer.json', + ], + ]); + $this->visit("/package-manager-test-api?$query"); + $mink = $this->getMink(); + $mink->assertSession()->statusCodeEquals(200); + + $file_contents = $mink->getSession()->getPage()->getContent(); + $file_contents = json_decode($file_contents, TRUE); + + $this->assertArrayHasKey('web/modules/contrib/alpha/composer.json', $file_contents); + } + +}