1 | <?php |
||
30 | class CategoryGroupsTest extends BaseTest |
||
31 | { |
||
32 | //============================================================================================================== |
||
33 | //================================================= TESTS ==================================================== |
||
34 | //============================================================================================================== |
||
35 | |||
36 | /** |
||
37 | * @covers ::export |
||
38 | * @dataProvider provideValidCategoryGroups |
||
39 | * |
||
40 | * @param CategoryGroupModel[] $groups |
||
41 | * @param array $expectedResult |
||
42 | */ |
||
43 | public function testSuccessfulExport(array $groups, array $expectedResult = []) |
||
54 | |||
55 | /** |
||
56 | * @covers ::import |
||
57 | * @dataProvider provideValidCategoryGroupDefinitions |
||
58 | * |
||
59 | * @param array $groupDefinitions |
||
60 | */ |
||
61 | public function testSuccessfulImport(array $groupDefinitions) |
||
62 | { |
||
63 | $this->setMockCategoriesService(); |
||
64 | $this->setMockDbConnection(); |
||
65 | $this->setMockSchematicFields(); |
||
66 | |||
67 | $schematicUserGroupsService = new CategoryGroups(); |
||
68 | |||
69 | $import = $schematicUserGroupsService->import($groupDefinitions); |
||
70 | |||
71 | $this->assertInstanceOf(Result::class, $import); |
||
72 | $this->assertFalse($import->hasErrors()); |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * @covers ::import |
||
77 | * @dataProvider provideValidCategoryGroupDefinitions |
||
78 | * |
||
79 | * @param array $groupDefinitions |
||
80 | */ |
||
81 | public function testImportWithForceOption(array $groupDefinitions) |
||
82 | { |
||
83 | $this->setMockCategoriesService(); |
||
84 | $this->setMockDbConnection(); |
||
85 | $this->setMockSchematicFields(); |
||
86 | |||
87 | $schematicUserGroupsService = new CategoryGroups(); |
||
88 | |||
89 | $import = $schematicUserGroupsService->import($groupDefinitions, true); |
||
90 | |||
91 | $this->assertInstanceOf(Result::class, $import); |
||
92 | $this->assertFalse($import->hasErrors()); |
||
93 | } |
||
94 | |||
95 | //============================================================================================================== |
||
96 | //============================================== PROVIDERS =================================================== |
||
97 | //============================================================================================================== |
||
98 | |||
99 | /** |
||
100 | * @return array |
||
101 | */ |
||
102 | public function provideValidCategoryGroups() |
||
171 | |||
172 | /** |
||
173 | * @return array |
||
174 | */ |
||
175 | public function provideValidCategoryGroupDefinitions() |
||
202 | |||
203 | //============================================================================================================== |
||
204 | //================================================= MOCKS ==================================================== |
||
205 | //============================================================================================================== |
||
206 | |||
207 | /** |
||
208 | * @param string $groupId |
||
209 | * |
||
210 | * @return Mock|CategoryGroupModel |
||
211 | */ |
||
212 | private function getMockCategoryGroup($groupId) |
||
239 | |||
240 | /** |
||
241 | * @return Mock|CraftFieldsService |
||
242 | */ |
||
243 | private function setMockFieldsService() |
||
244 | { |
||
245 | $mockFieldsService = $this->getMockBuilder(FieldsService::class) |
||
246 | ->disableOriginalConstructor() |
||
247 | ->getMock(); |
||
248 | |||
249 | $mockFieldsService->expects($this->any()) |
||
250 | ->method('getLayoutById') |
||
251 | ->with($this->isType('integer')) |
||
252 | ->willReturn($this->getMockFieldLayout()); |
||
253 | |||
254 | $this->setComponent(Craft::app(), 'fields', $mockFieldsService); |
||
255 | |||
256 | return $mockFieldsService; |
||
257 | } |
||
258 | |||
259 | /** |
||
260 | * @return Mock|fields |
||
261 | */ |
||
262 | private function setMockSchematicFields() |
||
282 | |||
283 | /** |
||
284 | * @return Mock|CategoriesService |
||
285 | */ |
||
286 | private function setMockCategoriesService() |
||
287 | { |
||
288 | $mockCategoriesService = $this->getMockBuilder(CategoriesService::class) |
||
289 | ->disableOriginalConstructor() |
||
290 | ->getMock(); |
||
291 | |||
292 | $mockCategoriesService->expects($this->any()) |
||
293 | ->method('getAllGroups') |
||
294 | ->with('handle') |
||
295 | ->willReturn([]); |
||
296 | |||
297 | $this->setComponent(Craft::app(), 'categories', $mockCategoriesService); |
||
298 | |||
299 | return $mockCategoriesService; |
||
300 | } |
||
301 | |||
302 | |||
303 | /** |
||
304 | * @return Mock|FieldLayoutModel |
||
305 | */ |
||
306 | private function getMockFieldLayout() |
||
314 | |||
315 | /** |
||
316 | * @return Mock|CategoryGroupLocaleModel |
||
317 | */ |
||
318 | private function getMockCategoryGroupLocale() |
||
332 | |||
333 | /** |
||
334 | * @return Mock|DbConnection |
||
335 | */ |
||
336 | private function setMockDbConnection() |
||
352 | |||
353 | /** |
||
354 | * @return Mock|DbCommand |
||
355 | */ |
||
356 | private function getMockDbCommand() |
||
365 | } |
||
366 |