1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverLeague\Console\Tests\Command\Object; |
4
|
|
|
|
5
|
|
|
use SilverLeague\Console\Command\Object\ExtensionsCommand; |
6
|
|
|
use SilverLeague\Console\Tests\Command\AbstractCommandTest; |
7
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @coversDefaultClass \SilverLeague\Console\Command\Object\ExtensionsCommand |
11
|
|
|
* @package silverstripe-console |
12
|
|
|
* @author Robbie Averill <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
class ExtensionsCommandTest extends AbstractCommandTest |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* {@inheritDoc} |
18
|
|
|
*/ |
19
|
|
|
public function getTestCommand() |
20
|
|
|
{ |
21
|
|
|
return 'object:extensions'; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Ensure that the Injector's class resolution is returned for a given Object |
26
|
|
|
* |
27
|
|
|
* @covers ::execute |
28
|
|
|
*/ |
29
|
|
|
public function testExecute() |
30
|
|
|
{ |
31
|
|
|
$tester = new CommandTester($this->command); |
32
|
|
|
$tester->execute( |
33
|
|
|
[ |
34
|
|
|
'command' => $this->command->getName(), |
35
|
|
|
'object' => "SilverStripe\Forms\GridField\GridFieldDetailForm" |
36
|
|
|
] |
37
|
|
|
); |
38
|
|
|
|
39
|
|
|
$output = $tester->getDisplay(); |
40
|
|
|
$this->assertContains("SilverStripe\ORM\Versioning\VersionedGridFieldDetailForm", $output); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Ensure that the InputArgument for the object is added |
45
|
|
|
* |
46
|
|
|
* @covers ::configure |
47
|
|
|
*/ |
48
|
|
|
public function testConfigure() |
49
|
|
|
{ |
50
|
|
|
$this->assertTrue($this->command->getDefinition()->hasArgument('object')); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Ensure that extra headers are added for CMS pages |
55
|
|
|
* |
56
|
|
|
* @covers ::getHeaders |
57
|
|
|
* @dataProvider headerProvider |
58
|
|
|
* |
59
|
|
|
* @param bool $isCms |
60
|
|
|
* @param string[] $expected |
61
|
|
|
*/ |
62
|
|
|
public function testGetHeaders($isCms, $expected) |
63
|
|
|
{ |
64
|
|
|
$this->assertSame($expected, $this->command->getHeaders($isCms)); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return string[] |
69
|
|
|
*/ |
70
|
|
|
public function headerProvider() |
71
|
|
|
{ |
72
|
|
|
return [ |
73
|
|
|
[true, ['Class name', 'Added DB fields', 'Updates CMS fields']], |
74
|
|
|
[false, ['Class name', 'Added DB fields']] |
75
|
|
|
]; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Ensure that extra headers are added for CMS pages |
80
|
|
|
* |
81
|
|
|
* @covers ::getRows |
82
|
|
|
* @dataProvider rowsProvider |
83
|
|
|
* |
84
|
|
|
* @param bool $isCms |
85
|
|
|
* @param array $extensions |
86
|
|
|
* @param string[] $expected |
87
|
|
|
*/ |
88
|
|
|
public function testGetRows($isCms, $extensions, $expected) |
89
|
|
|
{ |
90
|
|
|
$this->assertSame($expected, $this->command->getRows($isCms, $extensions)); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return array[] |
95
|
|
|
*/ |
96
|
|
|
public function rowsProvider() |
97
|
|
|
{ |
98
|
|
|
$extensions = [ |
99
|
|
|
"SilverStripe\Assets\AssetControlExtension" |
100
|
|
|
]; |
101
|
|
|
|
102
|
|
|
return [ |
103
|
|
|
[ |
104
|
|
|
false, |
105
|
|
|
$extensions, |
106
|
|
|
[array_merge($extensions, [0])] |
107
|
|
|
], |
108
|
|
|
[ |
109
|
|
|
true, |
110
|
|
|
$extensions, |
111
|
|
|
[array_merge($extensions, [0, 'Yes'])] |
112
|
|
|
] |
113
|
|
|
]; |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|