|
46 | 46 | use PHPUnit_Framework_MockObject_MockObject as MockObject;
|
47 | 47 |
|
48 | 48 | /**
|
49 |
| - * Class ProductRepositoryTest |
50 |
| - * @package Magento\Catalog\Test\Unit\Model |
| 49 | + * Test for \Magento\Catalog\Model\ProductRepository. |
| 50 | + * |
51 | 51 | * @SuppressWarnings(PHPMD.TooManyFields)
|
52 | 52 | * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
53 | 53 | * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
@@ -291,6 +291,7 @@ protected function setUp()
|
291 | 291 | ->disableOriginalConstructor()
|
292 | 292 | ->setMethods([])
|
293 | 293 | ->getMockForAbstractClass();
|
| 294 | + $storeMock->method('getId')->willReturn('1'); |
294 | 295 | $storeMock->expects($this->any())->method('getWebsiteId')->willReturn('1');
|
295 | 296 | $storeMock->expects($this->any())->method('getCode')->willReturn(Store::ADMIN_CODE);
|
296 | 297 | $this->storeManager->expects($this->any())->method('getStore')->willReturn($storeMock);
|
@@ -345,6 +346,66 @@ function ($value) {
|
345 | 346 | $this->objectManager->setBackwardCompatibleProperty($this->model, 'mediaProcessor', $mediaProcessor);
|
346 | 347 | }
|
347 | 348 |
|
| 349 | + /** |
| 350 | + * Test save product with store id 0 |
| 351 | + * |
| 352 | + * @param array $productData |
| 353 | + * @return void |
| 354 | + * @dataProvider getProductData |
| 355 | + */ |
| 356 | + public function testSaveForAllStoreViewScope(array $productData): void |
| 357 | + { |
| 358 | + $this->productFactory->method('create')->willReturn($this->product); |
| 359 | + $this->product->method('getSku')->willReturn($productData['sku']); |
| 360 | + $this->extensibleDataObjectConverter |
| 361 | + ->expects($this->once()) |
| 362 | + ->method('toNestedArray') |
| 363 | + ->willReturn($productData); |
| 364 | + $this->resourceModel->method('getIdBySku')->willReturn(100); |
| 365 | + $this->resourceModel->expects($this->once())->method('validate')->willReturn(true); |
| 366 | + $this->product->expects($this->at(14))->method('setData')->with('store_id', $productData['store_id']); |
| 367 | + |
| 368 | + $this->model->save($this->product); |
| 369 | + } |
| 370 | + |
| 371 | + /** |
| 372 | + * Product data provider |
| 373 | + * |
| 374 | + * @return array |
| 375 | + */ |
| 376 | + public function getProductData(): array |
| 377 | + { |
| 378 | + return [ |
| 379 | + [ |
| 380 | + [ |
| 381 | + 'sku' => 'sku', |
| 382 | + 'name' => 'product', |
| 383 | + 'store_id' => 0, |
| 384 | + ], |
| 385 | + ], |
| 386 | + ]; |
| 387 | + } |
| 388 | + |
| 389 | + /** |
| 390 | + * Test save product without store |
| 391 | + * |
| 392 | + * @return void |
| 393 | + */ |
| 394 | + public function testSaveWithoutStoreId(): void |
| 395 | + { |
| 396 | + $this->productFactory->method('create')->willReturn($this->product); |
| 397 | + $this->product->method('getSku')->willReturn($this->productData['sku']); |
| 398 | + $this->extensibleDataObjectConverter |
| 399 | + ->expects($this->once()) |
| 400 | + ->method('toNestedArray') |
| 401 | + ->willReturn($this->productData); |
| 402 | + $this->resourceModel->method('getIdBySku')->willReturn(100); |
| 403 | + $this->resourceModel->expects($this->once())->method('validate')->willReturn(true); |
| 404 | + $this->product->expects($this->at(15))->method('setData')->with('store_id', 1); |
| 405 | + |
| 406 | + $this->model->save($this->product); |
| 407 | + } |
| 408 | + |
348 | 409 | /**
|
349 | 410 | * @expectedException \Magento\Framework\Exception\NoSuchEntityException
|
350 | 411 | * @expectedExceptionMessage The product that was requested doesn't exist. Verify the product and try again.
|
|
0 commit comments