From bce6afde10876eb11a24aef57e4b3a6d91464619 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ph=C3=A9na=20Proxima?= <adam@phenaproxima.net>
Date: Mon, 11 Apr 2022 10:25:37 -0400
Subject: [PATCH] And TestSiteExcluder

---
 .../tests/src/Kernel/ExcludedPathsTest.php    |  2 -
 .../tests/src/Kernel/TestSiteExcluderTest.php | 58 +++++++++++++++++++
 2 files changed, 58 insertions(+), 2 deletions(-)
 create mode 100644 package_manager/tests/src/Kernel/TestSiteExcluderTest.php

diff --git a/package_manager/tests/src/Kernel/ExcludedPathsTest.php b/package_manager/tests/src/Kernel/ExcludedPathsTest.php
index 1ca552ea4a..cb780a17be 100644
--- a/package_manager/tests/src/Kernel/ExcludedPathsTest.php
+++ b/package_manager/tests/src/Kernel/ExcludedPathsTest.php
@@ -13,7 +13,6 @@ use Drupal\package_manager\EventSubscriber\SqliteDatabaseExcluder;
  * @covers \Drupal\package_manager\EventSubscriber\SiteFilesExcluder
  * @covers \Drupal\package_manager\EventSubscriber\SqliteDatabaseExcluder
  * @covers \Drupal\package_manager\EventSubscriber\TestSiteExcluder
- * @covers \Drupal\package_manager\EventSubscriber\VendorHardeningExcluder
  *
  * @group package_manager
  */
@@ -84,7 +83,6 @@ class ExcludedPathsTest extends PackageManagerKernelTestBase {
     $stage_dir = $stage->getStageDirectory();
 
     $ignore = [
-      'sites/simpletest',
       "$site_path/files/ignore.txt",
       'private/ignore.txt',
       "$site_path/settings.php",
diff --git a/package_manager/tests/src/Kernel/TestSiteExcluderTest.php b/package_manager/tests/src/Kernel/TestSiteExcluderTest.php
new file mode 100644
index 0000000000..05cc8615ab
--- /dev/null
+++ b/package_manager/tests/src/Kernel/TestSiteExcluderTest.php
@@ -0,0 +1,58 @@
+<?php
+
+namespace Drupal\Tests\package_manager\Kernel;
+
+/**
+ * @covers \Drupal\package_manager\EventSubscriber\TestSiteExcluder
+ *
+ * @group package_manager
+ */
+class TestSiteExcluderTest extends PackageManagerKernelTestBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp(): void {
+    // In this test, we want to disable the lock file validator because, even
+    // though both the active and stage directories will have a valid lock file,
+    // this validator will complain because they don't differ at all.
+    $this->disableValidators[] = 'package_manager.validator.lock_file';
+    parent::setUp();
+  }
+
+  /**
+   * Tests that Git directories are excluded from staging operations.
+   */
+  public function testGitDirectoriesExcluded(): void {
+    // In this test, we want to perform the actual staging operations so that we
+    // can be sure that files are staged as expected.
+    $this->container->get('module_installer')->uninstall([
+      'package_manager_bypass',
+    ]);
+    // Ensure we have an up-to-date container.
+    $this->container = $this->container->get('kernel')->getContainer();
+
+    $this->createTestProject();
+    $active_dir = $this->container->get('package_manager.path_locator')
+      ->getProjectRoot();
+
+    $stage = $this->createStage();
+    $stage->create();
+    $stage_dir = $stage->getStageDirectory();
+
+    $ignored = [
+      'sites/simpletest',
+    ];
+    foreach ($ignored as $path) {
+      $this->assertFileExists("$active_dir/$path");
+      $this->assertFileDoesNotExist("$stage_dir/$path");
+    }
+
+    $stage->apply();
+    // The ignored files should still be in the active directory.
+    foreach ($ignored as $path) {
+      $this->assertFileExists("$active_dir/$path");
+    }
+  }
+
+}
-- 
GitLab