示例#1
0
 /**
  *
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testProcessCartUpdateBefore()
 {
     $customerId = 1;
     $itemId = 5;
     $itemQty = 123;
     $productId = 321;
     $eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
     $event = $this->getMockBuilder('Magento\\Framework\\Event')->setMethods(['getCart', 'getInfo'])->disableOriginalConstructor()->getMock();
     $eventObserver->expects($this->exactly(2))->method('getEvent')->willReturn($event);
     $quoteItem = $this->getMockBuilder('Magento\\Quote\\Model\\Quote\\Item')->setMethods(['getProductId', 'getBuyRequest', '__wakeup'])->disableOriginalConstructor()->getMock();
     $buyRequest = $this->getMockBuilder('Magento\\Framework\\Object')->setMethods(['setQty'])->disableOriginalConstructor()->getMock();
     $infoData = $this->getMockBuilder('Magento\\Framework\\Object')->setMethods(['toArray'])->disableOriginalConstructor()->getMock();
     $infoData->expects($this->once())->method('toArray')->willReturn([$itemId => ['qty' => $itemQty, 'wishlist' => true]]);
     $cart = $this->getMockBuilder('Magento\\Checkout\\Model\\Cart')->disableOriginalConstructor()->getMock();
     $quote = $this->getMockBuilder('Magento\\Quote\\Model\\Quote')->setMethods(['getCustomerId', 'getItemById', 'removeItem', '__wakeup'])->disableOriginalConstructor()->getMock();
     $event->expects($this->once())->method('getCart')->willReturn($cart);
     $event->expects($this->once())->method('getInfo')->willReturn($infoData);
     $cart->expects($this->any())->method('getQuote')->willReturn($quote);
     $quoteItem->expects($this->once())->method('getProductId')->willReturn($productId);
     $quoteItem->expects($this->once())->method('getBuyRequest')->willReturn($buyRequest);
     $buyRequest->expects($this->once())->method('setQty')->with($itemQty)->willReturnSelf();
     $quote->expects($this->once())->method('getCustomerId')->willReturn($customerId);
     $quote->expects($this->once())->method('getItemById')->with($itemId)->willReturn($quoteItem);
     $quote->expects($this->once())->method('removeItem')->with($itemId);
     $this->wishlist->expects($this->once())->method('loadByCustomerId')->with($this->logicalOr($customerId, true))->willReturnSelf();
     $this->wishlist->expects($this->once())->method('addNewItem')->with($this->logicalOr($productId, $buyRequest));
     $this->wishlist->expects($this->once())->method('save');
     $this->helper->expects($this->once())->method('calculate');
     /** @var $eventObserver \Magento\Framework\Event\Observer */
     $this->assertSame($this->observer, $this->observer->processCartUpdateBefore($eventObserver));
 }