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); }
/** * Add Braintree PayPal shortcut buttons * * @param \Magento\Framework\Event\Observer $observer * @return void */ public function execute(\Magento\Framework\Event\Observer $observer) { //Don't display shortcut on product view page if (!$this->methodPayPal->isActive() || !$this->paypalConfig->isShortcutCheckoutEnabled()) { return; } /** @var \Magento\Catalog\Block\ShortcutButtons $shortcutButtons */ $shortcutButtons = $observer->getEvent()->getContainer(); /** @var Shortcut $shortcut */ $shortcut = $shortcutButtons->getLayout()->createBlock(self::PAYPAL_SHORTCUT_BLOCK, '', ['data' => [Shortcut::MINI_CART_FLAG_KEY => !$observer->getEvent()->getIsCatalogProduct()]]); if ($shortcut->skipShortcutForGuest()) { return; } $shortcut->setShowOrPosition($observer->getEvent()->getOrPosition()); $shortcutButtons->addShortcut($shortcut); }
public function testGetConfigData() { $field = 'configFieldName'; $storeId = '2'; $configValue = 'configValue'; $this->payPalConfigMock->expects($this->once())->method('getConfigData')->with($field, $storeId)->willReturn($configValue); $this->assertEquals($configValue, $this->model->getConfigData($field, $storeId)); }
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()); }