Skip to content

Commit c4f3f51

Browse files
committed
Added d8:component:test command.
1 parent 3fc9848 commit c4f3f51

File tree

7 files changed

+207
-3
lines changed

7 files changed

+207
-3
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace DrupalCodeGenerator\Commands\Drupal_8\Component;
4+
5+
use Symfony\Component\Console\Input\InputInterface;
6+
use Symfony\Component\Console\Output\OutputInterface;
7+
use DrupalCodeGenerator\Commands\BaseGenerator;
8+
9+
/**
10+
* Implements d8:component:test command.
11+
*/
12+
class Test extends BaseGenerator {
13+
14+
protected $name = 'd8:component:test';
15+
protected $description = 'Generates a test';
16+
17+
/**
18+
* {@inheritdoc}
19+
*/
20+
protected function interact(InputInterface $input, OutputInterface $output) {
21+
22+
$questions = [
23+
'name' => ['Module name', [$this, 'defaultName']],
24+
'machine_name' => ['Module machine name', [$this, 'defaultMachineName']],
25+
'test_name' => ['Test name', 'Example'],
26+
];
27+
$vars = $this->collectVars($input, $output, $questions);
28+
$vars['class'] = $this->human2class($vars['test_name'] . 'Test');
29+
30+
$this->files[$vars['class'] . '.php'] = $this->render('d8/test.twig', $vars);
31+
}
32+
33+
/**
34+
* Creates default plugin ID.
35+
*/
36+
protected function defaultPluginId($vars) {
37+
return $vars['machine_name'] . '_' . $this->human2machine($vars['plugin_label']);
38+
}
39+
40+
}

src/Commands/Navigation.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ protected function createMenuItemLabel($menu_item, $comment) {
160160
'd7' => 'Drupal 7',
161161
'd8' => 'Drupal 8',
162162
'js' => 'MODULE.js',
163-
'test' => 'MODULE.test',
164163
'html-page' => 'HTML page',
165164
'install' => 'MODULE.install',
166165
'module-file' => 'MODULE.module',

src/Templates/d8/test.twig

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
/**
4+
* @file
5+
* Contains \Drupal\{{ machine_name }}\Tests\{{ class }}.
6+
*/
7+
8+
namespace Drupal\{{ machine_name }}\Tests;
9+
10+
use Drupal\simpletest\WebTestBase;
11+
12+
/**
13+
* Tests the creation of text fields.
14+
*
15+
* @group {{ machine_name }}
16+
*/
17+
class {{ class }} extends WebTestBase {
18+
19+
/**
20+
* Modules to enable.
21+
*
22+
* @var array
23+
*/
24+
public static $modules = [
25+
'node',
26+
'field',
27+
'contact',
28+
'views',
29+
'taxonomy',
30+
];
31+
32+
/**
33+
* {@inheritdoc}
34+
*/
35+
protected function setUp() {
36+
parent::setUp();
37+
38+
$user = $this->drupalCreateUser([
39+
'administer site configuration',
40+
]);
41+
$this->drupalLogin($user);
42+
}
43+
44+
/**
45+
* Test site information form.
46+
*/
47+
public function testFieldStorageSettingsForm() {
48+
$edit = [
49+
'site_name' => 'Drupal',
50+
'site_slogan' => 'Community plumbing',
51+
'site_mail' => '[email protected]',
52+
'site_frontpage' => '/user',
53+
];
54+
55+
$this->drupalPostForm('admin/config/system/site-information', $edit, t('Save configuration'));
56+
$this->assertText(t('The configuration options have been saved.'), 'Configuration options have been saved');
57+
}
58+
59+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace DrupalCodeGenerator\Tests\Drupal_8\Component\Plugin;
4+
5+
use DrupalCodeGenerator\Tests\GeneratorTestCase;
6+
7+
/**
8+
* Test for d8:component:test command.
9+
*/
10+
class Test extends GeneratorTestCase {
11+
12+
/**
13+
* {@inheritdoc}
14+
*/
15+
public function setUp() {
16+
$this->class = 'Drupal_8\Component\Test';
17+
$this->answers = [
18+
'Foo',
19+
'foo',
20+
'Example',
21+
];
22+
$this->target = 'ExampleTest.php';
23+
$this->fixture = __DIR__ . '/_test_' . $this->target;
24+
25+
// Add suffix to prevent phpunit from loading this file.
26+
$this->fixture .= '_';
27+
28+
parent::setUp();
29+
}
30+
31+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
/**
4+
* @file
5+
* Contains \Drupal\foo\Tests\ExampleTest.
6+
*/
7+
8+
namespace Drupal\foo\Tests;
9+
10+
use Drupal\simpletest\WebTestBase;
11+
12+
/**
13+
* Tests the creation of text fields.
14+
*
15+
* @group foo
16+
*/
17+
class ExampleTest extends WebTestBase {
18+
19+
/**
20+
* Modules to enable.
21+
*
22+
* @var array
23+
*/
24+
public static $modules = [
25+
'node',
26+
'field',
27+
'contact',
28+
'views',
29+
'taxonomy',
30+
];
31+
32+
/**
33+
* {@inheritdoc}
34+
*/
35+
protected function setUp() {
36+
parent::setUp();
37+
38+
$user = $this->drupalCreateUser([
39+
'administer site configuration',
40+
]);
41+
$this->drupalLogin($user);
42+
}
43+
44+
/**
45+
* Test site information form.
46+
*/
47+
public function testFieldStorageSettingsForm() {
48+
$edit = [
49+
'site_name' => 'Drupal',
50+
'site_slogan' => 'Community plumbing',
51+
'site_mail' => '[email protected]',
52+
'site_frontpage' => '/user',
53+
];
54+
55+
$this->drupalPostForm('admin/config/system/site-information', $edit, t('Save configuration'));
56+
$this->assertText(t('The configuration options have been saved.'), 'Configuration options have been saved');
57+
}
58+
59+
}

src/Tests/GeneratorsDiscoveryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
class GeneratorsDiscoveryTest extends \PHPUnit_Framework_TestCase {
1414

15-
const TOTAL_GENERATORS = 24;
15+
const TOTAL_GENERATORS = 25;
1616

1717
/**
1818
* Test callback.

src/Tests/integration-fixtures.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@
194194
'answers' => [
195195
'<comment>Drupal 7</comment>',
196196
'<comment>Component</comment>',
197-
'MODULE.test',
197+
'Test',
198198
'Example',
199199
'example',
200200
'ExampleTestCase',
@@ -312,6 +312,22 @@
312312
'- ZooFormatter.php',
313313
],
314314
],
315+
[
316+
'answers' => [
317+
'<comment>Drupal 8</comment>',
318+
'<comment>Component</comment>',
319+
'Test',
320+
'Foo',
321+
'foo',
322+
'Example',
323+
],
324+
'output' => [
325+
'Command: d8:component:test',
326+
'--------------------------',
327+
'The following files have been created:',
328+
'- ExampleTest.php',
329+
],
330+
],
315331
[
316332
'answers' => [
317333
'<comment>Drupal 8</comment>',

0 commit comments

Comments
 (0)