コード例 #1
0
ファイル: ProcessDataTest.php プロジェクト: tingyeeh/magento2
 /**
  * @param bool $noDiscount
  * @param string $couponCode
  * @param string $errorMessage
  * @param string $actualCouponCode
  * @dataProvider isApplyDiscountDataProvider
  */
 public function testExecute($noDiscount, $couponCode, $errorMessage, $actualCouponCode)
 {
     $quote = $this->getMock('Magento\\Quote\\Model\\Quote', ['getCouponCode', 'isVirtual', 'getAllItems'], [], '', false);
     $create = $this->getMock('Magento\\Sales\\Model\\AdminOrder\\Create', [], [], '', false);
     $paramReturnMap = [['customer_id', null, null], ['store_id', null, null], ['currency_id', null, null]];
     $this->request->expects($this->atLeastOnce())->method('getParam')->willReturnMap($paramReturnMap);
     $objectManagerParamMap = [['Magento\\Sales\\Model\\AdminOrder\\Create', $create], ['Magento\\Backend\\Model\\Session\\Quote', $this->session]];
     $this->objectManager->expects($this->atLeastOnce())->method('get')->willReturnMap($objectManagerParamMap);
     $this->eventManager->expects($this->any())->method('dispatch');
     $data = ['coupon' => ['code' => $couponCode]];
     $postReturnMap = [['order', $data], ['reset_shipping', false], ['collect_shipping_rates', false], ['sidebar', false], ['add_product', false], ['', false], ['update_items', false], ['remove_item', 1], ['from', 2], ['move_item', 1], ['to', 2], ['qty', 3], ['payment', false], [null, 'request'], ['payment', false], ['giftmessage', false], ['add_products', false], ['update_items', false]];
     $this->request->expects($this->atLeastOnce())->method('getPost')->willReturnMap($postReturnMap);
     $create->expects($this->once())->method('importPostData')->willReturnSelf();
     $create->expects($this->once())->method('initRuleData')->willReturnSelf();
     $create->expects($this->any())->method('getQuote')->willReturn($quote);
     $address = $this->getMock('Magento\\Quote\\Model\\Quote\\Address', [], [], '', false);
     $create->expects($this->once())->method('getBillingAddress')->willReturn($address);
     $quote->expects($this->any())->method('isVirtual')->willReturn(true);
     $this->request->expects($this->once())->method('has')->with('item')->willReturn(false);
     $create->expects($this->once())->method('saveQuote')->willReturnSelf();
     $this->session->expects($this->any())->method('getQuote')->willReturn($quote);
     $item = $this->getMockForAbstractClass('Magento\\Eav\\Model\\Entity\\Collection\\AbstractCollection', [], '', false, true, true, ['getNoDiscount']);
     $quote->expects($this->any())->method('getAllItems')->willReturn([$item]);
     $item->expects($this->any())->method('getNoDiscount')->willReturn($noDiscount);
     if (!$noDiscount) {
         $quote->expects($this->once())->method('getCouponCode')->willReturn($actualCouponCode);
     }
     $errorMessageManager = __($errorMessage, $couponCode);
     $this->escaper->expects($this->once())->method('escapeHtml')->with($couponCode)->willReturn($couponCode);
     $this->messageManager->expects($this->once())->method('addError')->with($errorMessageManager)->willReturnSelf();
     $this->resultForward->expects($this->once())->method('forward')->with('index')->willReturnSelf();
     $this->assertInstanceOf('Magento\\Backend\\Model\\View\\Result\\Forward', $this->processData->execute());
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function dispatch(\Magento\Framework\App\RequestInterface $request)
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'dispatch');
     if (!$pluginInfo) {
         return parent::dispatch($request);
     } else {
         return $this->___callPlugins('dispatch', func_get_args(), $pluginInfo);
     }
 }