Skip to content

Commit

Permalink
Issue2784 (#2807)
Browse files Browse the repository at this point in the history
* Very simple test option in generate:module see also Issue #2784

* Update load-test.php.twig

fix missing newline
  • Loading branch information
NickDickinsonWilde authored and jmolivas committed Oct 15, 2016
1 parent e6d1111 commit 1788496
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 2 deletions.
19 changes: 18 additions & 1 deletion src/Command/Generate/ModuleCommand.php
Expand Up @@ -157,6 +157,12 @@ protected function configure()
'',
InputOption::VALUE_OPTIONAL,
$this->trans('commands.generate.module.options.dependencies')
)
->addOption(
'test',
'',
InputOption::VALUE_OPTIONAL,
$this->trans('commands.generate.module.options.test')
);
}

Expand Down Expand Up @@ -185,6 +191,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$moduleFile = $input->getOption('module-file');
$featuresBundle = $input->getOption('features-bundle');
$composer = $input->getOption('composer');
$test = $input->getOption('test');

// Modules Dependencies, re-factor and share with other commands
$dependencies = $this->validator->validateModuleDependencies($input->getOption('dependencies'));
Expand Down Expand Up @@ -212,7 +219,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
$moduleFile,
$featuresBundle,
$composer,
$dependencies
$dependencies,
$test
);
}

Expand Down Expand Up @@ -417,6 +425,15 @@ function ($core) {
}
$input->setOption('dependencies', $dependencies);
}

$test = $input->getOption('test');
if (!$test) {
$test = $io->confirm(
$this->trans('commands.generate.module.questions.test'),
true
);
$input->setOption('test', $test);
}
}

/**
Expand Down
13 changes: 12 additions & 1 deletion src/Generator/ModuleGenerator.php
Expand Up @@ -24,6 +24,7 @@ class ModuleGenerator extends Generator
* @param $featuresBundle
* @param $composer
* @param $dependencies
* @param $test
*/
public function generate(
$module,
Expand All @@ -35,7 +36,8 @@ public function generate(
$moduleFile,
$featuresBundle,
$composer,
$dependencies
$dependencies,
$test
) {
$dir .= '/'.$machineName;
if (file_exists($dir)) {
Expand Down Expand Up @@ -74,6 +76,7 @@ public function generate(
'description' => $description,
'package' => $package,
'dependencies' => $dependencies,
'test' => $test,
);

$this->renderFile(
Expand Down Expand Up @@ -107,5 +110,13 @@ public function generate(
$parameters
);
}

if ($test) {
$this->renderFile(
'module/src/Tests/load-test.php.twig',
$dir . '/src/Tests/' . 'LoadTest.php',
$parameters
);
}
}
}
54 changes: 54 additions & 0 deletions templates/module/src/Tests/load-test.php.twig
@@ -0,0 +1,54 @@
{% extends "base/class.php.twig" %}

{% block file_path %}
\Drupal\{{ module }}\Tests\LoadTest
{% endblock %}

{% block namespace_class %}
namespace Drupal\{{ module }}\Tests;
{% endblock %}

{% block use_class %}
use Drupal\Core\Url;
use Drupal\simpletest\WebTestBase;
{% endblock %}

{% block class_declaration %}
/**
* Simple test to ensure that main page loads with module enabled.
*
* @group {{ module }}
*/
class LoadTest extends WebTestBase{% endblock %}
{% block class_methods %}
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['{{ module }}'];

/**
* A user with permission to administer site configuration.
*
* @var \Drupal\user\UserInterface
*/
protected $user;

/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->user = $this->drupalCreateUser(['administer site configuration']);
$this->drupalLogin($this->user);
}

/**
* Tests that the home page loads with a 200 response.
*/
public function testLoad() {
$this->drupalGet(Url::fromRoute('<front>'));
$this->assertResponse(200);
}
{% endblock %}

0 comments on commit 1788496

Please sign in to comment.