|
16 | 16 | use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface;
|
17 | 17 | use Magento\Framework\Api\SortOrder;
|
18 | 18 | use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
|
| 19 | +use Magento\Store\Api\Data\StoreInterface; |
19 | 20 |
|
20 | 21 | /**
|
21 | 22 | * Tests \Magento\Catalog\Model\ProductRepositoryTest
|
@@ -1290,6 +1291,45 @@ public function testSaveExistingWithNewMediaGalleryEntries()
|
1290 | 1291 | $this->model->save($this->productMock);
|
1291 | 1292 | }
|
1292 | 1293 |
|
| 1294 | + public function testSaveWithDifferentWebsites() |
| 1295 | + { |
| 1296 | + $getWebsitesResultData = [ |
| 1297 | + 1 => ['first'], |
| 1298 | + 2 => ['second'], |
| 1299 | + 3 => ['third'] |
| 1300 | + ]; |
| 1301 | + $getWebsiteIdsResultData = [1,2,3]; |
| 1302 | + $setWebsiteIdsResultData = [2,3]; |
| 1303 | + $getIdBySkuResultData = 100; |
| 1304 | + $storeMock = $this->getMock(StoreInterface::class); |
| 1305 | + $this->resourceModelMock->expects($this->at(0))->method('getIdBySku')->will($this->returnValue(null)); |
| 1306 | + $this->resourceModelMock |
| 1307 | + ->expects($this->at(3)) |
| 1308 | + ->method('getIdBySku') |
| 1309 | + ->will($this->returnValue($getIdBySkuResultData)); |
| 1310 | + $this->productFactoryMock->expects($this->any()) |
| 1311 | + ->method('create') |
| 1312 | + ->will($this->returnValue($this->productMock)); |
| 1313 | + $this->initializationHelperMock->expects($this->never())->method('initialize'); |
| 1314 | + $this->resourceModelMock->expects($this->once())->method('validate')->with($this->productMock) |
| 1315 | + ->willReturn(true); |
| 1316 | + $this->resourceModelMock->expects($this->once())->method('save')->with($this->productMock)->willReturn(true); |
| 1317 | + $this->extensibleDataObjectConverterMock |
| 1318 | + ->expects($this->once()) |
| 1319 | + ->method('toNestedArray') |
| 1320 | + ->will($this->returnValue($this->productData)); |
| 1321 | + $this->storeManagerMock->expects($this->any()) |
| 1322 | + ->method('getStore') |
| 1323 | + ->willReturn($storeMock); |
| 1324 | + $this->storeManagerMock->expects($this->once()) |
| 1325 | + ->method('getWebsites') |
| 1326 | + ->willReturn($getWebsitesResultData); |
| 1327 | + $this->productMock->expects($this->once())->method('getWebsiteIds')->willReturn($getWebsiteIdsResultData); |
| 1328 | + $this->productMock->expects($this->once())->method('setWebsiteIds')->willReturn($setWebsiteIdsResultData); |
| 1329 | + |
| 1330 | + $this->assertEquals($this->productMock, $this->model->save($this->productMock)); |
| 1331 | + } |
| 1332 | + |
1293 | 1333 | public function testSaveExistingWithMediaGalleryEntries()
|
1294 | 1334 | {
|
1295 | 1335 | //update one entry, delete one entry
|
|
0 commit comments