Skip to content

Commit

Permalink
Add test for bedrock configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
dingo-d committed Nov 10, 2023
1 parent dfd5b66 commit dbbc031
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Command/InitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int

// This is a dirty hack so that the test pass.
if (isset($_ENV['WP_PEST_TESTING']) && $_ENV['WP_PEST_TESTING']) {
$packageDropIn = dirname($this->rootPath, 2) . $ds . 'wp-content' . $ds . 'wp-sqlite-db' . $ds . 'src' . $ds . 'db.php';
if ($bedrock) {
$packageDropIn = dirname($this->rootPath, 6) . $ds . 'wp-content' . $ds . 'wp-sqlite-db' . $ds . 'src' . $ds . 'db.php';
} else {
$packageDropIn = dirname($this->rootPath, 2) . $ds . 'wp-content' . $ds . 'wp-sqlite-db' . $ds . 'src' . $ds . 'db.php';
}
}

if (!$this->filesystem->exists($coreDropInPath)) {
Expand Down
25 changes: 25 additions & 0 deletions tests/Unit/Command/InitCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,31 @@
expect($bootstrapContents)->toContain('\tests_add_filter(\'muplugins_loaded\', \'_register_theme\');');
});

it("checks that the command creates folder with correct templates for a theme with bedrock", function () {

TestCommand::for($this->command)
->addArgument('theme')
->addOption('--theme-slug', 'twentytwentyfour')
->addOption('--bedrock')
->execute()
->assertSuccessful();

// Check if the files were created, as intended.
expect($this->outputDir)->toBeDirectory();

$ds = DIRECTORY_SEPARATOR;

$bootstrapFilePath = "{$this->outputDir}{$ds}web{$ds}app{$ds}themes{$ds}twentytwentyfour{$ds}tests{$ds}bootstrap.php";

// Check if correct file is copied over.
expect($bootstrapFilePath)->toBeReadableFile();

// Ensure the contents are correct.
$bootstrapContents = file_get_contents($bootstrapFilePath);

expect($bootstrapContents)->toContain('\tests_add_filter(\'muplugins_loaded\', \'_register_theme\');');
});

it("checks that the command will fail if the theme slug is not provided", function () {
TestCommand::for($this->command)
->addArgument('theme')
Expand Down

0 comments on commit dbbc031

Please sign in to comment.