Skip to content
Snippets Groups Projects
Commit 9af8839a authored by Adam G-H's avatar Adam G-H Committed by Adam G-H
Browse files

Move stuff around and add test coverage

parent 45f54dd9
No related branches found
No related tags found
1 merge request!103Issue #3245996: Move basic exclusions and test coverage into Package Manager
This commit is part of merge request !103. Comments created here will be created in the context of that merge request.
......@@ -64,3 +64,9 @@ services:
class: Drupal\automatic_updates\Validator\CoreComposerValidator
tags:
- { name: event_subscriber }
automatic_updates.excluded_paths_subscriber:
class: Drupal\automatic_updates\Event\ExcludedPathsSubscriber
arguments:
- '@extension.list.module'
tags:
- { name: event_subscriber }
......@@ -131,6 +131,5 @@ services:
- '%site.path%'
- '@file_system'
- '@stream_wrapper_manager'
- '@extension.list.module'
tags:
- { name: event_subscriber }
......@@ -2,7 +2,6 @@
namespace Drupal\package_manager\EventSubscriber;
use Drupal\Core\Extension\ModuleExtensionList;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\StreamWrapper\LocalStream;
use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface;
......@@ -43,13 +42,6 @@ class ExcludedPathsSubscriber implements EventSubscriberInterface {
*/
protected $streamWrapperManager;
/**
* The module list service.
*
* @var \Drupal\Core\Extension\ModuleExtensionList
*/
protected $moduleList;
/**
* Constructs an UpdateSubscriber.
*
......@@ -61,19 +53,16 @@ class ExcludedPathsSubscriber implements EventSubscriberInterface {
* The file system service.
* @param \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper_manager
* The stream wrapper manager service.
* @param \Drupal\Core\Extension\ModuleExtensionList $module_list
* The module list service.
*/
public function __construct(string $app_root, string $site_path, FileSystemInterface $file_system, StreamWrapperManagerInterface $stream_wrapper_manager, ModuleExtensionList $module_list) {
public function __construct(string $app_root, string $site_path, FileSystemInterface $file_system, StreamWrapperManagerInterface $stream_wrapper_manager) {
$this->appRoot = $app_root;
$this->sitePath = $site_path;
$this->fileSystem = $file_system;
$this->streamWrapperManager = $stream_wrapper_manager;
$this->moduleList = $module_list;
}
/**
* Reacts before staged updates are committed the active directory.
* Reacts before staged changes are committed the active directory.
*
* @param \Drupal\package_manager\Event\PreApplyEvent $event
* The event object.
......@@ -90,7 +79,7 @@ class ExcludedPathsSubscriber implements EventSubscriberInterface {
}
/**
* Reacts to the beginning of an update process.
* Excludes paths from a staging area before it is created.
*
* @param \Drupal\package_manager\Event\PreCreateEvent $event
* The event object.
......@@ -111,11 +100,6 @@ class ExcludedPathsSubscriber implements EventSubscriberInterface {
if ($private = $this->getFilesPath('private')) {
$event->excludePath($private);
}
// If this module is a git clone, exclude it.
if (is_dir(__DIR__ . '/../../.git')) {
$dir = $this->moduleList->getPath('automatic_updates');
$event->excludePath($dir);
}
// Exclude site-specific settings files.
$settings_files = [
......
{}
......@@ -24,6 +24,9 @@ class ExcludedPathsTest extends BrowserTestBase {
*/
protected static $modules = ['package_manager'];
/**
* Tests that certain paths are excluded from staging areas.
*/
public function testExcludedPaths(): void {
$active_dir = __DIR__ . '/../../fixtures/fake_site';
$stage_dir = $this->siteDirectory . '/stage';
......@@ -32,6 +35,8 @@ class ExcludedPathsTest extends BrowserTestBase {
$path_locator->getActiveDirectory()->willReturn($active_dir);
$path_locator->getStageDirectory()->willReturn($stage_dir);
// Ensure that we are using directories within the fake site fixture for
// public and private files.
$settings = Settings::getAll();
$settings['file_public_path'] = 'sites/example.com/files';
$settings['file_private_path'] = 'private';
......
<?php
namespace Drupal\automatic_updates\Event;
use Drupal\Core\Extension\ModuleExtensionList;
use Drupal\package_manager\Event\PreCreateEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Defines an event subscriber to exclude certain paths from staging areas.
*/
class ExcludedPathsSubscriber implements EventSubscriberInterface {
/**
* The module list service.
*
* @var \Drupal\Core\Extension\ModuleExtensionList
*/
protected $moduleList;
/**
* Constructs an UpdateSubscriber.
*
* @param \Drupal\Core\Extension\ModuleExtensionList $module_list
* The module list service.
*/
public function __construct(ModuleExtensionList $module_list) {
$this->moduleList = $module_list;
}
/**
* Excludes paths from a staging area before it is created.
*
* @param \Drupal\package_manager\Event\PreCreateEvent $event
* The event object.
*/
public function preCreate(PreCreateEvent $event): void {
// If this module is a git clone, exclude it.
if (is_dir(__DIR__ . '/../../.git')) {
$dir = $this->moduleList->getPath('automatic_updates');
$event->excludePath($dir);
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
return [
PreCreateEvent::class => 'preCreate',
];
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment