class PackageInstallTest

Tests installing packages in a stage directory.

@group package_manager @internal

Hierarchy

Expanded class hierarchy of PackageInstallTest

File

core/modules/package_manager/tests/src/Build/PackageInstallTest.php, line 13

Namespace

Drupal\Tests\package_manager\Build
View source
class PackageInstallTest extends TemplateProjectTestBase {
    
    /**
     * Tests installing packages in a stage directory.
     */
    public function testPackageInstall() : void {
        $this->createTestProject('RecommendedProject');
        $this->setReleaseMetadata([
            'alpha' => __DIR__ . '/../../fixtures/release-history/alpha.1.1.0.xml',
        ]);
        $this->addRepository('alpha', $this->copyFixtureToTempDirectory(__DIR__ . '/../../fixtures/build_test_projects/alpha/1.0.0'));
        // Repository definitions affect the lock file hash, so update the hash to
        // ensure that Composer won't complain that the lock file is out of sync.
        $this->runComposer('composer update --lock', 'project');
        // Use the API endpoint to create a stage and install alpha 1.0.0.
        $this->makePackageManagerTestApiRequest('/package-manager-test-api', [
            'runtime' => [
                'drupal/alpha:1.0.0',
            ],
        ]);
        // Assert the module was installed.
        $this->assertFileEquals(__DIR__ . '/../../fixtures/build_test_projects/alpha/1.0.0/composer.json', $this->getWebRoot() . '/modules/contrib/alpha/composer.json');
        $this->assertRequestedChangesWereLogged([
            'Install drupal/alpha 1.0.0',
        ]);
        $this->assertAppliedChangesWereLogged([
            'Installed drupal/alpha 1.0.0',
        ]);
    }
    
    /**
     * Tests installing a Drupal submodule.
     *
     * This test installs a submodule using a set-up that mimics how
     * packages.drupal.org handles submodules. Submodules are Composer
     * metapackages which depend on the Composer package of the main module.
     */
    public function testSubModules() : void {
        $this->createTestProject('RecommendedProject');
        // Set up the release metadata for the main module. The submodule does not
        // have its own release metadata.
        $this->setReleaseMetadata([
            'main_module' => __DIR__ . '/../../fixtures/release-history/main_module.1.0.0.xml',
        ]);
        // Add repositories for Drupal modules which will contain the code for its
        // submodule also.
        $this->addRepository('main_module', $this->copyFixtureToTempDirectory(__DIR__ . '/../../fixtures/build_test_projects/main_module'));
        // Add a repository for the submodule of 'main_module'. Submodule
        // repositories are metapackages which have no code of their own but that
        // require the main module.
        $this->addRepository('main_module_submodule', $this->copyFixtureToTempDirectory(__DIR__ . '/../../fixtures/path_repos/main_module_submodule'));
        // Repository definitions affect the lock file hash, so update the hash to
        // ensure that Composer won't complain that the lock file is out of sync.
        $this->runComposer('composer update --lock', 'project');
        $this->makePackageManagerTestApiRequest('/package-manager-test-api', [
            'runtime' => [
                'drupal/main_module_submodule:1.0.0',
            ],
        ]);
        // Assert main_module and the submodule were installed.
        $main_module_path = $this->getWebRoot() . '/modules/contrib/main_module';
        $this->assertFileExists("{$main_module_path}/main_module.info.yml");
        $this->assertFileExists("{$main_module_path}/main_module_submodule/main_module_submodule.info.yml");
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
AssertPreconditionsTrait::assertNoFailureMarker private static function Asserts that there is no failure marker present.
AssertPreconditionsTrait::failIfUnmetPreConditions protected static function Asserts universal test preconditions before any setup is done.
AssertPreconditionsTrait::getProjectRoot private static function Returns the absolute path of the project root.
AssertPreconditionsTrait::setUpBeforeClass public static function Invokes the test preconditions assertion before the first test is run.
BuildTestBase::$commandProcess private property The most recent command process.
BuildTestBase::$destroyBuild protected property Default to destroying build artifacts after a test finishes.
BuildTestBase::$hostName private static property Our native host name, used by PHP when it starts up the server.
BuildTestBase::$hostPort private property Port that will be tested.
BuildTestBase::$mink private property The Mink session manager.
BuildTestBase::$phpFinder private property The PHP executable finder.
BuildTestBase::$portLocks private property A list of ports used by the test.
BuildTestBase::$serverDocroot private property The docroot for the server process.
BuildTestBase::$serverProcess private property The process that's running the HTTP server.
BuildTestBase::$workspaceDir private property The working directory where this test will manipulate files.
BuildTestBase::assertCommandExitCode public function Asserts that the last command returned the specified exit code.
BuildTestBase::assertCommandOutputContains public function Assert that text is present in the output of the most recent command.
BuildTestBase::assertCommandSuccessful public function Asserts that the last command ran without error.
BuildTestBase::assertDrupalVisit public function Helper function to assert that the last visit was a Drupal site.
BuildTestBase::assertErrorOutputContains public function Assert that text is present in the error output of the most recent command.
BuildTestBase::assertErrorOutputNotContains public function Assert text is not present in the error output of the most recent command.
BuildTestBase::checkPortIsAvailable protected function Checks whether a port is available.
BuildTestBase::executeCommand public function Run a command.
BuildTestBase::findAvailablePort protected function Discover an available port number.
BuildTestBase::getCodebaseFinder public function Get a default Finder object for a Drupal codebase.
BuildTestBase::getComposerRoot public function Gets the path to the Composer root directory.
BuildTestBase::getDrupalRoot public function Get the root path of this Drupal codebase.
BuildTestBase::getDrupalRootStatic public static function Get the root path of this Drupal codebase.
BuildTestBase::getMink public function Get the Mink instance.
BuildTestBase::getPortNumber protected function Get the port number for requests.
BuildTestBase::getWorkingPath protected function Get the working directory within the workspace, creating if necessary.
BuildTestBase::getWorkingPathDrupalRoot public function Gets the working path for Drupal core.
BuildTestBase::getWorkspaceDirectory public function Full path to the workspace where this test can build.
BuildTestBase::getWorkspaceDrupalRoot public function Gets the path to Drupal root in the workspace directory.
BuildTestBase::initMink protected function Set up the Mink session manager.
BuildTestBase::standUpServer protected function Makes a local test server using PHP's internal HTTP server.
BuildTestBase::stopServer protected function Stop the HTTP server, zero out all necessary variables.
FixtureUtilityTrait::copyFixtureFilesTo protected static function Mirrors a fixture directory to the given path.
FixtureUtilityTrait::renameGitDirectories private static function Renames _git directories to .git.
FixtureUtilityTrait::renameInfoYmlFiles protected static function Renames all files that end with .info.yml.hide.
PackageInstallTest::testPackageInstall public function Tests installing packages in a stage directory.
PackageInstallTest::testSubModules public function Tests installing a Drupal submodule.
QuickStartTestBase::$adminPassword protected property Password of the admin account generated during install.
QuickStartTestBase::$adminUsername protected property User name of the admin account generated during install.
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers.
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
RequiresComposerTrait::requiresComposer public static function
TemplateProjectTestBase::$metadataServer private property A secondary server instance, to serve XML metadata about available updates.
TemplateProjectTestBase::$serverErrorLog private property All output that the PHP web server logs to the error buffer.
TemplateProjectTestBase::$webRoot private property The web root of the test site, relative to the workspace directory.
TemplateProjectTestBase::addRepository protected function Adds a path repository to the test site.
TemplateProjectTestBase::assertAppliedChangesWereLogged protected function Asserts that changes applied during the stage life cycle were logged.
TemplateProjectTestBase::assertExpectedStageEventsFired protected function Asserts stage events were fired in a specific order.
TemplateProjectTestBase::assertRequestedChangesWereLogged protected function Asserts changes requested during the stage life cycle were logged.
TemplateProjectTestBase::copyCodebase public function Copy the current working codebase into a workspace. Overrides BuildTestBase::copyCodebase
TemplateProjectTestBase::copyFixtureToTempDirectory protected function Copies a fixture directory to a temporary directory and returns its path.
TemplateProjectTestBase::createTestProject protected function Creates a test project from a given template and installs Drupal.
TemplateProjectTestBase::createVendorRepository protected function Creates a Composer repository for all dependencies of the test project.
TemplateProjectTestBase::formLogin public function Helper that uses Drupal's user/login form to log in. Overrides QuickStartTestBase::formLogin
TemplateProjectTestBase::getWebRoot protected function Returns the full path to the test site's document root.
TemplateProjectTestBase::installModules protected function Installs modules in the UI.
TemplateProjectTestBase::installQuickStart public function Install a Drupal site using the quick start feature. Overrides QuickStartTestBase::installQuickStart
TemplateProjectTestBase::instantiateServer protected function Do the work of making a server process. Overrides BuildTestBase::instantiateServer
TemplateProjectTestBase::makePackageManagerTestApiRequest protected function Gets a /package-manager-test-api response.
TemplateProjectTestBase::MAX_EXECUTION_TIME protected constant The PHP web server's max_execution_time value.
TemplateProjectTestBase::providerTemplate public static function Data provider for tests which use all the core project templates.
TemplateProjectTestBase::runComposer protected function Runs a Composer command and returns its output.
TemplateProjectTestBase::setReleaseMetadata protected function Prepares the test site to serve an XML feed of available release metadata.
TemplateProjectTestBase::setUp protected function Overrides BuildTestBase::setUp
TemplateProjectTestBase::setUpstreamCoreVersion protected function Sets the version of Drupal core to which the test site will be updated.
TemplateProjectTestBase::tearDown protected function Invokes the test preconditions assertion after each test run. Overrides AssertPreconditionsTrait::tearDown
TemplateProjectTestBase::unboundCoreConstraints private static function Changes constraints for core packages to `*`.
TemplateProjectTestBase::visit public function Visit a URI on the HTTP server. Overrides BuildTestBase::visit
TemplateProjectTestBase::visitPackageManagerChangeLog private function Visits the 'admin/reports/dblog' and selects Package Manager's change log.
TemplateProjectTestBase::writeSettings protected function Appends PHP code to the test site's settings.php.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.