|
16 | 16 | */
|
17 | 17 | class TypeTest extends \PHPUnit_Framework_TestCase
|
18 | 18 | {
|
| 19 | + /** |
| 20 | + * @var \Magento\Bundle\Model\Resource\BundleFactory|\PHPUnit_Framework_MockObject_MockObject |
| 21 | + */ |
| 22 | + private $bundleFactory; |
| 23 | + /** |
| 24 | + * @var \Magento\Bundle\Model\SelectionFactory|\PHPUnit_Framework_MockObject_MockObject |
| 25 | + */ |
| 26 | + private $bundleModelSelection; |
19 | 27 | /**
|
20 | 28 | * @var \Magento\Bundle\Model\Product\Type
|
21 | 29 | */
|
@@ -96,19 +104,18 @@ protected function setUp()
|
96 | 104 | ->setMethods(['convert'])
|
97 | 105 | ->disableOriginalConstructor()
|
98 | 106 | ->getMockForAbstractClass();
|
99 |
| - $bundleModelSelection = $this->getMockBuilder('\Magento\Bundle\Model\SelectionFactory') |
| 107 | + $this->bundleModelSelection = $this->getMockBuilder('Magento\Bundle\Model\SelectionFactory') |
100 | 108 | ->disableOriginalConstructor()
|
101 | 109 | ->getMock();
|
102 |
| - $bundleFactory = $this->getMockBuilder('\Magento\Bundle\Model\Resource\BundleFactory') |
| 110 | + $this->bundleFactory = $this->getMockBuilder('\Magento\Bundle\Model\Resource\BundleFactory') |
103 | 111 | ->disableOriginalConstructor()
|
104 | 112 | ->getMock();
|
105 |
| - |
106 | 113 | $objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
|
107 | 114 | $this->model = $objectHelper->getObject(
|
108 | 115 | 'Magento\Bundle\Model\Product\Type',
|
109 | 116 | [
|
110 |
| - 'bundleModelSelection' => $bundleModelSelection, |
111 |
| - 'bundleFactory' => $bundleFactory, |
| 117 | + 'bundleModelSelection' => $this->bundleModelSelection, |
| 118 | + 'bundleFactory' => $this->bundleFactory, |
112 | 119 | 'bundleCollection' => $this->bundleCollection,
|
113 | 120 | 'bundleOption' => $this->bundleOptionFactory,
|
114 | 121 | 'catalogData' => $this->catalogData,
|
@@ -2427,4 +2434,80 @@ protected function parentClass($group, $option, $buyRequest, $product)
|
2427 | 2434 | ->method('getSkipSaleableCheck')
|
2428 | 2435 | ->willReturn(false);
|
2429 | 2436 | }
|
| 2437 | + |
| 2438 | + public function testSave() |
| 2439 | + { |
| 2440 | + $options = [ |
| 2441 | + 'some_option' => ['option_id' => '', 'delete' => false], |
| 2442 | + ]; |
| 2443 | + $selections = [ |
| 2444 | + 'some_option' => [ |
| 2445 | + 123 => ['selection_id' => '', 'delete' => false], |
| 2446 | + ] |
| 2447 | + ]; |
| 2448 | + |
| 2449 | + $resource = $this->getMockBuilder('Magento\Bundle\Model\Resource\Bundle') |
| 2450 | + ->disableOriginalConstructor() |
| 2451 | + ->getMock(); |
| 2452 | + $this->bundleFactory->expects($this->once()) |
| 2453 | + ->method('create') |
| 2454 | + ->willReturn($resource); |
| 2455 | + |
| 2456 | + $product = $this->getMockBuilder('Magento\Catalog\Model\Product') |
| 2457 | + ->setMethods( |
| 2458 | + [ |
| 2459 | +// 'getOptions', |
| 2460 | +// 'prepareCustomOptions', |
| 2461 | +// 'addCustomOption', |
| 2462 | +// 'setCartQty', |
| 2463 | +// 'setQty', |
| 2464 | +// 'getSkipCheckRequiredOption', |
| 2465 | +// 'getTypeInstance', |
| 2466 | + 'getStoreId', |
| 2467 | + 'getOrigData', |
| 2468 | +// 'hasData', |
| 2469 | + 'getData', |
| 2470 | + 'getBundleOptionsData', |
| 2471 | + 'getBundleSelectionsData' |
| 2472 | + ] |
| 2473 | + ) |
| 2474 | + ->disableOriginalConstructor() |
| 2475 | + ->getMock(); |
| 2476 | + $product->expects($this->once()) |
| 2477 | + ->method('getBundleOptionsData') |
| 2478 | + ->willReturn($options); |
| 2479 | + $product->expects($this->once()) |
| 2480 | + ->method('getBundleSelectionsData') |
| 2481 | + ->willReturn($selections); |
| 2482 | + $option = $this->getMockBuilder('Magento\Bundle\Model\Resource\Option\Collection') |
| 2483 | + ->setMethods(['setData', 'setParentId', 'setStoreId', 'isDeleted', 'save', 'getOptionId']) |
| 2484 | + ->disableOriginalConstructor() |
| 2485 | + ->getMock(); |
| 2486 | + $option->expects($this->once())->method('setData')->willReturnSelf(); |
| 2487 | + $option->expects($this->once())->method('setParentId')->willReturnSelf(); |
| 2488 | + $option->expects($this->once())->method('setStoreId')->willReturnSelf(); |
| 2489 | + $this->bundleOptionFactory->expects($this->once())->method('create')->will($this->returnValue($option)); |
| 2490 | + |
| 2491 | + $selection = $this->getMockBuilder('Magento\Bundle\Model\Selection') |
| 2492 | + ->setMethods(['setData', 'setOptionId', 'setParentProductId', 'setWebsiteId', 'save']) |
| 2493 | + ->disableOriginalConstructor() |
| 2494 | + ->getMock(); |
| 2495 | + $selection->expects($this->once())->method('setData')->willReturnSelf(); |
| 2496 | + $selection->expects($this->once())->method('setOptionId')->willReturnSelf(); |
| 2497 | + $selection->expects($this->once())->method('setParentProductId')->willReturnSelf(); |
| 2498 | + $selection->expects($this->once())->method('setWebsiteId')->willReturnSelf(); |
| 2499 | + $selection->expects($this->once())->method('setParentProductId')->willReturnSelf(); |
| 2500 | + $this->bundleModelSelection->expects($this->once())->method('create')->willReturn($selection); |
| 2501 | + $store = $this->getMockBuilder('Magento\Store\Model\Store') |
| 2502 | + ->setMethods(['getWebsiteId', '__wakeup']) |
| 2503 | + ->disableOriginalConstructor() |
| 2504 | + ->getMock(); |
| 2505 | + $this->storeManager->expects($this->once()) |
| 2506 | + ->method('getStore') |
| 2507 | + ->will($this->returnValue($store)); |
| 2508 | + $store->expects($this->once()) |
| 2509 | + ->method('getWebsiteId') |
| 2510 | + ->will($this->returnValue(10)); |
| 2511 | + $this->model->save($product); |
| 2512 | + } |
2430 | 2513 | }
|
0 commit comments