Skip to content
Snippets Groups Projects
Commit f0fda9de authored by catch's avatar catch
Browse files

Issue #3403382 by alexpott, Wim Leers: BuildTestBase makes assumptions it...

Issue #3403382 by alexpott, Wim Leers: BuildTestBase makes assumptions it should not about the code layout

(cherry picked from commit cbbe53da)
parent 6170ea97
No related branches found
No related tags found
16 merge requests!8376Drupal views: adding more granularity to the ‘use ajax’ functionality,!8300Issue #3443586 View area displays even when parent view has no results.,!7567Issue #3153723 by quietone, Hardik_Patel_12: Change the scaffolding...,!7565Issue #3153723 by quietone, Hardik_Patel_12: Change the scaffolding...,!7509Change label "Block description" to "Block type",!7344Issue #3292350 by O'Briat, KlemenDEV, hswong3i, smustgrave, quietone: Update...,!6922Issue #3412959 by quietone, smustgrave, longwave: Fix 12 'un' words,!6848Issue #3417553 by longwave: Remove withConsecutive() in CacheCollectorTest,!6720Revert "Issue #3358581 by pfrenssen, _tarik_, a.dmitriiev, smustgrave:...,!6560Update ClaroPreRender.php, confirming classes provided are in array format,!6528Issue #3414261 by catch: Add authenticated user umami performance tests,!6501Issue #3263668 by omkar-pd, Wim Leers, hooroomoo: Re-enable inline form errors...,!6354Draft: Issue #3380392 by phma: Updating language weight from the overview reverts label if translated,!6324Issue #3416723 by Ludo.R: Provide a "node type" views default argument,!6119Issue #3405704 by Spokje, longwave: symfony/psr-http-message-bridge major version bump,!5950Issue #3403653 by alexpott, longwave: Incorporate improvements to how contrib runs PHPStan to core
Pipeline #66176 passed with warnings
Pipeline: drupal

#66187

    Pipeline: drupal

    #66180

      ...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
      use Behat\Mink\Driver\BrowserKitDriver; use Behat\Mink\Driver\BrowserKitDriver;
      use Behat\Mink\Mink; use Behat\Mink\Mink;
      use Behat\Mink\Session; use Behat\Mink\Session;
      use Composer\InstalledVersions;
      use Drupal\Component\FileSystem\FileSystem as DrupalFilesystem; use Drupal\Component\FileSystem\FileSystem as DrupalFilesystem;
      use Drupal\Tests\DrupalTestBrowser; use Drupal\Tests\DrupalTestBrowser;
      use Drupal\Tests\PhpUnitCompatibilityTrait; use Drupal\Tests\PhpUnitCompatibilityTrait;
      ...@@ -557,7 +558,7 @@ public function copyCodebase(\Iterator $iterator = NULL, $working_dir = NULL) { ...@@ -557,7 +558,7 @@ public function copyCodebase(\Iterator $iterator = NULL, $working_dir = NULL) {
      $fs = new SymfonyFilesystem(); $fs = new SymfonyFilesystem();
      $options = ['override' => TRUE, 'delete' => FALSE]; $options = ['override' => TRUE, 'delete' => FALSE];
      $fs->mirror($this->getDrupalRoot(), $working_path, $iterator, $options); $fs->mirror($this->getComposerRoot(), $working_path, $iterator, $options);
      } }
      /** /**
      ...@@ -577,14 +578,16 @@ public function copyCodebase(\Iterator $iterator = NULL, $working_dir = NULL) { ...@@ -577,14 +578,16 @@ public function copyCodebase(\Iterator $iterator = NULL, $working_dir = NULL) {
      * A Finder object ready to iterate over core codebase. * A Finder object ready to iterate over core codebase.
      */ */
      public function getCodebaseFinder() { public function getCodebaseFinder() {
      $drupal_root = $this->getWorkingPathDrupalRoot() ?? '';
      $finder = new Finder(); $finder = new Finder();
      $finder->files() $finder->files()
      ->followLinks()
      ->ignoreUnreadableDirs() ->ignoreUnreadableDirs()
      ->in($this->getDrupalRoot()) ->in($this->getComposerRoot())
      ->notPath('#^sites/default/files#') ->notPath("#^{$drupal_root}sites/default/files#")
      ->notPath('#^sites/simpletest#') ->notPath("#^{$drupal_root}sites/simpletest#")
      ->notPath('#^core/node_modules#') ->notPath("#^{$drupal_root}core/node_modules#")
      ->notPath('#^sites/default/settings\..*php#') ->notPath("#^{$drupal_root}sites/default/settings\..*php#")
      ->ignoreDotFiles(FALSE) ->ignoreDotFiles(FALSE)
      ->ignoreVCS(FALSE); ->ignoreVCS(FALSE);
      return $finder; return $finder;
      ...@@ -596,8 +599,53 @@ public function getCodebaseFinder() { ...@@ -596,8 +599,53 @@ public function getCodebaseFinder() {
      * @return string * @return string
      * The full path to the root of this Drupal codebase. * The full path to the root of this Drupal codebase.
      */ */
      protected function getDrupalRoot() { public function getDrupalRoot() {
      return realpath(dirname(__DIR__, 5)); // Given this code is in the drupal/core package, $core cannot be NULL.
      /** @var string $core */
      $core = InstalledVersions::getInstallPath('drupal/core');
      return realpath(dirname($core));
      }
      /**
      * Gets the path to the Composer root directory.
      *
      * @return string
      * The absolute path to the Composer root directory.
      */
      public function getComposerRoot(): string {
      $root = InstalledVersions::getRootPackage();
      return realpath($root['install_path']);
      }
      /**
      * Gets the path to Drupal root in the workspace directory.
      *
      * @return string
      * The absolute path to the Drupal root directory in the workspace.
      */
      public function getWorkspaceDrupalRoot(): string {
      $dir = $this->getWorkspaceDirectory();
      $drupal_root = $this->getWorkingPathDrupalRoot();
      if ($drupal_root !== NULL) {
      $dir = $dir . DIRECTORY_SEPARATOR . $drupal_root;
      }
      return $dir;
      }
      /**
      * Gets the working path for Drupal core.
      *
      * @return string|null
      * The relative path to Drupal's root directory or NULL if it is the same
      * as the composer root directory.
      */
      public function getWorkingPathDrupalRoot(): ?string {
      $composer_root = $this->getComposerRoot();
      $drupal_root = $this->getDrupalRoot();
      if ($composer_root === $drupal_root) {
      return NULL;
      }
      return (new SymfonyFilesystem())->makePathRelative($drupal_root, $composer_root);
      } }
      } }
      ...@@ -87,14 +87,18 @@ public function testCopyCodebaseExclude() { ...@@ -87,14 +87,18 @@ public function testCopyCodebaseExclude() {
      ], ],
      ]); ]);
      // Mock BuildTestBase so that it thinks our VFS is the Drupal root. // Mock BuildTestBase so that it thinks our VFS is the Composer and Drupal
      // roots.
      /** @var \PHPUnit\Framework\MockObject\MockBuilder|\Drupal\BuildTests\Framework\BuildTestBase $base */ /** @var \PHPUnit\Framework\MockObject\MockBuilder|\Drupal\BuildTests\Framework\BuildTestBase $base */
      $base = $this->getMockBuilder(BuildTestBase::class) $base = $this->getMockBuilder(BuildTestBase::class)
      ->onlyMethods(['getDrupalRoot']) ->onlyMethods(['getDrupalRoot', 'getComposerRoot'])
      ->getMockForAbstractClass(); ->getMockForAbstractClass();
      $base->expects($this->exactly(2)) $base->expects($this->exactly(1))
      ->method('getDrupalRoot') ->method('getDrupalRoot')
      ->willReturn(vfsStream::url('drupal')); ->willReturn(vfsStream::url('drupal'));
      $base->expects($this->exactly(3))
      ->method('getComposerRoot')
      ->willReturn(vfsStream::url('drupal'));
      $base->setUp(); $base->setUp();
      ...@@ -121,6 +125,84 @@ public function testCopyCodebaseExclude() { ...@@ -121,6 +125,84 @@ public function testCopyCodebaseExclude() {
      $base->tearDown(); $base->tearDown();
      } }
      /**
      * Tests copying codebase when Drupal and Composer roots are different.
      *
      * @covers ::copyCodebase
      */
      public function testCopyCodebaseDocRoot() {
      // Create a virtual file system containing items that should be
      // excluded. Exception being modules directory.
      vfsStream::setup('drupal', NULL, [
      'docroot' => [
      'sites' => [
      'default' => [
      'files' => [
      'a_file.txt' => 'some file.',
      ],
      'settings.php' => '<?php $settings = "stuff";',
      'settings.local.php' => '<?php $settings = "override";',
      'default.settings.php' => '<?php $settings = "default";',
      ],
      'simpletest' => [
      'simpletest_hash' => [
      'some_results.xml' => '<xml/>',
      ],
      ],
      ],
      'modules' => [
      'my_module' => [
      'vendor' => [
      'my_vendor' => [
      'composer.json' => "{\n}",
      ],
      ],
      ],
      ],
      ],
      'vendor' => [
      'test.txt' => 'File exists',
      ],
      ]);
      // Mock BuildTestBase so that it thinks our VFS is the Composer and Drupal
      // roots.
      /** @var \PHPUnit\Framework\MockObject\MockBuilder|\Drupal\BuildTests\Framework\BuildTestBase $base */
      $base = $this->getMockBuilder(BuildTestBase::class)
      ->onlyMethods(['getDrupalRoot', 'getComposerRoot'])
      ->getMockForAbstractClass();
      $base->expects($this->exactly(3))
      ->method('getDrupalRoot')
      ->willReturn(vfsStream::url('drupal/docroot'));
      $base->expects($this->exactly(5))
      ->method('getComposerRoot')
      ->willReturn(vfsStream::url('drupal'));
      $base->setUp();
      // Perform the copy.
      $base->copyCodebase();
      $full_path = $base->getWorkspaceDirectory();
      $this->assertDirectoryExists($full_path . '/docroot');
      // Verify expected files exist.
      $this->assertFileExists($full_path . DIRECTORY_SEPARATOR . 'docroot/modules/my_module/vendor/my_vendor/composer.json');
      $this->assertFileExists($full_path . DIRECTORY_SEPARATOR . 'docroot/sites/default/default.settings.php');
      $this->assertFileExists($full_path . DIRECTORY_SEPARATOR . 'vendor');
      // Verify expected files do not exist
      $this->assertFileDoesNotExist($full_path . DIRECTORY_SEPARATOR . 'docroot/sites/default/settings.php');
      $this->assertFileDoesNotExist($full_path . DIRECTORY_SEPARATOR . 'docroot/sites/default/settings.local.php');
      $this->assertFileDoesNotExist($full_path . DIRECTORY_SEPARATOR . 'docroot/sites/default/files');
      // Ensure that the workspace Drupal root is calculated correctly.
      $this->assertSame($full_path . '/docroot/', $base->getWorkspaceDrupalRoot());
      $this->assertSame('docroot/', $base->getWorkingPathDrupalRoot());
      $base->tearDown();
      }
      /** /**
      * @covers ::findAvailablePort * @covers ::findAvailablePort
      */ */
      ......
      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