1 | <?php |
||
33 | class SchematicTest extends BaseTest |
||
34 | { |
||
35 | /** |
||
36 | * @var Schematic |
||
37 | */ |
||
38 | private $schematicService; |
||
39 | |||
40 | /** |
||
41 | * {@inheritdoc} |
||
42 | */ |
||
43 | public function setUp() |
||
48 | |||
49 | /** |
||
50 | * @return string |
||
51 | */ |
||
52 | private function getYamlTestFile() |
||
56 | |||
57 | /** |
||
58 | * @return string |
||
59 | */ |
||
60 | private function getYamlExportFile() |
||
64 | |||
65 | /** |
||
66 | * @param string $handle |
||
67 | * @param Mock $mock |
||
68 | */ |
||
69 | private function setCraftComponent($handle, Mock $mock) |
||
73 | |||
74 | /** |
||
75 | * @return Mock|FieldsService |
||
76 | */ |
||
77 | public function getMockFieldsService() |
||
87 | |||
88 | /** |
||
89 | * @param string $class |
||
90 | * @param string $method |
||
91 | * @param Invocation $invocation |
||
92 | * @param mixed $returnValue |
||
93 | * |
||
94 | * @return Mock |
||
95 | */ |
||
96 | public function getDynamicallyMockedService($class, $method, Invocation $invocation, $returnValue) |
||
104 | |||
105 | /** |
||
106 | * @return Mock|GlobalsService |
||
107 | */ |
||
108 | public function getMockGlobalsService() |
||
118 | |||
119 | /** |
||
120 | * @return Mock|SectionsService |
||
121 | */ |
||
122 | public function getMockSectionsService() |
||
132 | |||
133 | /** |
||
134 | * @return Mock|Result |
||
135 | */ |
||
136 | public function getMockResultModel() |
||
144 | |||
145 | /** |
||
146 | * Creates mock for service. |
||
147 | * |
||
148 | * @param string $service |
||
149 | * @param string $handle |
||
150 | */ |
||
151 | private function createMockService($service, $handle) |
||
162 | |||
163 | /** |
||
164 | * @return Base|Mock |
||
165 | */ |
||
166 | public function getMockAbstractService() |
||
175 | |||
176 | /** |
||
177 | * @return PluginsService|Mock |
||
178 | */ |
||
179 | public function getMockPluginsService() |
||
193 | |||
194 | /** |
||
195 | * @return Mock|AssetSourcesService |
||
196 | */ |
||
197 | public function getMockAssetSourcesService() |
||
198 | { |
||
199 | $mock = $this->getMockBuilder(AssetSourcesService::class) |
||
200 | ->disableOriginalConstructor() |
||
201 | ->getMock(); |
||
202 | |||
203 | $mock->expects($this->exactly(1))->method('getAllSources')->willReturn([]); |
||
204 | |||
205 | return $mock; |
||
206 | } |
||
207 | |||
208 | /** |
||
209 | * @return Mock|CategoriesService |
||
210 | */ |
||
211 | public function getMockCategoriesService() |
||
221 | |||
222 | /** |
||
223 | * @return Mock|TagsService |
||
224 | */ |
||
225 | public function getMockTagsService() |
||
235 | |||
236 | /** |
||
237 | * Mock all required services. |
||
238 | */ |
||
239 | private function mockServices() |
||
256 | |||
257 | /** |
||
258 | * Test import from Yaml. |
||
259 | * |
||
260 | * @covers ::importFromYaml |
||
261 | */ |
||
262 | public function testImportFromYamlWithForce() |
||
267 | |||
268 | /** |
||
269 | * @param $service |
||
270 | * |
||
271 | * @return Mock |
||
272 | */ |
||
273 | private function getMockAllGroupsMethodService($service) |
||
277 | |||
278 | /** |
||
279 | * Prep export services. |
||
280 | */ |
||
281 | private function prepExportMockServices() |
||
282 | { |
||
283 | $mockPluginsService = $this->getMockPluginsService(); |
||
284 | $this->setCraftComponent('plugins', $mockPluginsService); |
||
285 | |||
286 | $mockFieldsService = $this->getMockAllGroupsMethodService(FieldsService::class); |
||
287 | $this->setCraftComponent('fields', $mockFieldsService); |
||
288 | |||
289 | $mockSectionsService = $this->getMockSectionsService(); |
||
290 | $this->setCraftComponent('sections', $mockSectionsService); |
||
291 | |||
292 | $mockGlobalsService = $this->getMockGlobalsService(); |
||
293 | $this->setCraftComponent('globals', $mockGlobalsService); |
||
294 | |||
295 | $mockUserGroupsService = $this->getMockAllGroupsMethodService(UserGroupsService::class); |
||
296 | $this->setCraftComponent('userGroups', $mockUserGroupsService); |
||
297 | |||
298 | $mockAssetSourcesService = $this->getMockAssetSourcesService(); |
||
299 | $this->setCraftComponent('assetSources', $mockAssetSourcesService); |
||
300 | |||
301 | $mockCategoriesService = $this->getMockCategoriesService(); |
||
302 | $this->setCraftComponent('categories', $mockCategoriesService); |
||
303 | |||
304 | $mockTagsService = $this->getMockTagsService(); |
||
305 | $this->setCraftComponent('tags', $mockTagsService); |
||
306 | } |
||
307 | |||
308 | /** |
||
309 | * Test export to yml. |
||
310 | * |
||
311 | * @covers ::exportToYaml |
||
312 | */ |
||
313 | public function testExportFromYaml() |
||
320 | |||
321 | /** |
||
322 | * Test export to yml excluding data types. |
||
323 | * |
||
324 | * @covers ::exportToYaml |
||
325 | */ |
||
326 | public function testExportToYamlExcludingDataTypes() |
||
344 | |||
345 | /** |
||
346 | * Test export to yml with error writing to file. |
||
347 | * |
||
348 | * @covers ::exportToYaml |
||
349 | */ |
||
350 | public function testExportFromYamlWithFileError() |
||
357 | } |
||
358 |