Example #1
0
 public function testSave()
 {
     $options = ['some_option' => ['option_id' => '', 'delete' => false]];
     $selections = ['some_option' => [123 => ['selection_id' => '', 'delete' => false]]];
     $resource = $this->getMockBuilder('Magento\\Bundle\\Model\\ResourceModel\\Bundle')->disableOriginalConstructor()->getMock();
     $this->bundleFactory->expects($this->once())->method('create')->willReturn($resource);
     $product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->setMethods(['getStoreId', 'getOrigData', 'getData', 'getBundleOptionsData', 'getBundleSelectionsData'])->disableOriginalConstructor()->getMock();
     $product->expects($this->once())->method('getBundleOptionsData')->willReturn($options);
     $product->expects($this->once())->method('getBundleSelectionsData')->willReturn($selections);
     $option = $this->getMockBuilder('Magento\\Bundle\\Model\\ResourceModel\\Option\\Collection')->setMethods(['setData', 'setParentId', 'setStoreId', 'isDeleted', 'save', 'getOptionId'])->disableOriginalConstructor()->getMock();
     $option->expects($this->once())->method('setData')->willReturnSelf();
     $option->expects($this->once())->method('setParentId')->willReturnSelf();
     $option->expects($this->once())->method('setStoreId')->willReturnSelf();
     $this->bundleOptionFactory->expects($this->once())->method('create')->will($this->returnValue($option));
     $selection = $this->getMockBuilder('Magento\\Bundle\\Model\\Selection')->setMethods(['setData', 'setOptionId', 'setParentProductId', 'setWebsiteId', 'save'])->disableOriginalConstructor()->getMock();
     $selection->expects($this->once())->method('setData')->willReturnSelf();
     $selection->expects($this->once())->method('setOptionId')->willReturnSelf();
     $selection->expects($this->once())->method('setParentProductId')->willReturnSelf();
     $selection->expects($this->once())->method('setWebsiteId')->willReturnSelf();
     $selection->expects($this->once())->method('setParentProductId')->willReturnSelf();
     $this->bundleModelSelection->expects($this->once())->method('create')->willReturn($selection);
     $store = $this->getMockBuilder('Magento\\Store\\Model\\Store')->setMethods(['getWebsiteId', '__wakeup'])->disableOriginalConstructor()->getMock();
     $this->storeManager->expects($this->once())->method('getStore')->will($this->returnValue($store));
     $store->expects($this->once())->method('getWebsiteId')->will($this->returnValue(10));
     $this->model->save($product);
 }