Newer
Older

Ted Bowman
committed
<?php
namespace Drupal\Tests\automatic_updates\Functional;
/**
* Tests that only one Automatic Update operation can be performed at a time.
*
* @group automatic_updates
*/
class UpdateLockTest extends AutomaticUpdatesFunctionalTestBase {
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected static $modules = [
'automatic_updates',
'automatic_updates_test',
];
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();

Kunal Sachdev
committed
$this->setReleaseMetadata(__DIR__ . '/../../fixtures/release-history/drupal.9.8.2.xml');

Ted Bowman
committed
$this->drupalLogin($this->rootUser);
$this->checkForUpdates();
}
/**
* Tests that only user who started an update can continue through it.
*/
public function testLock(): void {

Ted Bowman
committed
$page = $this->getSession()->getPage();
$assert_session = $this->assertSession();
$this->setCoreVersion('9.8.0');
$this->checkForUpdates();
$permissions = ['administer software updates'];
$user_1 = $this->createUser($permissions);
$user_2 = $this->createUser($permissions);
// We should be able to get partway through an update without issue.
$this->drupalLogin($user_1);
$this->drupalGet('/admin/modules/automatic-update');
$page->pressButton('Update');
$this->checkForMetaRefresh();
$this->assertUpdateReady();

Ted Bowman
committed
$assert_session->buttonExists('Continue');
$url = parse_url($this->getSession()->getCurrentUrl(), PHP_URL_PATH);

Ted Bowman
committed
// Another user cannot show up and try to start an update, since the other
// user already started one.
$this->drupalLogin($user_2);
$this->drupalGet('/admin/modules/automatic-update');
$assert_session->buttonNotExists('Update');
$assert_session->pageTextContains('Cannot begin an update because another Composer operation is currently in progress.');
// If the current user did not start the update, they should not be able to
// continue it, either.
$this->drupalGet($url);

Ted Bowman
committed
$assert_session->pageTextContains('Cannot continue the update because another Composer operation is currently in progress.');
$assert_session->buttonNotExists('Continue');
// The user who started the update should be able to continue it.
$this->drupalLogin($user_1);
$this->drupalGet($url);

Ted Bowman
committed
$assert_session->pageTextNotContains('Cannot continue the update because another Composer operation is currently in progress.');
$assert_session->buttonExists('Continue');
}
}