function SiteConfigurationExcluderTest::testExcludedPaths

Tests that certain paths are excluded from stage operations.

File

core/modules/package_manager/tests/src/Kernel/PathExcluder/SiteConfigurationExcluderTest.php, line 32

Class

SiteConfigurationExcluderTest
@covers \Drupal\package_manager\PathExcluder\SiteConfigurationExcluder @group package_manager @internal

Namespace

Drupal\Tests\package_manager\Kernel\PathExcluder

Code

public function testExcludedPaths() : void {
    // In this test, we want to perform the actual stage operations so that we
    // can be sure that files are staged as expected.
    $this->setSetting('package_manager_bypass_composer_stager', FALSE);
    // Ensure we have an up-to-date container.
    $this->container = $this->container
        ->get('kernel')
        ->rebuildContainer();
    $active_dir = $this->container
        ->get(PathLocator::class)
        ->getProjectRoot();
    $site_path = 'sites/example.com';
    // Update the event subscribers' dependencies.
    $site_configuration_excluder = $this->container
        ->get(SiteConfigurationExcluder::class);
    $site_configuration_excluder->sitePath = $site_path;
    $stage = $this->createStage();
    $stage->create();
    $stage->require([
        'ext-json:*',
    ]);
    $stage_dir = $stage->getStageDirectory();
    $excluded = [
        "{$site_path}/settings.php",
        "{$site_path}/settings.local.php",
        "{$site_path}/services.yml",
        // Default site-specific settings files should be excluded.
'sites/default/settings.php',
        'sites/default/settings.local.php',
        'sites/default/services.yml',
    ];
    foreach ($excluded as $path) {
        $this->assertFileExists("{$active_dir}/{$path}");
        $this->assertFileDoesNotExist("{$stage_dir}/{$path}");
    }
    // A non-excluded file in the default site directory should be staged.
    $this->assertFileExists("{$stage_dir}/sites/default/stage.txt");
    // Regular module files should be staged.
    $this->assertFileExists("{$stage_dir}/modules/example/example.info.yml");
    // A new file added to the site directory in the stage directory should be
    // copied to the active directory.
    $file = "{$stage_dir}/sites/default/new.txt";
    touch($file);
    $stage->apply();
    $this->assertFileExists("{$active_dir}/sites/default/new.txt");
    // The excluded files should still be in the active directory.
    foreach ($excluded as $path) {
        $this->assertFileExists("{$active_dir}/{$path}");
    }
}

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