1 | <?php |
||
34 | class SchematicTest extends BaseTest |
||
35 | { |
||
36 | /** |
||
37 | * @var Schematic |
||
38 | */ |
||
39 | private $schematicService; |
||
40 | |||
41 | /** |
||
42 | * {@inheritdoc} |
||
43 | */ |
||
44 | public function setUp() |
||
49 | |||
50 | /** |
||
51 | * @return string |
||
52 | */ |
||
53 | private function getYamlTestFile() |
||
57 | |||
58 | /** |
||
59 | * @return string |
||
60 | */ |
||
61 | private function getYamlExportFile() |
||
65 | |||
66 | /** |
||
67 | * @param string $handle |
||
68 | * @param Mock $mock |
||
69 | */ |
||
70 | private function setCraftComponent($handle, Mock $mock) |
||
74 | |||
75 | /** |
||
76 | * @return Mock|FieldsService |
||
77 | */ |
||
78 | public function getMockFieldsService() |
||
88 | |||
89 | /** |
||
90 | * @param string $class |
||
91 | * @param string $method |
||
92 | * @param Invocation $invocation |
||
93 | * @param mixed $returnValue |
||
94 | * |
||
95 | * @return Mock |
||
96 | */ |
||
97 | public function getDynamicallyMockedService($class, $method, Invocation $invocation, $returnValue) |
||
105 | |||
106 | /** |
||
107 | * @return Mock|GlobalsService |
||
108 | */ |
||
109 | public function getMockGlobalsService() |
||
119 | |||
120 | /** |
||
121 | * @return Mock|SectionsService |
||
122 | */ |
||
123 | public function getMockSectionsService() |
||
133 | |||
134 | /** |
||
135 | * @return Mock|Result |
||
136 | */ |
||
137 | public function getMockResultModel() |
||
145 | |||
146 | /** |
||
147 | * Creates mock for service. |
||
148 | * |
||
149 | * @param string $service |
||
150 | * @param string $handle |
||
151 | */ |
||
152 | private function createMockService($service, $handle) |
||
163 | |||
164 | /** |
||
165 | * @return Base|Mock |
||
166 | */ |
||
167 | public function getMockAbstractService() |
||
176 | |||
177 | /** |
||
178 | * @return PluginsService|Mock |
||
179 | */ |
||
180 | public function getMockPluginsService() |
||
194 | |||
195 | /** |
||
196 | * @return Mock|AssetSourcesService |
||
197 | */ |
||
198 | public function getMockAssetSourcesService() |
||
208 | |||
209 | /** |
||
210 | * @return Mock|AssetTransformsService |
||
211 | */ |
||
212 | public function getMockAssetTransformsService() |
||
222 | |||
223 | /** |
||
224 | * @return Mock|CategoriesService |
||
225 | */ |
||
226 | public function getMockCategoriesService() |
||
236 | |||
237 | /** |
||
238 | * @return Mock|TagsService |
||
239 | */ |
||
240 | public function getMockTagsService() |
||
241 | { |
||
242 | $mock = $this->getMockBuilder(TagsService::class) |
||
243 | ->disableOriginalConstructor() |
||
244 | ->getMock(); |
||
245 | |||
246 | $mock->expects($this->exactly(1))->method('getAllTagGroups')->willReturn([]); |
||
247 | |||
248 | return $mock; |
||
249 | } |
||
250 | |||
251 | /** |
||
252 | * Mock all required services. |
||
253 | */ |
||
254 | private function mockServices() |
||
255 | { |
||
256 | $this->createMockService(Locales::class, 'schematic_locales'); |
||
257 | $this->createMockService(AssetSources::class, 'schematic_assetSources'); |
||
258 | $this->createMockService(AssetTransforms::class, 'schematic_assetTransforms'); |
||
259 | $this->createMockService(Fields::class, 'schematic_fields'); |
||
260 | $this->createMockService(GlobalSets::class, 'schematic_globalSets'); |
||
261 | $this->createMockService(Plugins::class, 'schematic_plugins'); |
||
262 | $this->createMockService(Sections::class, 'schematic_sections'); |
||
263 | $this->createMockService(UserGroups::class, 'schematic_userGroups'); |
||
264 | $this->createMockService(Users::class, 'schematic_users'); |
||
265 | $this->createMockService(CategoryGroups::class, 'schematic_categoryGroups'); |
||
266 | $this->createMockService(TagGroups::class, 'schematic_tagGroups'); |
||
267 | $this->createMockService(ElementIndexSettings::class, 'schematic_elementIndexSettings'); |
||
268 | |||
269 | $mockPluginsService = $this->getMockPluginsService(); |
||
270 | $this->setCraftComponent('plugins', $mockPluginsService); |
||
271 | } |
||
272 | |||
273 | /** |
||
274 | * Test import from Yaml. |
||
275 | * |
||
276 | * @covers ::importFromYaml |
||
277 | */ |
||
278 | public function testImportFromYamlWithForce() |
||
283 | |||
284 | /** |
||
285 | * Test import from yml excluding data types. |
||
286 | * |
||
287 | * @covers ::exportToYaml |
||
288 | */ |
||
289 | public function testImportFromYamlExcludingDataTypes() |
||
290 | { |
||
291 | //We do not want to import these DataTypes, so these import functions should not be called. |
||
292 | Craft::app()->schematic_users->expects($this->exactly(0))->method('import'); |
||
293 | Craft::app()->schematic_plugins->expects($this->exactly(0))->method('import'); |
||
294 | |||
295 | //We do want to import these DataTypes, so these import functions should be called. |
||
296 | Craft::app()->schematic_userGroups->expects($this->exactly(1))->method('import'); |
||
297 | Craft::app()->schematic_assetSources->expects($this->exactly(1))->method('import'); |
||
298 | |||
299 | $results = $this->schematicService->importFromYaml($this->getYamlTestFile(), null, false, ['assetSources', 'userGroups']); |
||
300 | $this->assertFalse($results->hasErrors()); |
||
301 | } |
||
302 | |||
303 | /** |
||
304 | * @param $service |
||
305 | * |
||
306 | * @return Mock |
||
307 | */ |
||
308 | private function getMockAllGroupsMethodService($service) |
||
312 | |||
313 | /** |
||
314 | * Prep export services. |
||
315 | */ |
||
316 | private function prepExportMockServices() |
||
345 | |||
346 | /** |
||
347 | * Test export to yml. |
||
348 | * |
||
349 | * @covers ::exportToYaml |
||
350 | */ |
||
351 | public function testExportFromYaml() |
||
358 | |||
359 | /** |
||
360 | * Test export to yml excluding data types. |
||
361 | * |
||
362 | * @covers ::exportToYaml |
||
363 | */ |
||
364 | public function testExportToYamlExcludingDataTypes() |
||
382 | |||
383 | /** |
||
384 | * Test export to yml with error writing to file. |
||
385 | * |
||
386 | * @covers ::exportToYaml |
||
387 | */ |
||
388 | public function testExportFromYamlWithFileError() |
||
395 | } |
||
396 |