|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests\ShopwarePlugins\Connect\Subscribers; |
|
4
|
|
|
|
|
5
|
|
|
use ShopwarePlugins\Connect\Components\Config; |
|
6
|
|
|
use ShopwarePlugins\Connect\Components\ProductStream\ProductStreamsAssignments; |
|
7
|
|
|
use ShopwarePlugins\Connect\Subscribers\Article; |
|
8
|
|
|
use Shopware\Connect\Gateway; |
|
9
|
|
|
use Shopware\Components\Model\ModelManager; |
|
10
|
|
|
use ShopwarePlugins\Connect\Components\ConnectExport; |
|
11
|
|
|
use ShopwarePlugins\Connect\Components\ProductStream\ProductStreamService; |
|
12
|
|
|
use Tests\ShopwarePlugins\Connect\ConnectTestHelper; |
|
13
|
|
|
use Shopware\Models\Article\Article as ArticleModel; |
|
14
|
|
|
use Doctrine\ORM\EntityRepository; |
|
15
|
|
|
use ShopwarePlugins\Connect\Components\Helper; |
|
16
|
|
|
use Shopware\CustomModels\Connect\Attribute as ConnectAttribute; |
|
17
|
|
|
use Doctrine\DBAL\Connection; |
|
18
|
|
|
|
|
19
|
|
|
class ArticleTest extends ConnectTestHelper |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var Article |
|
23
|
|
|
*/ |
|
24
|
|
|
private $subscriber; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var ModelManager |
|
28
|
|
|
*/ |
|
29
|
|
|
private $modelManager; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var Helper |
|
33
|
|
|
*/ |
|
34
|
|
|
private $helper; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var ConnectExport |
|
38
|
|
|
*/ |
|
39
|
|
|
private $connectExport; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var Config |
|
43
|
|
|
*/ |
|
44
|
|
|
private $config; |
|
45
|
|
|
|
|
46
|
|
|
public function setUp() |
|
47
|
|
|
{ |
|
48
|
|
|
$this->modelManager = $this->createMock(ModelManager::class); |
|
49
|
|
|
$this->helper = $this->createMock(Helper::class); |
|
50
|
|
|
$this->connectExport = $this->createMock(ConnectExport::class); |
|
51
|
|
|
$this->config = $this->createMock(Config::class); |
|
52
|
|
|
|
|
53
|
|
|
$this->subscriber = new Article( |
|
54
|
|
|
$this->createMock(Gateway::class), |
|
55
|
|
|
$this->modelManager, |
|
56
|
|
|
$this->connectExport, |
|
57
|
|
|
$this->createMock(ProductStreamService::class), |
|
58
|
|
|
$this->helper, |
|
59
|
|
|
$this->config |
|
60
|
|
|
); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function testRegenerateChanges() |
|
64
|
|
|
{ |
|
65
|
|
|
$articleId = 5; |
|
66
|
|
|
$article = new ArticleModel(); |
|
67
|
|
|
$connectAttribute = new ConnectAttribute(); |
|
68
|
|
|
|
|
69
|
|
|
$repositoryMock = $this->createMock(EntityRepository::class); |
|
70
|
|
|
|
|
71
|
|
|
$this->modelManager->method('getRepository') |
|
72
|
|
|
->with(ArticleModel::class) |
|
73
|
|
|
->willReturn($repositoryMock); |
|
74
|
|
|
|
|
75
|
|
|
$repositoryMock->method('find') |
|
76
|
|
|
->with($articleId) |
|
77
|
|
|
->willReturn($article); |
|
78
|
|
|
|
|
79
|
|
|
$this->helper->method('getConnectAttributeByModel') |
|
|
|
|
|
|
80
|
|
|
->with($article) |
|
81
|
|
|
->willReturn($connectAttribute); |
|
82
|
|
|
|
|
83
|
|
|
$this->helper->method('isProductExported') |
|
|
|
|
|
|
84
|
|
|
->with($connectAttribute) |
|
85
|
|
|
->willReturn(true); |
|
86
|
|
|
|
|
87
|
|
|
$this->connectExport->method('setDeleteStatusForVariants') |
|
|
|
|
|
|
88
|
|
|
->with($article); |
|
89
|
|
|
|
|
90
|
|
|
$this->config->method('getConfig') |
|
|
|
|
|
|
91
|
|
|
->with('autoUpdateProducts', Config::UPDATE_AUTO) |
|
92
|
|
|
->willReturn(Config::UPDATE_AUTO); |
|
93
|
|
|
|
|
94
|
|
|
$sourceIds = ['5', '5-101', '5-102', '5-103']; |
|
95
|
|
|
$this->helper->method('getSourceIdsFromArticleId') |
|
|
|
|
|
|
96
|
|
|
->with($articleId) |
|
97
|
|
|
->willReturn($sourceIds); |
|
98
|
|
|
|
|
99
|
|
|
$this->connectExport->expects($this->once()) |
|
|
|
|
|
|
100
|
|
|
->method('export') |
|
101
|
|
|
->with($sourceIds, new ProductStreamsAssignments()); |
|
102
|
|
|
|
|
103
|
|
|
$this->subscriber->regenerateChangesForArticle($articleId); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function testRegenerateSkipsNotExportedProduct() |
|
107
|
|
|
{ |
|
108
|
|
|
$articleId = 5; |
|
109
|
|
|
$article = new ArticleModel(); |
|
110
|
|
|
$connectAttribute = new ConnectAttribute(); |
|
111
|
|
|
|
|
112
|
|
|
$repositoryMock = $this->createMock(EntityRepository::class); |
|
113
|
|
|
|
|
114
|
|
|
$this->modelManager->method('getRepository') |
|
115
|
|
|
->with(ArticleModel::class) |
|
116
|
|
|
->willReturn($repositoryMock); |
|
117
|
|
|
|
|
118
|
|
|
$repositoryMock->method('find') |
|
119
|
|
|
->with($articleId) |
|
120
|
|
|
->willReturn($article); |
|
121
|
|
|
|
|
122
|
|
|
$this->helper->method('getConnectAttributeByModel') |
|
|
|
|
|
|
123
|
|
|
->with($article) |
|
124
|
|
|
->willReturn($connectAttribute); |
|
125
|
|
|
|
|
126
|
|
|
$this->helper->method('isProductExported') |
|
|
|
|
|
|
127
|
|
|
->with($connectAttribute) |
|
128
|
|
|
->willReturn(false); |
|
129
|
|
|
|
|
130
|
|
|
$this->connectExport->expects($this->never()) |
|
|
|
|
|
|
131
|
|
|
->method('export'); |
|
132
|
|
|
|
|
133
|
|
|
$this->subscriber->regenerateChangesForArticle($articleId); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
public function testRegenerateSkipsMissingArticles() |
|
137
|
|
|
{ |
|
138
|
|
|
$repositoryMock = $this->createMock(EntityRepository::class); |
|
139
|
|
|
|
|
140
|
|
|
$this->modelManager->method('getRepository') |
|
141
|
|
|
->with(ArticleModel::class) |
|
142
|
|
|
->willReturn($repositoryMock); |
|
143
|
|
|
|
|
144
|
|
|
$this->connectExport->expects($this->never()) |
|
|
|
|
|
|
145
|
|
|
->method('export'); |
|
146
|
|
|
|
|
147
|
|
|
$this->subscriber->regenerateChangesForArticle(5); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
|
|
151
|
|
|
|
|
152
|
|
|
public function testRegenerateSkipsWhenConnectAttributeIsMissing() |
|
153
|
|
|
{ |
|
154
|
|
|
$articleId = 5; |
|
155
|
|
|
$article = new ArticleModel(); |
|
156
|
|
|
|
|
157
|
|
|
$repositoryMock = $this->createMock(EntityRepository::class); |
|
158
|
|
|
|
|
159
|
|
|
$this->modelManager->method('getRepository') |
|
160
|
|
|
->with(ArticleModel::class) |
|
161
|
|
|
->willReturn($repositoryMock); |
|
162
|
|
|
|
|
163
|
|
|
$repositoryMock->method('find') |
|
164
|
|
|
->with($articleId) |
|
165
|
|
|
->willReturn($article); |
|
166
|
|
|
|
|
167
|
|
|
$this->connectExport->expects($this->never()) |
|
|
|
|
|
|
168
|
|
|
->method('export'); |
|
169
|
|
|
|
|
170
|
|
|
$this->subscriber->regenerateChangesForArticle($articleId); |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
public function testRegenerateWhenCronIsEnabled() |
|
174
|
|
|
{ |
|
175
|
|
|
$articleId = 5; |
|
176
|
|
|
$article = new ArticleModel(); |
|
177
|
|
|
$connectAttribute = new ConnectAttribute(); |
|
178
|
|
|
|
|
179
|
|
|
$repositoryMock = $this->createMock(EntityRepository::class); |
|
180
|
|
|
|
|
181
|
|
|
$this->modelManager->method('getRepository') |
|
182
|
|
|
->with(ArticleModel::class) |
|
183
|
|
|
->willReturn($repositoryMock); |
|
184
|
|
|
|
|
185
|
|
|
$repositoryMock->method('find') |
|
186
|
|
|
->with($articleId) |
|
187
|
|
|
->willReturn($article); |
|
188
|
|
|
|
|
189
|
|
|
$this->helper->method('getConnectAttributeByModel') |
|
|
|
|
|
|
190
|
|
|
->with($article) |
|
191
|
|
|
->willReturn($connectAttribute); |
|
192
|
|
|
|
|
193
|
|
|
$this->helper->method('isProductExported') |
|
|
|
|
|
|
194
|
|
|
->with($connectAttribute) |
|
195
|
|
|
->willReturn(true); |
|
196
|
|
|
|
|
197
|
|
|
$this->connectExport->method('setDeleteStatusForVariants') |
|
|
|
|
|
|
198
|
|
|
->with($article); |
|
199
|
|
|
|
|
200
|
|
|
$this->config->method('getConfig') |
|
|
|
|
|
|
201
|
|
|
->with('autoUpdateProducts', Config::UPDATE_AUTO) |
|
202
|
|
|
->willReturn(Config::UPDATE_CRON_JOB); |
|
203
|
|
|
|
|
204
|
|
|
$connectionMock = $this->createMock(Connection::class); |
|
205
|
|
|
$this->modelManager->method('getConnection') |
|
206
|
|
|
->willReturn($connectionMock); |
|
207
|
|
|
$connectionMock->expects($this->once()) |
|
208
|
|
|
->method('update') |
|
209
|
|
|
->with( |
|
210
|
|
|
's_plugin_connect_items', |
|
211
|
|
|
['cron_update' => 1], |
|
212
|
|
|
['article_id' => $articleId] |
|
213
|
|
|
); |
|
214
|
|
|
|
|
215
|
|
|
$this->connectExport->expects($this->never()) |
|
|
|
|
|
|
216
|
|
|
->method('export'); |
|
217
|
|
|
|
|
218
|
|
|
$this->subscriber->regenerateChangesForArticle($articleId); |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
public function testRegenerateWhenUpdateIsManual() |
|
222
|
|
|
{ |
|
223
|
|
|
$this->config->method('getConfig') |
|
|
|
|
|
|
224
|
|
|
->with('autoUpdateProducts', Config::UPDATE_AUTO) |
|
225
|
|
|
->willReturn(Config::UPDATE_MANUAL); |
|
226
|
|
|
|
|
227
|
|
|
$this->modelManager->expects($this->never()) |
|
228
|
|
|
->method('getRepository'); |
|
229
|
|
|
$this->connectExport->expects($this->never()) |
|
|
|
|
|
|
230
|
|
|
->method('export'); |
|
231
|
|
|
|
|
232
|
|
|
$this->subscriber->regenerateChangesForArticle(5); |
|
233
|
|
|
} |
|
234
|
|
|
} |
|
235
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.