@@ -76,16 +76,24 @@ class WebsitesTest extends AbstractModifierTest
76
76
*/
77
77
protected $ storeViewMock ;
78
78
79
+ /**
80
+ * @var array
81
+ */
82
+ private $ websitesList ;
83
+
84
+ /**
85
+ * @var int
86
+ */
87
+ private $ productId ;
88
+
79
89
/**
80
90
* @inheritdoc
81
91
*/
82
92
protected function setUp (): void
83
93
{
84
94
parent ::setUp ();
85
- $ this ->productMock ->expects ($ this ->any ())
86
- ->method ('getId ' )
87
- ->willReturn (self ::PRODUCT_ID );
88
95
$ this ->assignedWebsites = [self ::SECOND_WEBSITE_ID ];
96
+ $ this ->productId = self ::PRODUCT_ID ;
89
97
$ this ->websiteMock = $ this ->getMockBuilder (Website::class)
90
98
->setMethods (['getId ' , 'getName ' ])
91
99
->disableOriginalConstructor ()
@@ -94,6 +102,7 @@ protected function setUp(): void
94
102
->setMethods (['getId ' , 'getName ' ])
95
103
->disableOriginalConstructor ()
96
104
->getMock ();
105
+ $ this ->websitesList = [$ this ->websiteMock , $ this ->secondWebsiteMock ];
97
106
$ this ->websiteRepositoryMock = $ this ->getMockBuilder (WebsiteRepositoryInterface::class)
98
107
->setMethods (['getList ' ])
99
108
->getMockForAbstractClass ();
@@ -106,17 +115,9 @@ protected function setUp(): void
106
115
$ this ->storeRepositoryMock = $ this ->getMockBuilder (StoreRepositoryInterface::class)
107
116
->setMethods (['getList ' ])
108
117
->getMockForAbstractClass ();
109
- $ this ->productMock = $ this ->getMockBuilder (ProductInterface::class)
110
- ->setMethods (['getId ' ])
111
- ->getMockForAbstractClass ();
112
- $ this ->locatorMock ->expects ($ this ->any ())
113
- ->method ('getWebsiteIds ' )
114
- ->willReturn ($ this ->assignedWebsites );
115
118
$ this ->storeManagerMock = $ this ->getMockBuilder (StoreManagerInterface::class)
116
119
->setMethods (['isSingleStoreMode ' , 'getWebsites ' ])
117
120
->getMockForAbstractClass ();
118
- $ this ->storeManagerMock ->method ('getWebsites ' )
119
- ->willReturn ([$ this ->websiteMock , $ this ->secondWebsiteMock ]);
120
121
$ this ->storeManagerMock ->expects ($ this ->any ())
121
122
->method ('isSingleStoreMode ' )
122
123
->willReturn (false );
@@ -174,12 +175,30 @@ protected function createModel()
174
175
);
175
176
}
176
177
178
+ /**
179
+ * Initialize return values
180
+ * @return void
181
+ */
182
+ private function init ()
183
+ {
184
+ $ this ->productMock ->expects ($ this ->any ())
185
+ ->method ('getId ' )
186
+ ->willReturn ($ this ->productId );
187
+ $ this ->locatorMock ->expects ($ this ->any ())
188
+ ->method ('getWebsiteIds ' )
189
+ ->willReturn ($ this ->assignedWebsites );
190
+ $ this ->storeManagerMock ->method ('getWebsites ' )
191
+ ->willReturn ($ this ->websitesList );
192
+ }
193
+
177
194
/**
178
195
* @return void
179
196
*/
180
197
public function testModifyMeta ()
181
198
{
199
+ $ this ->init ();
182
200
$ meta = $ this ->getModel ()->modifyMeta ([]);
201
+
183
202
$ this ->assertArrayHasKey ('websites ' , $ meta );
184
203
$ this ->assertArrayHasKey (self ::SECOND_WEBSITE_ID , $ meta ['websites ' ]['children ' ]);
185
204
$ this ->assertArrayHasKey (self ::WEBSITE_ID , $ meta ['websites ' ]['children ' ]);
@@ -190,7 +209,7 @@ public function testModifyMeta()
190
209
);
191
210
$ this ->assertEquals (
192
211
$ meta ['websites ' ]['children ' ][self ::WEBSITE_ID ]['arguments ' ]['data ' ]['config ' ]['value ' ],
193
- " 0 "
212
+ ' 0 '
194
213
);
195
214
}
196
215
@@ -214,10 +233,44 @@ public function testModifyData()
214
233
]
215
234
],
216
235
];
236
+ $ this ->init ();
217
237
218
238
$ this ->assertEquals (
219
239
$ expectedData ,
220
240
$ this ->getModel ()->modifyData ([])
221
241
);
222
242
}
243
+
244
+ public function testModifyDataNoWebsitesExistingProduct ()
245
+ {
246
+ $ this ->assignedWebsites = [];
247
+ $ this ->websitesList = [$ this ->websiteMock ];
248
+ $ this ->init ();
249
+
250
+ $ meta = $ this ->getModel ()->modifyMeta ([]);
251
+
252
+ $ this ->assertArrayHasKey (self ::WEBSITE_ID , $ meta ['websites ' ]['children ' ]);
253
+ $ this ->assertArrayHasKey ('copy_to_stores. ' . self ::WEBSITE_ID , $ meta ['websites ' ]['children ' ]);
254
+ $ this ->assertEquals ('0 ' ,
255
+ $ meta ['websites ' ]['children ' ][self ::WEBSITE_ID ]['arguments ' ]['data ' ]['config ' ]['value ' ]
256
+ );
257
+ }
258
+
259
+ public function testModifyDataNoWebsitesNewProduct ()
260
+ {
261
+ $ this ->assignedWebsites = [];
262
+ $ this ->websitesList = [$ this ->websiteMock ];
263
+ $ this ->productId = false ;
264
+ $ this ->init ();
265
+ $ this ->productMock ->expects ($ this ->any ())
266
+ ->method ('getId ' )
267
+ ->willReturn (false );
268
+
269
+ $ meta = $ this ->getModel ()->modifyMeta ([]);
270
+
271
+ $ this ->assertArrayHasKey (self ::WEBSITE_ID , $ meta ['websites ' ]['children ' ]);
272
+ $ this ->assertEquals ('1 ' ,
273
+ $ meta ['websites ' ]['children ' ][self ::WEBSITE_ID ]['arguments ' ]['data ' ]['config ' ]['value ' ]
274
+ );
275
+ }
223
276
}
0 commit comments