Newer
Older

Adam G-H
committed
<?php
declare(strict_types = 1);

Adam G-H
committed
namespace Drupal\Tests\package_manager\Build;

Ted Bowman
committed
use Drupal\package_manager\Stage;

Adam G-H
committed
/**

omkar podey
committed
* Tests updating packages in a stage directory.

Adam G-H
committed
*
* @group package_manager

Yash Rode
committed
* @internal

Adam G-H
committed
*/
class PackageUpdateTest extends TemplateProjectTestBase {
/**

omkar podey
committed
* Tests updating packages in a stage directory.

Adam G-H
committed
*/
public function testPackageUpdate(): void {
$this->createTestProject('RecommendedProject');

omkar podey
committed
$this->addRepository('alpha', $this->copyFixtureToTempDirectory(__DIR__ . '/../../fixtures/build_test_projects/alpha/1.0.0'));
$this->addRepository('updated_module', $this->copyFixtureToTempDirectory(__DIR__ . '/../../fixtures/build_test_projects/updated_module/1.0.0'));

Ted Bowman
committed
$this->setReleaseMetadata([
'updated_module' => __DIR__ . '/../../fixtures/release-history/updated_module.1.1.0.xml',
]);

Adam G-H
committed
$this->runComposer('COMPOSER_MIRROR_PATH_REPOS=1 composer require drupal/alpha drupal/updated_module --update-with-all-dependencies', 'project');
// The updated_module provides actual Drupal-facing functionality that we're
// testing as well, so we need to install it.

Ted Bowman
committed
$this->installModules(['updated_module']);

Adam G-H
committed
// Change both modules' upstream version.

omkar podey
committed
$this->addRepository('alpha', $this->copyFixtureToTempDirectory(__DIR__ . '/../../fixtures/build_test_projects/alpha/1.1.0'));
$this->addRepository('updated_module', $this->copyFixtureToTempDirectory(__DIR__ . '/../../fixtures/build_test_projects/updated_module/1.1.0'));
// Make .git folder

Adam G-H
committed
// Use the API endpoint to create a stage and update updated_module to
// 1.1.0. Even though both modules have version 1.1.0 available, only
// updated_module should be updated. We ask the API to return the contents
// of both modules' composer.json files, so we can assert that they were
// updated to the versions we expect.
// @see \Drupal\package_manager_test_api\ApiController::run()
$query = http_build_query([
'runtime' => [
'drupal/updated_module:1.1.0',
],
'files_to_return' => [
'web/modules/contrib/alpha/composer.json',
'web/modules/contrib/updated_module/composer.json',
'bravo.txt',
"system_changes.json",

Adam G-H
committed
],
]);
$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);
$expected_versions = [
'alpha' => '1.0.0',
'updated_module' => '1.1.0',
];
foreach ($expected_versions as $module_name => $expected_version) {
$path = "web/modules/contrib/$module_name/composer.json";
$module_composer_json = json_decode($file_contents[$path]);
$this->assertSame($expected_version, $module_composer_json->version);
}
// The post-apply event subscriber in updated_module 1.1.0 should have
// created this file.
// @see \Drupal\updated_module\PostApplySubscriber::postApply()
$this->assertSame('Bravo!', $file_contents['bravo.txt']);

Ted Bowman
committed
$this->assertExpectedStageEventsFired(Stage::class);