Skip to content
Snippets Groups Projects
Commit a8dfeaae authored by Ted Bowman's avatar Ted Bowman
Browse files

remove need for different renameInfoYmlFiles versions

parent da6f5255
No related branches found
No related tags found
No related merge requests found
......@@ -8,15 +8,12 @@ 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}
*/
......@@ -47,7 +44,6 @@ 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();
}
/**
......
......@@ -3,7 +3,6 @@
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;
/**
......@@ -14,7 +13,6 @@ use Drupal\Tests\user\Traits\UserCreationTrait;
class ExtensionUpdaterTest extends AutomaticUpdatesKernelTestBase {
use UserCreationTrait;
use InfoYmlConverterTrait;
/**
* {@inheritdoc}
......@@ -42,7 +40,6 @@ class ExtensionUpdaterTest extends AutomaticUpdatesKernelTestBase {
$this->setCurrentUser($user);
$this->createVirtualProject(__DIR__ . '/../../fixtures/fake-site');
$this->renameVfsInfoYmlFiles();
}
/**
......
......@@ -4,7 +4,6 @@ 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;
/**
......@@ -14,8 +13,6 @@ use org\bovigo\vfs\vfsStream;
*/
class ComposerUtilityTest extends KernelTestBase {
use InfoYmlConverterTrait;
/**
* {@inheritdoc}
*/
......@@ -28,9 +25,8 @@ class ComposerUtilityTest extends KernelTestBase {
parent::setUp();
$fixture = vfsStream::newDirectory('fixture');
vfsStream::copyFromFileSystem(__DIR__ . '/../../fixtures/project_package_conversion', $fixture);
$this->vfsRoot->addChild($fixture);
$this->renameVfsInfoYmlFiles();
FixtureUtility::copyFixtureFilesTo(__DIR__ . '/../../fixtures/project_package_conversion', $fixture->url());
}
/**
......
<?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);
}
}
});
}
}
......@@ -5,8 +5,7 @@ namespace Drupal\Tests\automatic_updates\Build;
use Drupal\Component\Utility\Html;
use Drupal\Tests\package_manager\Build\TemplateProjectTestBase;
use Drupal\Tests\RandomGeneratorTrait;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Iterator\RecursiveDirectoryIterator;
use Drupal\Tests\package_manager\Kernel\FixtureUtility;
/**
* Base class for tests that perform in-place updates.
......@@ -117,29 +116,8 @@ END;
*/
protected function copyFixtureToTempDirectory(string $fixture_directory): string {
$temp_directory = $this->getWorkspaceDirectory() . '/fixtures_temp_' . $this->randomMachineName(20);
(new Filesystem())->mirror($fixture_directory, $temp_directory);
$this->assertDirectoryIsWritable($temp_directory);
$this->renameInfoYmlFiles($temp_directory);
FixtureUtility::copyFixtureFilesTo($fixture_directory, $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()));
}
}
}
}
......@@ -6,9 +6,8 @@ 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.
......@@ -174,8 +173,7 @@ 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);
(new Filesystem())->mirror($fixture_directory, $temp_directory);
$this->assertDirectoryIsWritable($temp_directory);
FixtureUtility::copyFixtureFilesTo($fixture_directory, $temp_directory);
return $temp_directory;
}
......@@ -193,8 +191,6 @@ 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);
}
/**
......@@ -209,27 +205,6 @@ 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()));
}
}
}
}
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