public function GenerateThemeTest::testContribStarterkitDevSnapshotWithGitNotInstalled in Drupal 10
Tests the generate-theme command on a theme with a dev version without git.
File
- core/
tests/ Drupal/ Tests/ Core/ Command/ GenerateThemeTest.php, line 197
Class
- GenerateThemeTest
- Tests the generate-theme commands.
Namespace
Drupal\Tests\Core\CommandCode
public function testContribStarterkitDevSnapshotWithGitNotInstalled() : void {
// Change the version to a development snapshot version number, to simulate
// using a contrib theme as the starterkit.
$starterkit_info_yml = $this
->getWorkspaceDirectory() . '/core/themes/starterkit_theme/starterkit_theme.info.yml';
$info = Yaml::decode(file_get_contents($starterkit_info_yml));
$info['core_version_requirement'] = '*';
$info['version'] = '7.x-dev';
file_put_contents($starterkit_info_yml, Yaml::encode($info));
// Avoid the core git commit from being considered the source theme's: move
// it out of core.
Process::fromShellCommandline('mv core/themes/starterkit_theme themes/', $this
->getWorkspaceDirectory())
->run();
// Confirm that 'git' is available.
$output = [];
exec('git --help', $output, $status);
$this
->assertEquals(0, $status);
// Modify our $PATH so that it begins with a path that contains an
// executable script named 'git' that always exits with 127, as if git were
// not found. Note that we run our tests using process isolation, so we do
// not need to restore the PATH when we are done.
$unavailableGitPath = $this
->getWorkspaceDirectory() . '/bin';
mkdir($unavailableGitPath);
$bash = <<<SH
#!/bin/bash
exit 127
SH;
file_put_contents($unavailableGitPath . '/git', $bash);
chmod($unavailableGitPath . '/git', 0755);
$oldPath = getenv('PATH');
putenv('PATH=' . $unavailableGitPath . ':' . getenv('PATH'));
// Confirm that 'git' is no longer available.
$output = [];
exec('git --help', $output, $status);
$this
->assertEquals(127, $status);
$process = $this
->generateThemeFromStarterkit();
$result = $process
->run();
$this
->assertEquals("[ERROR] The source theme starterkit_theme has a development version number \n (7.x-dev). Determining a specific commit is not possible because git is\n not installed. Either install git or use a tagged release to generate a\n theme.", trim($process
->getOutput()), $process
->getErrorOutput());
$this
->assertSame(1, $result);
$this
->assertFileDoesNotExist($this
->getWorkspaceDirectory() . "/themes/test_custom_theme");
putenv('PATH=' . $oldPath . ':' . getenv('PATH'));
}