class GenerateThemeTest in Drupal 9
Tests the generate-theme commands.
@requires extension pdo_sqlite
@group Command
Hierarchy
- class \Drupal\BuildTests\Framework\BuildTestBase extends \PHPUnit\Framework\TestCase uses ExternalCommandRequirementsTrait, PhpUnitCompatibilityTrait, PhpUnitWarnings
- class \Drupal\BuildTests\QuickStart\QuickStartTestBase
- class \Drupal\Tests\Core\Command\GenerateThemeTest
- class \Drupal\BuildTests\QuickStart\QuickStartTestBase
Expanded class hierarchy of GenerateThemeTest
File
- core/
tests/ Drupal/ Tests/ Core/ Command/ GenerateThemeTest.php, line 17
Namespace
Drupal\Tests\Core\CommandView source
class GenerateThemeTest extends QuickStartTestBase {
/**
* The PHP executable path.
*
* @var string
*/
protected $php;
/**
* {@inheritdoc}
*/
public function setUp() : void {
parent::setUp();
$php_executable_finder = new PhpExecutableFinder();
$this->php = $php_executable_finder
->find();
$this
->copyCodebase();
$this
->executeCommand('COMPOSER_DISCARD_CHANGES=true composer install --no-dev --no-interaction');
chdir($this
->getWorkingPath());
}
/**
* Tests the generate-theme command.
*/
public function test() {
if (version_compare(\SQLite3::version()['versionString'], Tasks::SQLITE_MINIMUM_VERSION) < 0) {
$this
->markTestSkipped();
}
$install_command = [
$this->php,
'core/scripts/drupal',
'generate-theme',
'test_custom_theme',
'--name="Test custom starterkit theme"',
'--description="Custom theme generated from a starterkit theme"',
];
$process = new Process($install_command, NULL);
$process
->setTimeout(60);
$result = $process
->run();
$this
->assertEquals('Theme generated successfully to themes/test_custom_theme', trim($process
->getOutput()));
$this
->assertSame(0, $result);
$theme_path_relative = 'themes/test_custom_theme';
$theme_path_absolute = $this
->getWorkspaceDirectory() . "/{$theme_path_relative}";
$this
->assertFileExists($theme_path_absolute . '/test_custom_theme.info.yml');
// Ensure that the generated theme can be installed.
$this
->installQuickStart('minimal');
$this
->formLogin($this->adminUsername, $this->adminPassword);
$this
->visit('/admin/appearance');
$this
->getMink()
->assertSession()
->pageTextContains('Test custom starterkit');
$this
->getMink()
->assertSession()
->pageTextContains('Custom theme generated from a starterkit theme');
$this
->getMink()
->getSession()
->getPage()
->clickLink('Install "Test custom starterkit theme" theme');
$this
->getMink()
->assertSession()
->pageTextContains('The "Test custom starterkit theme" theme has been installed.');
$this
->assertFileExists($theme_path_absolute . '/test_custom_theme.theme');
unlink($theme_path_absolute . '/test_custom_theme.theme');
$process = new Process($install_command, NULL);
$process
->setTimeout(60);
$result = $process
->run();
$this
->assertStringContainsString('Theme could not be generated because the destination directory', $process
->getErrorOutput());
$this
->assertStringContainsString($theme_path_relative, $process
->getErrorOutput());
$this
->assertSame(1, $result);
$this
->assertFileDoesNotExist($theme_path_absolute . '/test_custom_theme.theme');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BuildTestBase:: |
private | property | The most recent command process. | |
BuildTestBase:: |
protected | property | Default to destroying build artifacts after a test finishes. | |
BuildTestBase:: |
private static | property | Our native host name, used by PHP when it starts up the server. | |
BuildTestBase:: |
private | property | Port that will be tested. | |
BuildTestBase:: |
private | property | The Mink session manager. | |
BuildTestBase:: |
private | property | A list of ports used by the test. | |
BuildTestBase:: |
private | property | The docroot for the server process. | |
BuildTestBase:: |
private | property | The process that's running the HTTP server. | |
BuildTestBase:: |
private | property | The working directory where this test will manipulate files. | |
BuildTestBase:: |
public | function | Asserts that the last command returned the specified exit code. | |
BuildTestBase:: |
public | function | Assert that text is present in the output of the most recent command. | |
BuildTestBase:: |
public | function | Asserts that the last command ran without error. | |
BuildTestBase:: |
public | function | Helper function to assert that the last visit was a Drupal site. | |
BuildTestBase:: |
public | function | Assert that text is present in the error output of the most recent command. | |
BuildTestBase:: |
protected | function | Checks whether a port is available. | |
BuildTestBase:: |
public | function | Copy the current working codebase into a workspace. | |
BuildTestBase:: |
public | function | Run a command. | |
BuildTestBase:: |
protected | function | Discover an available port number. | |
BuildTestBase:: |
public | function | Get a default Finder object for a Drupal codebase. | |
BuildTestBase:: |
protected | function | Get the root path of this Drupal codebase. | |
BuildTestBase:: |
public | function | Get the Mink instance. | |
BuildTestBase:: |
protected | function | Get the port number for requests. | |
BuildTestBase:: |
protected | function | Get the working directory within the workspace, creating if necessary. | |
BuildTestBase:: |
public | function | Full path to the workspace where this test can build. | |
BuildTestBase:: |
protected | function | Set up the Mink session manager. | |
BuildTestBase:: |
protected | function | Do the work of making a server process. | |
BuildTestBase:: |
public static | function | ||
BuildTestBase:: |
protected | function | Makes a local test server using PHP's internal HTTP server. | |
BuildTestBase:: |
protected | function | Stop the HTTP server, zero out all necessary variables. | |
BuildTestBase:: |
protected | function | ||
BuildTestBase:: |
public | function | Visit a URI on the HTTP server. | |
ExternalCommandRequirementsTrait:: |
private static | property | A list of existing external commands we've already discovered. | |
ExternalCommandRequirementsTrait:: |
private static | function | Checks whether required external commands are available per test class. | |
ExternalCommandRequirementsTrait:: |
private static | function | Checks missing external command requirements. | |
ExternalCommandRequirementsTrait:: |
private static | function | Checks whether required external commands are available per method. | |
ExternalCommandRequirementsTrait:: |
private static | function | Determine if an external command is available. | 3 |
GenerateThemeTest:: |
protected | property | The PHP executable path. | |
GenerateThemeTest:: |
public | function |
Overrides BuildTestBase:: |
|
GenerateThemeTest:: |
public | function | Tests the generate-theme command. | |
PhpUnitWarnings:: |
private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |
PhpUnitWarnings:: |
public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |
QuickStartTestBase:: |
protected | property | Password of the admin account generated during install. | |
QuickStartTestBase:: |
protected | property | User name of the admin account generated during install. | |
QuickStartTestBase:: |
public | function | Helper that uses Drupal's user/login form to log in. | |
QuickStartTestBase:: |
public | function | Install a Drupal site using the quick start feature. |