42 $this->_event = new \Magento\Framework\DataObject();
44 $this->_observer = new \Magento\Framework\Event\Observer();
45 $this->_observer->setEvent($this->_event);
47 $this->_agreementFactory = $this->createPartialMock(
48 \
Magento\Paypal\Model\Billing\AgreementFactory::class,
51 $this->_checkoutSession = $this->createMock(\
Magento\Checkout\Model\Session::class);
52 $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
53 $this->_model = $objectManagerHelper->getObject(
56 'agreementFactory' => $this->_agreementFactory,
57 'checkoutSession' => $this->_checkoutSession,
64 $payment = $this->createMock(\
Magento\Sales\Model\Order\Payment::class);
70 'getBillingAgreementData' 72 $this->returnValue(
null)
75 $this->_agreementFactory->expects($this->never())->method(
'create');
76 $this->_checkoutSession->expects($this->once())->method(
'__call')->with(
'unsLastBillingAgreementReferenceId');
77 $this->_model->execute($this->_observer);
87 $agreement->expects($this->once())->method(
'isValid')->will($this->returnValue($isValid));
88 $comment = $this->getMockForAbstractClass(
89 \
Magento\Framework\Model\AbstractModel::class,
97 $order = $this->createMock(\
Magento\Sales\Model\Order::class);
101 'addStatusHistoryComment' 104 'Created billing agreement #%1.',
105 'agreement reference id' 107 'We can\'t create a billing agreement for this order.' 110 $this->returnValue($comment)
120 $this->returnValue(
'agreement reference id')
122 $agreement->expects($this->once())->method(
'addOrderRelation')->with(
$order);
124 $this->_checkoutSession->expects(
129 'setLastBillingAgreementReferenceId',
130 [
'agreement reference id']
133 $this->_checkoutSession->expects(
138 'unsLastBillingAgreementReferenceId' 140 $agreement->expects($this->never())->method(
'__call');
144 $payment = $this->createMock(\
Magento\Sales\Model\Order\Payment::class);
150 'getBillingAgreementData' 152 $this->returnValue(
'not empty')
154 $payment->expects($this->once())->method(
'getOrder')->will($this->returnValue(
$order));
164 $this->_event->setPayment(
$payment);
165 $this->_agreementFactory->expects($this->once())->method(
'create')->will($this->returnValue(
$agreement));
166 $this->_model->execute($this->_observer);
174 return [[
true], [
false]];
testAddBillingAgreementToSessionNoData()
addBillingAgreementToSessionDataProvider()
testAddBillingAgreementToSession($isValid)