1 | <?php |
||
27 | class PluginsTest extends BaseTest |
||
28 | { |
||
29 | /** |
||
30 | * @var Plugins |
||
31 | */ |
||
32 | private $schematicPluginsService; |
||
33 | |||
34 | /** |
||
35 | * @var string |
||
36 | */ |
||
37 | private $pluginHandle; |
||
38 | |||
39 | /** |
||
40 | * {@inheritdoc} |
||
41 | */ |
||
42 | public function setUp() |
||
46 | |||
47 | /** |
||
48 | * Prevent code duplication by mocking multiple services. |
||
49 | * |
||
50 | * @param bool $returnPlugin |
||
51 | * @param bool $installPluginResponse |
||
52 | */ |
||
53 | public function mockMultipleServices( |
||
62 | |||
63 | /** |
||
64 | * @param bool $returnPlugin |
||
65 | * @param bool $installPluginResponse |
||
66 | * @param bool $enablePluginResponse |
||
67 | * @param bool $disablePluginResponse |
||
68 | * @param bool $uninstallPluginResponse |
||
69 | * |
||
70 | * @return PluginsService|Mock |
||
71 | */ |
||
72 | public function getMockPluginsService( |
||
95 | |||
96 | /** |
||
97 | * @return UpdatesService|Mock |
||
98 | */ |
||
99 | public function getMockUpdatesService() |
||
106 | |||
107 | /** |
||
108 | * @return Mock|BasePlugin |
||
109 | */ |
||
110 | public function getMockBasePlugin() |
||
118 | |||
119 | /** |
||
120 | * Test default import functionality. |
||
121 | * |
||
122 | * @covers ::import |
||
123 | */ |
||
124 | public function testImportWithInstalledPlugins() |
||
125 | { |
||
126 | $data = $this->getPluginsData(); |
||
127 | |||
128 | $this->mockMultipleServices(); |
||
129 | |||
130 | $import = $this->schematicPluginsService->import($data); |
||
131 | |||
132 | $this->assertTrue($import instanceof Result); |
||
133 | $this->assertFalse($import->hasErrors()); |
||
134 | } |
||
135 | |||
136 | /** |
||
137 | * Test default import functionality. |
||
138 | * |
||
139 | * @covers ::import |
||
140 | */ |
||
141 | public function testImportWithInstalledDisabledPlugins() |
||
142 | { |
||
143 | $this->getMockBasePlugin(); |
||
144 | |||
145 | $data = $this->getPluginsData(); |
||
146 | $data[$this->pluginHandle]['isEnabled'] = false; |
||
147 | |||
148 | $this->mockMultipleServices(); |
||
149 | |||
150 | $import = $this->schematicPluginsService->import($data); |
||
151 | |||
152 | $this->assertTrue($import instanceof Result); |
||
153 | $this->assertFalse($import->hasErrors()); |
||
154 | } |
||
155 | |||
156 | /** |
||
157 | * Test default import functionality. |
||
158 | * |
||
159 | * @covers ::import |
||
160 | */ |
||
161 | public function testImportWithMissingPlugin() |
||
162 | { |
||
163 | $data = $this->getPluginsData(); |
||
164 | |||
165 | $this->mockMultipleServices(false); |
||
166 | |||
167 | $import = $this->schematicPluginsService->import($data); |
||
168 | |||
169 | $this->assertTrue($import instanceof Result); |
||
170 | $this->assertTrue($import->hasErrors()); |
||
171 | } |
||
172 | |||
173 | /** |
||
174 | * Test default import functionality. |
||
175 | * |
||
176 | * @covers ::import |
||
177 | */ |
||
178 | public function testImportWithInstallException() |
||
179 | { |
||
180 | $data = $this->getPluginsData(); |
||
181 | |||
182 | $this->mockMultipleServices(true, false); |
||
183 | |||
184 | $import = $this->schematicPluginsService->import($data); |
||
185 | |||
186 | $this->assertTrue($import instanceof Result); |
||
187 | $this->assertTrue($import->hasErrors()); |
||
188 | } |
||
189 | |||
190 | /** |
||
191 | * Test default import functionality. |
||
192 | * |
||
193 | * @covers ::import |
||
194 | */ |
||
195 | public function testImportWithNotInstalledPlugin() |
||
196 | { |
||
197 | $this->mockMultipleServices(); |
||
198 | |||
199 | $this->getMockBasePlugin(); |
||
200 | |||
201 | $data = $this->getPluginsData(); |
||
202 | $data[$this->pluginHandle]['isInstalled'] = false; |
||
203 | |||
204 | $import = $this->schematicPluginsService->import($data); |
||
205 | |||
206 | $this->assertTrue($import instanceof Result); |
||
207 | $this->assertFalse($import->hasErrors()); |
||
208 | } |
||
209 | |||
210 | /** |
||
211 | * Test export functionality. |
||
212 | * |
||
213 | * @covers ::export |
||
214 | */ |
||
215 | public function testExport() |
||
238 | |||
239 | /** |
||
240 | * Returns plugins data. |
||
241 | * |
||
242 | * @return array |
||
243 | */ |
||
244 | public function getPluginsData() |
||
258 | } |
||
259 |