|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace NerdsAndCompany\Schematic\Converters\Models; |
|
4
|
|
|
|
|
5
|
|
|
use Craft; |
|
6
|
|
|
use craft\models\TagGroup as TagGroupModel; |
|
7
|
|
|
use Codeception\Test\Unit; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class TagGroupTest. |
|
11
|
|
|
* |
|
12
|
|
|
* @author Nerds & Company |
|
13
|
|
|
* @copyright Copyright (c) 2015-2017, Nerds & Company |
|
14
|
|
|
* @license MIT |
|
15
|
|
|
* |
|
16
|
|
|
* @see http://www.nerds.company |
|
17
|
|
|
*/ |
|
18
|
|
|
class TagGroupTest extends Unit |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var TagGroup |
|
22
|
|
|
*/ |
|
23
|
|
|
private $converter; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Set the converter. |
|
27
|
|
|
* |
|
28
|
|
|
* @SuppressWarnings(PHPMD.CamelCaseMethodName) |
|
29
|
|
|
* phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
30
|
|
|
*/ |
|
31
|
|
|
protected function _before() |
|
32
|
|
|
{ |
|
33
|
|
|
$this->converter = new TagGroup(); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
//============================================================================================================== |
|
37
|
|
|
//================================================= TESTS ==================================================== |
|
38
|
|
|
//============================================================================================================== |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @dataProvider provideTagGroups |
|
42
|
|
|
* |
|
43
|
|
|
* @param TagGroupModel $group |
|
44
|
|
|
* @param array $definition |
|
45
|
|
|
*/ |
|
46
|
|
|
public function testGetRecordDefinition(TagGroupModel $group, array $definition) |
|
47
|
|
|
{ |
|
48
|
|
|
$result = $this->converter->getRecordDefinition($group); |
|
49
|
|
|
|
|
50
|
|
|
$this->assertSame($definition, $result); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @dataProvider provideTagGroups |
|
55
|
|
|
* |
|
56
|
|
|
* @param TagGroupModel $group |
|
57
|
|
|
* @param array $definition |
|
58
|
|
|
*/ |
|
59
|
|
|
public function testSaveRecord(TagGroupModel $group, array $definition) |
|
60
|
|
|
{ |
|
61
|
|
|
Craft::$app->tags->expects($this->exactly(1)) |
|
62
|
|
|
->method('saveTagGroup') |
|
63
|
|
|
->with($group) |
|
64
|
|
|
->willReturn(true); |
|
65
|
|
|
|
|
66
|
|
|
$result = $this->converter->saveRecord($group, $definition); |
|
67
|
|
|
|
|
68
|
|
|
$this->assertTrue($result); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @dataProvider provideTagGroups |
|
73
|
|
|
* |
|
74
|
|
|
* @param TagGroupModel $group |
|
75
|
|
|
*/ |
|
76
|
|
|
public function testDeleteRecord(TagGroupModel $group) |
|
77
|
|
|
{ |
|
78
|
|
|
Craft::$app->tags->expects($this->exactly(1)) |
|
79
|
|
|
->method('deleteTagGroupById') |
|
80
|
|
|
->with($group->id); |
|
81
|
|
|
|
|
82
|
|
|
$this->converter->deleteRecord($group); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
//============================================================================================================== |
|
86
|
|
|
//============================================== PROVIDERS =================================================== |
|
87
|
|
|
//============================================================================================================== |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @return array |
|
91
|
|
|
*/ |
|
92
|
|
|
public function provideTagGroups() |
|
93
|
|
|
{ |
|
94
|
|
|
$mockTagGroup = $this->getMockTagGroup(1); |
|
95
|
|
|
|
|
96
|
|
|
return [ |
|
97
|
|
|
'valid tag group' => [ |
|
98
|
|
|
'group' => $mockTagGroup, |
|
99
|
|
|
'definition' => $this->getMockTagGroupDefinition($mockTagGroup), |
|
100
|
|
|
], |
|
101
|
|
|
]; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
//============================================================================================================== |
|
105
|
|
|
//================================================ HELPERS =================================================== |
|
106
|
|
|
//============================================================================================================== |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @param int $tagGroupId |
|
110
|
|
|
* |
|
111
|
|
|
* @return TagGroupModel |
|
112
|
|
|
*/ |
|
113
|
|
|
private function getMockTagGroup(int $tagGroupId) |
|
114
|
|
|
{ |
|
115
|
|
|
return new TagGroupModel([ |
|
116
|
|
|
'id' => $tagGroupId, |
|
117
|
|
|
'handle' => 'tagGroupHandle'.$tagGroupId, |
|
118
|
|
|
'name' => 'tagGroupName'.$tagGroupId, |
|
119
|
|
|
]); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @param TagGroupModel $tagGroup |
|
124
|
|
|
* |
|
125
|
|
|
* @return array |
|
126
|
|
|
*/ |
|
127
|
|
|
private function getMockTagGroupDefinition(TagGroupModel $tagGroup) |
|
128
|
|
|
{ |
|
129
|
|
|
return [ |
|
130
|
|
|
'class' => get_class($tagGroup), |
|
131
|
|
|
'attributes' => [ |
|
132
|
|
|
'name' => 'tagGroupName'.$tagGroup->id, |
|
133
|
|
|
'handle' => 'tagGroupHandle'.$tagGroup->id, |
|
134
|
|
|
], |
|
135
|
|
|
]; |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|