Exemple #1
0
 public function testGetChildrenException()
 {
     $product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock();
     $product->expects($this->any())->method('getTypeId')->will($this->returnValue('same'));
     $this->productRepository->expects($this->any())->method('get')->with('sd')->will($this->returnValue($product));
     $this->assertCount(0, $this->object->getChildren('sd'));
 }
 public function testLoadBundleProduct()
 {
     $productId = 'test_id';
     $productSku = 'test_sku';
     $this->productRepository->expects($this->once())->method('get')->with($productId)->will($this->returnValue($this->product));
     $this->product->expects($this->once())->method('getTypeId')->will($this->returnValue(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE));
     $this->product->expects($this->once())->method('getSku')->will($this->returnValue($productSku));
     $optionCustomAttributeValue = ['a', 'b'];
     $this->optionReadService->expects($this->once())->method('getList')->with($productSku)->will($this->returnValue($optionCustomAttributeValue));
     $this->productBuilder->expects($this->at(0))->method('setCustomAttribute')->with('bundle_product_options', $optionCustomAttributeValue);
     $this->model->load($productId, $this->productBuilder);
 }
 /**
  * Test execute add success critical exception
  *
  * @return void
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testExecuteAddSuccessCriticalException()
 {
     $wishlist = $this->getMock('Magento\\Wishlist\\Model\\Wishlist', [], [], '', false);
     $product = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false);
     $item = $this->getMock('Magento\\Wishlist\\Model\\Item', [], [], '', false);
     $helper = $this->getMock('Magento\\Wishlist\\Helper\\Data', [], [], '', false);
     $logger = $this->getMock('Magento\\Framework\\Logger\\Monolog', [], [], '', false);
     $exception = new \Exception();
     $logger->expects($this->once())->method('critical')->with($exception)->willReturn(true);
     $helper->expects($this->exactly(2))->method('calculate')->willReturn(true);
     $wishlist->expects($this->once())->method('getItem')->with(3)->willReturn($item);
     $wishlist->expects($this->once())->method('updateItem')->with(3, new \Magento\Framework\DataObject([]))->willReturnSelf();
     $wishlist->expects($this->once())->method('save')->willReturn(null);
     $wishlist->expects($this->once())->method('getId')->willReturn(56);
     $product->expects($this->once())->method('isVisibleInCatalog')->willReturn(true);
     $product->expects($this->once())->method('getName')->willReturn('Test name');
     $this->request->expects($this->at(0))->method('getParam')->with('product', null)->willReturn(2);
     $this->request->expects($this->at(1))->method('getParam')->with('id', null)->willReturn(3);
     $this->productRepository->expects($this->once())->method('getById')->with(2)->willReturn($product);
     $item->expects($this->once())->method('load')->with(3)->willReturnSelf();
     $item->expects($this->once())->method('__call')->with('getWishlistId')->willReturn(12);
     $this->wishlistProvider->expects($this->once())->method('getWishlist')->with(12)->willReturn($wishlist);
     $this->om->expects($this->once())->method('create')->with('Magento\\Wishlist\\Model\\Item')->willReturn($item);
     $this->request->expects($this->once())->method('getParams')->willReturn([]);
     $this->om->expects($this->at(1))->method('get')->with('Magento\\Wishlist\\Helper\\Data')->willReturn($helper);
     $this->om->expects($this->at(2))->method('get')->with('Magento\\Wishlist\\Helper\\Data')->willReturn($helper);
     $this->om->expects($this->at(3))->method('get')->with('Psr\\Log\\LoggerInterface')->willReturn($logger);
     $this->eventManager->expects($this->once())->method('dispatch')->with('wishlist_update_item', ['wishlist' => $wishlist, 'product' => $product, 'item' => $item])->willReturn(true);
     $this->messageManager->expects($this->once())->method('addSuccess')->with('Test name has been updated in your Wish List.', null)->willThrowException($exception);
     $this->messageManager->expects($this->once())->method('addError')->with('We can\'t update your Wish List right now.', null)->willReturn(true);
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('*/*', ['wishlist_id' => 56])->willReturnSelf();
     $this->assertSame($this->resultRedirectMock, $this->getController()->execute());
 }
Exemple #4
0
 /**
  * @expectedException \Magento\Webapi\Exception
  * @expectedExceptionCode 403
  * @expectedExceptionMessage Only implemented for configurable product: oneSku
  */
 public function testGetListWebApiException()
 {
     $productSku = 'oneSku';
     $this->productRepository->expects($this->once())->method('get')->with($this->equalTo($productSku))->will($this->returnValue($this->product));
     $this->product->expects($this->once())->method('getTypeId')->will($this->returnValue(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE));
     $this->model->getList($productSku);
 }
 /**
  * @expectedException \Magento\Webapi\Exception
  * @expectedExceptionCode 403
  */
 public function testGetChildrenException()
 {
     $productSku = 'productSku';
     $this->productRepository->expects($this->once())->method('get')->with($this->equalTo($productSku))->will($this->returnValue($this->product));
     $this->product->expects($this->once())->method('getTypeId')->will($this->returnValue('simple'));
     $this->assertEquals([$this->link], $this->model->getChildren($productSku));
 }
 /**
  * @expectedException \Magento\Webapi\Exception
  */
 public function testRemoveWebApiException()
 {
     $productSku = 'productSku';
     $this->productRepositoryMock->expects($this->once())->method('get')->with($this->equalTo($productSku))->will($this->returnValue($this->productMock));
     $this->productMock->expects($this->once())->method('getTypeId')->will($this->returnValue(ProductType::TYPE_SIMPLE));
     $this->productMock->expects($this->once())->method('getSku')->will($this->returnValue($productSku));
     $this->writeService->remove($productSku, 3);
 }
Exemple #7
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testExecuteProductAddedToWishlistAfterObjectManagerThrowException()
 {
     $product = $this->getMock('Magento\\Catalog\\Model\\Product', ['isVisibleInCatalog', 'getName'], [], '', false);
     $product->expects($this->once())->method('isVisibleInCatalog')->will($this->returnValue(true));
     $product->expects($this->once())->method('getName')->will($this->returnValue('Product test name'));
     $this->productRepository->expects($this->once())->method('getById')->with(2)->will($this->returnValue($product));
     $exception = new \Exception('Exception');
     $wishListItem = new \stdClass();
     $wishlist = $this->getMock('Magento\\Wishlist\\Model\\Wishlist', ['addNewItem', 'save', 'getId'], [], '', false);
     $wishlist->expects($this->once())->method('addNewItem')->will($this->returnValue($wishListItem));
     $wishlist->expects($this->once())->method('getId')->will($this->returnValue(2));
     $wishlist->expects($this->once())->method('save')->will($this->returnValue(true));
     $this->wishlistProvider->expects($this->once())->method('getWishlist')->will($this->returnValue($wishlist));
     $request = $this->getMock('Magento\\Framework\\App\\Request\\Http', ['getParams'], [], '', false);
     $request->expects($this->once())->method('getParams')->will($this->returnValue(['product' => 2]));
     $wishlistHelper = $this->getMock('Magento\\Wishlist\\Helper\\Data', ['calculate'], [], '', false);
     $wishlistHelper->expects($this->once())->method('calculate')->will($this->returnSelf());
     $escaper = $this->getMock('Magento\\Framework\\Escaper', ['escapeHtml', 'escapeUrl'], [], '', false);
     $escaper->expects($this->once())->method('escapeHtml')->with('Product test name')->will($this->returnValue('Product test name'));
     $escaper->expects($this->once())->method('escapeUrl')->with('http://test-url.com')->will($this->returnValue('http://test-url.com'));
     $logger = $this->getMock('Magento\\Framework\\Logger\\Monolog', ['critical'], [], '', false);
     $logger->expects($this->once())->method('critical')->with($exception)->will($this->returnValue(true));
     $om = $this->getMock('Magento\\Framework\\App\\ObjectManager', ['get'], [], '', false);
     $om->expects($this->at(0))->method('get')->with('Magento\\Wishlist\\Helper\\Data')->will($this->returnValue($wishlistHelper));
     $om->expects($this->at(1))->method('get')->with('Magento\\Framework\\Escaper')->will($this->returnValue($escaper));
     $om->expects($this->at(2))->method('get')->with('Magento\\Framework\\Escaper')->will($this->returnValue($escaper));
     $om->expects($this->at(3))->method('get')->with('Psr\\Log\\LoggerInterface')->will($this->returnValue($logger));
     $response = $this->getMock('Magento\\Framework\\App\\Response\\Http', null, [], '', false);
     $eventManager = $this->getMock('Magento\\Framework\\Event\\Manager', ['dispatch'], [], '', false);
     $eventManager->expects($this->once())->method('dispatch')->with('wishlist_add_product', ['wishlist' => $wishlist, 'product' => $product, 'item' => $wishListItem])->will($this->returnValue(true));
     $url = $this->getMock('Magento\\Framework\\Url', null, [], '', false);
     $actionFlag = $this->getMock('Magento\\Framework\\App\\ActionFlag', null, [], '', false);
     $redirect = $this->getMock('\\Magento\\Store\\App\\Response\\Redirect', ['redirect'], [], '', false);
     $redirect->expects($this->once())->method('redirect')->with($response, '*', ['wishlist_id' => 2])->will($this->returnValue(null));
     $view = $this->getMock('Magento\\Framework\\App\\View', null, [], '', false);
     $messageManager = $this->getMock('Magento\\Framework\\Message\\Manager', ['addError', 'addSuccess'], [], '', false);
     $messageManager->expects($this->once())->method('addError')->with('An error occurred while adding item to wish list.')->will($this->returnValue(null));
     $messageManager->expects($this->once())->method('addSuccess')->will($this->throwException($exception));
     $this->context->expects($this->any())->method('getObjectManager')->will($this->returnValue($om));
     $this->context->expects($this->any())->method('getRequest')->will($this->returnValue($request));
     $this->context->expects($this->any())->method('getResponse')->will($this->returnValue($response));
     $this->context->expects($this->any())->method('getEventManager')->will($this->returnValue($eventManager));
     $this->context->expects($this->any())->method('getUrl')->will($this->returnValue($url));
     $this->context->expects($this->any())->method('getActionFlag')->will($this->returnValue($actionFlag));
     $this->context->expects($this->any())->method('getRedirect')->will($this->returnValue($redirect));
     $this->context->expects($this->any())->method('getView')->will($this->returnValue($view));
     $this->context->expects($this->any())->method('getMessageManager')->will($this->returnValue($messageManager));
     $this->customerSession->expects($this->exactly(1))->method('getBeforeWishlistRequest')->will($this->returnValue(false));
     $this->customerSession->expects($this->never())->method('unsBeforeWishlistRequest')->will($this->returnValue(null));
     $this->customerSession->expects($this->once())->method('getBeforeWishlistUrl')->will($this->returnValue('http://test-url.com'));
     $this->customerSession->expects($this->once())->method('setBeforeWishlistUrl')->with(null)->will($this->returnValue(null));
     $this->createController();
     $this->controller->execute();
 }
Exemple #8
0
 /**
  * @expectedException \Magento\Framework\Exception\StateException
  * @expectedExceptionMessage Product has been already attached
  */
 public function testAddChildStateException()
 {
     $productSku = 'configurable-sku';
     $childSku = 'simple-sku';
     $configurable = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock();
     $configurable->expects($this->any())->method('getId')->will($this->returnValue(666));
     $simplee = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock();
     $simplee->expects($this->any())->method('getId')->will($this->returnValue(1));
     $this->productRepository->expects($this->at(0))->method('get')->with($productSku)->will($this->returnValue($configurable));
     $this->productRepository->expects($this->at(1))->method('get')->with($childSku)->will($this->returnValue($simplee));
     $this->configurableType->expects($this->once())->method('getChildrenIds')->with(666)->will($this->returnValue([0 => [1, 2, 3]]));
     $this->assertTrue(true, $this->service->addChild($productSku, $childSku));
 }
 /**
  * @expectedException \Magento\Framework\Exception\NoSuchEntityException
  */
 public function testRemoveChildInvalidChildSku()
 {
     $this->productRepository->expects($this->any())->method('get')->will($this->returnValue($this->product));
     $productSku = 'productSku';
     $optionId = 1;
     $childSku = 'childSku';
     $this->product->expects($this->any())->method('getTypeId')->will($this->returnValue(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE));
     $this->getRemoveOptions();
     $selection = $this->getMockBuilder('\\Magento\\Bundle\\Model\\Selection')->setMethods(['getSku', 'getOptionId', 'getSelectionId', 'getProductId', '__wakeup'])->disableOriginalConstructor()->getMock();
     $selection->expects($this->any())->method('getSku')->will($this->returnValue($childSku . '_invalid'));
     $selection->expects($this->any())->method('getOptionId')->will($this->returnValue($optionId));
     $selection->expects($this->any())->method('getSelectionId')->will($this->returnValue(55));
     $selection->expects($this->any())->method('getProductId')->will($this->returnValue(1));
     $this->option->expects($this->any())->method('getSelections')->will($this->returnValue([$selection]));
     $this->model->removeChild($productSku, $optionId, $childSku);
 }
 public function testUpdate()
 {
     $product1Sku = 'sku1';
     $productOption1Sku = 'productOption1Sku';
     $productOption2Sku = 'productOption2Sku';
     $product1Options = [$this->productOption1, $this->productOption2];
     $product2Options = [$this->productOption1];
     $this->productRepository->expects($this->once())->method('get')->with($product1Sku, true)->will($this->returnValue($this->product));
     $this->product->expects($this->once())->method('getTypeId')->will($this->returnValue(ProductType::TYPE_BUNDLE));
     $this->optionReadService->expects($this->once())->method('getList')->with($product1Sku)->will($this->returnValue($product1Options));
     $this->productData->expects($this->once())->method('getCustomAttribute')->with('bundle_product_options')->will($this->returnValue($this->attributeValue));
     $this->attributeValue->expects($this->any())->method('getValue')->will($this->returnValue($product2Options));
     $this->productOption1->expects($this->any())->method('getId')->will($this->returnValue($productOption1Sku));
     $this->productOption2->expects($this->any())->method('getId')->will($this->returnValue($productOption2Sku));
     $this->optionWriteService->expects($this->once())->method('remove')->with($product1Sku, $productOption2Sku)->will($this->returnValue(1));
     $this->assertEquals($product1Sku, $this->saveProcessor->update($product1Sku, $this->productData));
 }