diff --git a/automatic_updates_extensions/tests/src/Kernel/AutomaticUpdatesExtensionsKernelTestBase.php b/automatic_updates_extensions/tests/src/Kernel/AutomaticUpdatesExtensionsKernelTestBase.php index 04bc6d7342af3b55a6fedc4a32a3db3b1727626d..a6357c9c77c96b512d501d919ecee10cb080e0f5 100644 --- a/automatic_updates_extensions/tests/src/Kernel/AutomaticUpdatesExtensionsKernelTestBase.php +++ b/automatic_updates_extensions/tests/src/Kernel/AutomaticUpdatesExtensionsKernelTestBase.php @@ -8,12 +8,15 @@ use Drupal\package_manager\Exception\StageValidationException; use Drupal\Tests\automatic_updates\Kernel\AutomaticUpdatesKernelTestBase; use Drupal\Tests\package_manager\Kernel\TestPathFactory; use Drupal\Tests\package_manager\Kernel\TestStageTrait; +use Drupal\Tests\package_manager\Traits\InfoYmlConverterTrait; /** * Base class for kernel tests of the Automatic Updates Extensions module. */ abstract class AutomaticUpdatesExtensionsKernelTestBase extends AutomaticUpdatesKernelTestBase { + use InfoYmlConverterTrait; + /** * {@inheritdoc} */ @@ -44,6 +47,7 @@ abstract class AutomaticUpdatesExtensionsKernelTestBase extends AutomaticUpdates protected function createVirtualProject(?string $source_dir = NULL): void { $source_dir = $source_dir ?? __DIR__ . '/../../fixtures/fake-site'; parent::createVirtualProject($source_dir); + $this->renameVfsInfoYmlFiles(); } /** diff --git a/automatic_updates_extensions/tests/src/Kernel/ExtensionUpdaterTest.php b/automatic_updates_extensions/tests/src/Kernel/ExtensionUpdaterTest.php index 3f9040ce4d042f420697a4081a0e7edce070c8e0..b05262708476bcfd2b48e362de5a55f1e73d9644 100644 --- a/automatic_updates_extensions/tests/src/Kernel/ExtensionUpdaterTest.php +++ b/automatic_updates_extensions/tests/src/Kernel/ExtensionUpdaterTest.php @@ -3,6 +3,7 @@ namespace Drupal\Tests\automatic_updates_extensions\Kernel; use Drupal\Tests\automatic_updates\Kernel\AutomaticUpdatesKernelTestBase; +use Drupal\Tests\package_manager\Traits\InfoYmlConverterTrait; use Drupal\Tests\user\Traits\UserCreationTrait; /** @@ -13,6 +14,7 @@ use Drupal\Tests\user\Traits\UserCreationTrait; class ExtensionUpdaterTest extends AutomaticUpdatesKernelTestBase { use UserCreationTrait; + use InfoYmlConverterTrait; /** * {@inheritdoc} @@ -40,6 +42,7 @@ class ExtensionUpdaterTest extends AutomaticUpdatesKernelTestBase { $this->setCurrentUser($user); $this->createVirtualProject(__DIR__ . '/../../fixtures/fake-site'); + $this->renameVfsInfoYmlFiles(); } /** diff --git a/package_manager/tests/src/Kernel/ComposerUtilityTest.php b/package_manager/tests/src/Kernel/ComposerUtilityTest.php index 15326421638b44c8a9387e9e2e240e0608ee2258..29023f1d4575b56aa9d6d61618e4724a3338adb6 100644 --- a/package_manager/tests/src/Kernel/ComposerUtilityTest.php +++ b/package_manager/tests/src/Kernel/ComposerUtilityTest.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\package_manager\Kernel; use Drupal\KernelTests\KernelTestBase; use Drupal\package_manager\ComposerUtility; +use Drupal\Tests\package_manager\Traits\InfoYmlConverterTrait; use org\bovigo\vfs\vfsStream; /** @@ -13,6 +14,8 @@ use org\bovigo\vfs\vfsStream; */ class ComposerUtilityTest extends KernelTestBase { + use InfoYmlConverterTrait; + /** * {@inheritdoc} */ @@ -25,8 +28,9 @@ class ComposerUtilityTest extends KernelTestBase { parent::setUp(); $fixture = vfsStream::newDirectory('fixture'); + vfsStream::copyFromFileSystem(__DIR__ . '/../../fixtures/project_package_conversion', $fixture); $this->vfsRoot->addChild($fixture); - FixtureUtility::copyFixtureFilesTo(__DIR__ . '/../../fixtures/project_package_conversion', $fixture->url()); + $this->renameVfsInfoYmlFiles(); } /** diff --git a/package_manager/tests/src/Traits/InfoYmlConverterTrait.php b/package_manager/tests/src/Traits/InfoYmlConverterTrait.php new file mode 100644 index 0000000000000000000000000000000000000000..4f186a53faf69540926627dae11ba5a70cd5518c --- /dev/null +++ b/package_manager/tests/src/Traits/InfoYmlConverterTrait.php @@ -0,0 +1,48 @@ +<?php + +namespace Drupal\Tests\package_manager\Traits; + +use org\bovigo\vfs\vfsStream; +use org\bovigo\vfs\vfsStreamDirectory; +use org\bovigo\vfs\vfsStreamFile; +use org\bovigo\vfs\visitor\vfsStreamAbstractVisitor; + +/** + * Common methods to convert info.yml file that will pass core coding standards. + */ +trait InfoYmlConverterTrait { + + /** + * Renames all files that end with .info.yml.hide. + */ + protected function renameVfsInfoYmlFiles(): void { + // Strip the `.hide` suffix from all `.info.yml.hide` files. Drupal's coding + // standards don't allow info files to have the `project` key, but we need + // it to be present for testing. + vfsStream::inspect(new class () extends vfsStreamAbstractVisitor { + + /** + * {@inheritdoc} + */ + public function visitFile(vfsStreamFile $file) { + $name = $file->getName(); + + if (str_ends_with($name, '.info.yml.hide')) { + $new_name = basename($name, '.hide'); + $file->rename($new_name); + } + } + + /** + * {@inheritdoc} + */ + public function visitDirectory(vfsStreamDirectory $dir) { + foreach ($dir->getChildren() as $child) { + $this->visit($child); + } + } + + }); + } + +} diff --git a/tests/src/Build/UpdateTestBase.php b/tests/src/Build/UpdateTestBase.php index 35ef9ad3ae793002d46efc0bc890db2f92600407..32d754d758fef90fa281eeba770eda29362a96ef 100644 --- a/tests/src/Build/UpdateTestBase.php +++ b/tests/src/Build/UpdateTestBase.php @@ -5,7 +5,8 @@ namespace Drupal\Tests\automatic_updates\Build; use Drupal\Component\Utility\Html; use Drupal\Tests\package_manager\Build\TemplateProjectTestBase; use Drupal\Tests\RandomGeneratorTrait; -use Drupal\Tests\package_manager\Kernel\FixtureUtility; +use Symfony\Component\Filesystem\Filesystem; +use Symfony\Component\Finder\Iterator\RecursiveDirectoryIterator; /** * Base class for tests that perform in-place updates. @@ -116,8 +117,29 @@ END; */ protected function copyFixtureToTempDirectory(string $fixture_directory): string { $temp_directory = $this->getWorkspaceDirectory() . '/fixtures_temp_' . $this->randomMachineName(20); - FixtureUtility::copyFixtureFilesTo($fixture_directory, $temp_directory); + (new Filesystem())->mirror($fixture_directory, $temp_directory); + $this->assertDirectoryIsWritable($temp_directory); + $this->renameInfoYmlFiles($temp_directory); return $temp_directory; } + /** + * Renames all files that end with .info.yml.hide. + * + * @param string $dir + * The directory to be iterated through. + */ + protected function renameInfoYmlFiles(string $dir) { + // Construct the iterator. + $it = new RecursiveDirectoryIterator($dir, \RecursiveIteratorIterator::SELF_FIRST); + + // Loop through files and rename them. + foreach (new \RecursiveIteratorIterator($it) as $file) { + if ($file->getExtension() == 'hide') { + rename($file->getPathname(), $dir . DIRECTORY_SEPARATOR . + $file->getRelativePath() . DIRECTORY_SEPARATOR . str_replace(".hide", "", $file->getFilename())); + } + } + } + } diff --git a/tests/src/Functional/AutomaticUpdatesFunctionalTestBase.php b/tests/src/Functional/AutomaticUpdatesFunctionalTestBase.php index 33e15cba1523a3b625a4f75485fbaee0890ac7f8..7b2cc2216c9e49b44932434dc771bb5398743c56 100644 --- a/tests/src/Functional/AutomaticUpdatesFunctionalTestBase.php +++ b/tests/src/Functional/AutomaticUpdatesFunctionalTestBase.php @@ -6,8 +6,9 @@ use Drupal\Core\Site\Settings; use Drupal\package_manager_bypass\Beginner; use Drupal\package_manager_bypass\Stager; use Drupal\Tests\BrowserTestBase; -use Drupal\Tests\package_manager\Kernel\FixtureUtility; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\Filesystem\Filesystem; +use Symfony\Component\Finder\Iterator\RecursiveDirectoryIterator; /** * Base class for functional tests of the Automatic Updates module. @@ -173,7 +174,8 @@ abstract class AutomaticUpdatesFunctionalTestBase extends BrowserTestBase { */ protected function copyFixtureToTempDirectory(string $fixture_directory): string { $temp_directory = $this->root . DIRECTORY_SEPARATOR . $this->siteDirectory . DIRECTORY_SEPARATOR . $this->randomMachineName(20); - FixtureUtility::copyFixtureFilesTo($fixture_directory, $temp_directory); + (new Filesystem())->mirror($fixture_directory, $temp_directory); + $this->assertDirectoryIsWritable($temp_directory); return $temp_directory; } @@ -191,6 +193,8 @@ abstract class AutomaticUpdatesFunctionalTestBase extends BrowserTestBase { Beginner::setFixturePath($active_dir); $this->container->get('package_manager.path_locator') ->setPaths($active_dir, $active_dir . '/vendor', '', NULL); + + $this->renameInfoYmlFiles($active_dir); } /** @@ -205,6 +209,27 @@ abstract class AutomaticUpdatesFunctionalTestBase extends BrowserTestBase { // directory and not affect other tests. $staged_dir = $this->copyFixtureToTempDirectory($fixture_directory); Stager::setFixturePath($staged_dir); + + $this->renameInfoYmlFiles($staged_dir); + } + + /** + * Renames all files that end with .info.yml.hide. + * + * @param string $dir + * The directory to be iterated through. + */ + protected function renameInfoYmlFiles(string $dir) { + // Construct the iterator. + $it = new RecursiveDirectoryIterator($dir, \RecursiveIteratorIterator::SELF_FIRST); + + // Loop through files and rename them. + foreach (new \RecursiveIteratorIterator($it) as $file) { + if ($file->getExtension() == 'hide') { + rename($file->getPathname(), $dir . DIRECTORY_SEPARATOR . $file->getRelativePath() . DIRECTORY_SEPARATOR . str_replace(".hide", "", $file->getFilename())); + } + } + } }