devel_wizard-2.x-dev/tests/src/Drush/TaxonomyVocabularySpellCommandsTest.php
tests/src/Drush/TaxonomyVocabularySpellCommandsTest.php
<?php
declare(strict_types=1);
namespace Drupal\Tests\devel_wizard\Drush;
/**
* @group drush.command
* @group devel_wizard
* @group devel_wizard.spell
* @group devel_wizard.spell.taxonomy_vocabulary
* @group devel_wizard.spell.taxonomy_vocabulary.all_in_one
*
* @covers \Drupal\devel_wizard\Commands\TaxonomyVocabularySpellCommands
*/
class TaxonomyVocabularySpellCommandsTest extends DrushTestCase {
protected static string $command = 'devel-wizard:spell:taxonomy-vocabulary';
public function testRunSuccess(): void {
$taxonomyVocabularyId = 'wizard';
$drupalRoot = static::getDrupalRoot();
$expectedFiles = [
[
'{{ path }}' => "../tests/behat/features/$taxonomyVocabularyId/$taxonomyVocabularyId.access.create.feature",
'{{ message }}' => " Message: devel_wizard_taxonomy_vocabulary_behat - file has been created: \n{{ path }} ",
],
[
'{{ path }}' => "../tests/behat/features/$taxonomyVocabularyId/$taxonomyVocabularyId.access.delete.feature",
'{{ message }}' => " Message: devel_wizard_taxonomy_vocabulary_behat - file has been created: \n{{ path }} ",
],
[
'{{ path }}' => "../tests/behat/features/$taxonomyVocabularyId/$taxonomyVocabularyId.access.edit.feature",
'{{ message }}' => " Message: devel_wizard_taxonomy_vocabulary_behat - file has been created: \n{{ path }} ",
],
[
'{{ path }}' => "../tests/behat/features/$taxonomyVocabularyId/$taxonomyVocabularyId.access.view.feature",
'{{ message }}' => " Message: devel_wizard_taxonomy_vocabulary_behat - file has been created: \n{{ path }} ",
],
[
'{{ path }}' => "../tests/behat/features/$taxonomyVocabularyId/$taxonomyVocabularyId.form.create.feature",
'{{ message }}' => " Message: devel_wizard_taxonomy_vocabulary_behat - file has been created: \n{{ path }} ",
],
[
'{{ path }}' => "../tests/behat/features/$taxonomyVocabularyId/$taxonomyVocabularyId.form.edit.feature",
'{{ message }}' => " Message: devel_wizard_taxonomy_vocabulary_behat - file has been created: \n{{ path }} ",
],
];
foreach ($expectedFiles as $expectedFile) {
static::assertFileDoesNotExist("$drupalRoot/{$expectedFile['{{ path }}']}");
}
$envVars = [];
$envVars += $this->getCommonCommandLineEnvVars();
$args = [
$taxonomyVocabularyId,
];
$options = [];
$options += $this->getCommonCommandLineOptions();
$this->drush(
static::$command,
$args,
$options,
NULL,
NULL,
0,
NULL,
$envVars,
);
$actualStdError = $this->getErrorOutput();
$actualStdOutput = $this->getOutput();
foreach ($expectedFiles as $expectedFile) {
if (isset($expectedFile['{{ message }}'])) {
$message = strtr($expectedFile['{{ message }}'], $expectedFile);
static::assertStringContainsString($message, $actualStdError);
}
static::assertFileExists("$drupalRoot/{$expectedFile['{{ path }}']}");
}
static::assertSame('', $actualStdOutput, 'StdOutput');
}
public function testRunFailInvalidMachineName(): void {
$taxonomyVocabularyId = '0a b';
$envVars = [];
$envVars += $this->getCommonCommandLineEnvVars();
$args = [
$taxonomyVocabularyId,
];
$options = [];
$options += $this->getCommonCommandLineOptions();
$this->drush(
static::$command,
$args,
$options,
NULL,
NULL,
1,
NULL,
$envVars,
);
$actualStdError = $this->getErrorOutput();
$actualStdOutput = $this->getOutput();
static::assertStringContainsString(
"Machine name must only contain lowercase letters, numbers, and underscores",
$actualStdError,
'StdError',
);
static::assertSame('', $actualStdOutput, 'StdOutput');
}
}
