public function testObserveHtmlTransactionId() { $observerMock = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->setMethods(['getDataObject'])->disableOriginalConstructor()->getMock(); $transactionMock = $this->getMockBuilder('\\Magento\\Sales\\Model\\Order\\Payment\\Transaction')->setMethods(['getOrder', 'getTxnId', 'setData'])->disableOriginalConstructor()->getMock(); $orderMock = $this->getMockBuilder('\\Magento\\Sales\\Model\\Order')->setMethods(['getPayment'])->disableOriginalConstructor()->getMock(); $paymentMock = $this->getMockBuilder('\\Magento\\Sales\\Model\\Order\\Payment')->setMethods(['getMethodInstance'])->disableOriginalConstructor()->getMock(); $methodInstanceMock = $this->getMockBuilder('\\Magento\\Payment\\Model\\MethodInterface')->setMethods(['getCode'])->getMockForAbstractClass(); $observerMock->expects($this->once())->method('getDataObject')->willReturn($transactionMock); $transactionMock->expects($this->once())->method('getOrder')->willReturn($orderMock); $orderMock->expects($this->once())->method('getPayment')->willReturn($paymentMock); $paymentMock->expects($this->once())->method('getMethodInstance')->willReturn($methodInstanceMock); $methodInstanceMock->expects($this->once())->method('getCode')->willReturn("'test'"); $transactionMock->expects($this->once())->method('getTxnId')->willReturn("'test'"); $this->paypalDataMock->expects($this->once())->method('getHtmlTransactionId')->willReturn('test'); $transactionMock->expects($this->once())->method('setData')->with('html_txn_id', 'test'); $this->_model->observeHtmlTransactionId($observerMock); }
/** * @param bool $isValid * @dataProvider addBillingAgreementToSessionDataProvider */ public function testAddBillingAgreementToSession($isValid) { $agreement = $this->getMock('Magento\\Paypal\\Model\\Billing\\Agreement', array(), array(), '', false); $agreement->expects($this->once())->method('isValid')->will($this->returnValue($isValid)); $comment = $this->getMockForAbstractClass('Magento\\Framework\\Model\\AbstractModel', [], '', false, true, true, array('__wakeup')); $order = $this->getMock('Magento\\Sales\\Model\\Order', array(), array(), '', false); $order->expects($this->once())->method('addStatusHistoryComment')->with($isValid ? __('Created billing agreement #%1.', 'agreement reference id') : __('We couldn\'t create a billing agreement for this order.'))->will($this->returnValue($comment)); if ($isValid) { $agreement->expects($this->any())->method('__call')->with('getReferenceId')->will($this->returnValue('agreement reference id')); $order->expects(new MethodInvokedAtIndex(0))->method('addRelatedObject')->with($agreement); $this->_checkoutSession->expects($this->once())->method('__call')->with('setLastBillingAgreementReferenceId', array('agreement reference id')); } else { $this->_checkoutSession->expects($this->once())->method('__call')->with('unsLastBillingAgreementReferenceId'); $agreement->expects($this->never())->method('__call'); } $order->expects(new MethodInvokedAtIndex($isValid ? 1 : 0))->method('addRelatedObject')->with($comment); $payment = $this->getMock('Magento\\Sales\\Model\\Order\\Payment', array(), array(), '', false); $payment->expects($this->once())->method('__call')->with('getBillingAgreementData')->will($this->returnValue('not empty')); $payment->expects($this->once())->method('getOrder')->will($this->returnValue($order)); $agreement->expects($this->once())->method('importOrderPayment')->with($payment)->will($this->returnValue($agreement)); $this->_event->setPayment($payment); $this->_agreementFactory->expects($this->once())->method('create')->will($this->returnValue($agreement)); $this->_model->addBillingAgreementToSession($this->_observer); }