forked from hechoendrupal/drupal-console
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeneratorPluginBlockCommandTest.php
More file actions
109 lines (94 loc) · 3.25 KB
/
Copy pathGeneratorPluginBlockCommandTest.php
File metadata and controls
109 lines (94 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
/**
* @file
* Contains \Drupal\AppConsole\Test\Command\GeneratorModuleCommandTest.
*/
namespace Drupal\AppConsole\Test\Command;
use Symfony\Component\Console\Tester\CommandTester;
class GeneratorPluginBlockCommandTest extends GenerateCommandTest
{
/**
* @dataProvider getDataInteractive
*/
public function testInteractiveCommand($options, $expected, $input)
{
list($module, $class_name, $plugin_label, $plugin_id, $services, $inputs) = $expected;
$generator = $this->getGenerator();
$generator
->expects($this->once())
->method('generate')
->with($module, $class_name, $plugin_label, $plugin_id, $services, $inputs);
$command = $this->getCommand($generator, $input);
$cmd = new CommandTester($command);
$cmd->execute($options);
}
public function getDataInteractive()
{
$service ['twig'] = [
'name' => 'twig',
'machine_name' => 'twig',
'class' => 'Twig_Environment',
'short' => 'Twig_Environment',
];
$inputs = [
[
'name' => 'text_field',
'type' => 'textfield',
'label' => 'Text Field',
'options' => '',
'description' => 'Description Field',
]
];
return [
// case base
[
[],
['Foo', 'FooBlock', 'Foo label', 'foo_id', null, []],
"Foo\nFooBlock\nFoo label\nfoo_id\nno\nno"
],
//case two services
[
[],
['Foo', 'FooBlock', 'Foo label', 'foo_id', $service, []],
"Foo\nFooBlock\nFoo label\nfoo_id\nyes\nyes\ntwig\n\nno\n"
],
// case three inputs
[
['--module' => 'Foo'],
['Foo', 'FooBlock', 'Foo label', 'foo_id', null, $inputs],
"FooBlock\nFoo label\nfoo_id\nno\nyes\nText Field\ntext_field\n\nDescription Field\n"
],
//case four services and inputs
[
['--module' => 'Foo'],
['Foo', 'FooBlock', 'Foo label', 'foo_id', $service, $inputs],
"FooBlock\nFoo label\nfoo_id\nyes\ntwig\n\nyes\nText Field\ntext_field\n\nDescription Field\n"
],
];
}
public function getCommand($generator, $input)
{
$command = $this->getMockBuilder('Drupal\AppConsole\Command\GeneratorPluginBlockCommand')
->setMethods(['getModules', 'getServices', '__construct'])
->setConstructorArgs([$this->getTranslationHelper()])
->getMock();
$command->expects($this->any())
->method('getModules')
->will($this->returnValue(['Foo']));
$command->expects($this->any())
->method('getServices')
->will($this->returnValue(['twig', 'database']));
$command->setGenerator($generator);
$command->setContainer($this->getContainer());
$command->setHelperSet($this->getHelperSet($input));
return $command;
}
private function getGenerator()
{
return $this
->getMockBuilder('Drupal\AppConsole\Generator\PluginBlockGenerator')
->disableOriginalConstructor()
->setMethods(['generate'])
->getMock();
}
}