FileSystemOperationsTest.php in Automatic Updates 8.2
File
tests/src/Functional/FileSystemOperationsTest.php
View source
<?php
namespace Drupal\Tests\automatic_updates\Functional;
use Drupal\automatic_updates\ComposerStager\Cleaner;
use Drupal\automatic_updates\PathLocator;
use Drupal\automatic_updates\Updater;
use Drupal\Core\Site\Settings;
class FileSystemOperationsTest extends AutomaticUpdatesFunctionalTestBase {
protected static $modules = [
'automatic_updates_test',
];
protected $defaultTheme = 'stark';
private $updater;
protected $stageDir;
protected function setUp() : void {
parent::setUp();
$drupal_root = $this
->getDrupalRoot();
$locator = $this
->prophesize(PathLocator::class);
$locator
->getActiveDirectory()
->willReturn(__DIR__ . '/../../fixtures/fake-site');
$this->stageDir = implode(DIRECTORY_SEPARATOR, [
$drupal_root,
$this->siteDirectory,
'stage',
]);
$locator
->getStageDirectory()
->willReturn($this->stageDir);
$locator
->getProjectRoot()
->willReturn($drupal_root);
$locator
->getWebRoot()
->willReturn('');
$cleaner = new Cleaner($this->container
->get('package_manager.cleaner'), 'sites/default', $locator
->reveal());
$this->updater = new Updater($this->container
->get('state'), $this->container
->get('string_translation'), $this->container
->get('package_manager.beginner'), $this->container
->get('package_manager.stager'), $cleaner, $this->container
->get('package_manager.committer'), $this->container
->get('event_dispatcher'), $locator
->reveal());
$settings = Settings::getAll();
$settings['file_public_path'] = 'files/public';
$settings['file_private_path'] = 'files/private';
new Settings($settings);
$this
->setReleaseMetadata(__DIR__ . '/../../fixtures/release-history/drupal.9.8.1-security.xml');
$this
->setCoreVersion('9.8.0');
$this
->drupalLogin($this->rootUser);
$this
->checkForUpdates();
$this
->drupalLogout();
}
public function testExclusions() : void {
$this->updater
->begin([
'drupal' => '9.8.1',
]);
$this
->assertFileDoesNotExist("{$this->stageDir}/sites/default/settings.php");
$this
->assertFileDoesNotExist("{$this->stageDir}/sites/default/settings.local.php");
$this
->assertFileDoesNotExist("{$this->stageDir}/sites/default/services.yml");
$this
->assertFileExists("{$this->stageDir}/sites/default/staged.txt");
$this
->assertDirectoryDoesNotExist("{$this->stageDir}/sites/simpletest");
$this
->assertDirectoryDoesNotExist("{$this->stageDir}/files/public");
$this
->assertDirectoryDoesNotExist("{$this->stageDir}/files/private");
$this
->assertFileExists("{$this->stageDir}/files/staged.txt");
}
public function testClean() : void {
$this->updater
->begin([
'drupal' => '9.8.1',
]);
$this
->assertTrue(chmod("{$this->stageDir}/sites/default", 0400));
$this
->assertNotIsWritable("{$this->stageDir}/sites/default/staged.txt");
$this->updater
->clean();
$this
->assertDirectoryDoesNotExist($this->stageDir);
}
}