public function testAddPaypalShortcutsNotEnabled() { $orPosition = 'before'; $containerMock = $this->getMockBuilder('\\Magento\\Catalog\\Block\\ShortcutButtons')->disableOriginalConstructor()->getMock(); $event = new \Magento\Framework\DataObject(['is_catalog_product' => false, 'container' => $containerMock, 'or_position' => $orPosition]); $observer = new \Magento\Framework\Event\Observer(['event' => $event]); $this->paypalMethodMock->expects($this->once())->method('isActive')->willReturn(true); $this->paypalConfigMock->expects($this->once())->method('isShortcutCheckoutEnabled')->willReturn(false); $containerMock->expects($this->never())->method('getLayout'); $this->addPaypalShortcutsObserver->execute($observer); }
public function testExecuteValidationFailure() { $paymentMethodNonce = 'nonce'; $email = '*****@*****.**'; $billingAddress = ['someAddress']; $details = ['email' => $email, 'billingAddress' => $billingAddress]; $detailsEncoded = json_encode($details); $this->braintreePayPalConfigMock->expects($this->once())->method('isBillingAddressEnabled')->willReturn(true); $this->requestMock->expects($this->at(0))->method('getParam')->with('payment_method_nonce')->willReturn($paymentMethodNonce); $this->requestMock->expects($this->at(1))->method('getParam')->with('details')->willReturn($detailsEncoded); $this->setupCart(); $errorMessage = new \Magento\Framework\Phrase('Selected payment type is not allowed for billing country.'); $this->paymentMethodInstanceMock->expects($this->once())->method('validate')->willThrowException(new \Magento\Framework\Exception\LocalizedException($errorMessage)); $this->messageManagerMock->expects($this->once())->method('addError')->with(new \Magento\Framework\Phrase('Selected payment type is not allowed for billing country.')); $resultRedirect = $this->getMockBuilder('\\Magento\\Framework\\Controller\\Result\\Redirect')->disableOriginalConstructor()->getMock(); $resultRedirect->expects($this->once())->method('setPath')->with('checkout/cart')->willReturnSelf(); $this->resultFactoryMock->expects($this->once())->method('create')->with(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT)->willReturn($resultRedirect); $this->assertEquals($resultRedirect, $this->controller->execute()); }