/**
  * @param array $paymentMethodsAvailability
  * @param array $blocks
  * @dataProvider addAvailabilityOfMethodsDataProvider
  */
 public function testAddPaypalShortcuts($paymentMethodsAvailability, $blocks)
 {
     $this->paypalConfigMock->expects($this->any())->method('isMethodAvailable')->will($this->returnValueMap($paymentMethodsAvailability));
     $layoutMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout')->setMethods(['createBlock'])->disableOriginalConstructor()->getMock();
     $shortcutButtonsMock = $this->getMockBuilder('Magento\\Catalog\\Block\\ShortcutButtons')->setMethods(['getLayout', 'addShortcut'])->disableOriginalConstructor()->getMock();
     $blockInstances = [];
     $atPosition = 0;
     foreach ($blocks as $blockName => $blockInstance) {
         if ($this->paypalConfigMock->isMethodAvailable($blockInstance[1])) {
             $block = $this->getMockBuilder($blockInstance[0])->setMethods(null)->disableOriginalConstructor()->getMock();
             $blockInstances[$blockName] = $block;
             $layoutMock->expects(new MethodInvokedAtIndex($atPosition))->method('createBlock')->with($blockName)->will($this->returnValue($block));
             $atPosition++;
         }
     }
     $shortcutButtonsMock->expects($this->any())->method('getLayout')->will($this->returnValue($layoutMock));
     $atPosition = 0;
     foreach ($blocks as $blockName => $blockInstance) {
         if ($this->paypalConfigMock->isMethodAvailable($blockInstance[1])) {
             $shortcutButtonsMock->expects(new MethodInvokedAtIndex($atPosition))->method('addShortcut')->with($this->identicalTo($blockInstances[$blockName]));
             $atPosition++;
         }
     }
     $this->_event->setContainer($shortcutButtonsMock);
     $this->_model->execute($this->_observer);
 }
Exemple #2
0
 /**
  * @dataProvider isMethodAvailableDataProvider
  */
 public function testIsMethodAvailableForIsMethodActive($methodName, $expected)
 {
     $this->_scopeConfig->expects($this->any())->method('getValue')->with('paypal/general/merchant_country')->will($this->returnValue('US'));
     $this->_scopeConfig->expects($this->exactly(2))->method('isSetFlag')->withAnyParameters()->will($this->returnValue(true));
     $this->_model->setMethod($methodName);
     $this->assertEquals($expected, $this->_model->isMethodAvailable($methodName));
 }
Exemple #3
0
 /**
  * Disable block output if banner turned off or PublisherId is miss
  *
  * @return string
  */
 protected function _toHtml()
 {
     if (!$this->_paypalConfig->isMethodAvailable(Config::METHOD_WPP_BML) && !$this->_paypalConfig->isMethodAvailable(Config::METHOD_WPP_PE_BML)) {
         return '';
     }
     $publisherId = $this->_paypalConfig->getBmlPublisherId();
     $display = $this->_paypalConfig->getBmlDisplay($this->_section);
     $position = $this->_paypalConfig->getBmlPosition($this->_section);
     if (!$publisherId || $display == 0 || $this->_position != $position) {
         return '';
     }
     $this->setData('publisher_id', $publisherId);
     $this->setData('size', $this->_paypalConfig->getBmlSize($this->_section));
     return parent::_toHtml();
 }
 /**
  * Add PayPal shortcut buttons
  *
  * @param EventObserver $observer
  * @return void
  */
 public function execute(EventObserver $observer)
 {
     /** @var \Magento\Catalog\Block\ShortcutButtons $shortcutButtons */
     $shortcutButtons = $observer->getEvent()->getContainer();
     $blocks = ['Magento\\Paypal\\Block\\Express\\Shortcut' => PaypalConfig::METHOD_WPP_EXPRESS, 'Magento\\Paypal\\Block\\WpsExpress\\Shortcut' => PaypalConfig::METHOD_WPS_EXPRESS, 'Magento\\Paypal\\Block\\PayflowExpress\\Shortcut' => PaypalConfig::METHOD_WPP_PE_EXPRESS, 'Magento\\Paypal\\Block\\Bml\\Shortcut' => PaypalConfig::METHOD_WPP_EXPRESS, 'Magento\\Paypal\\Block\\WpsBml\\Shortcut' => PaypalConfig::METHOD_WPS_EXPRESS, 'Magento\\Paypal\\Block\\Payflow\\Bml\\Shortcut' => PaypalConfig::METHOD_WPP_PE_EXPRESS];
     foreach ($blocks as $blockInstanceName => $paymentMethodCode) {
         if (!$this->paypalConfig->isMethodAvailable($paymentMethodCode)) {
             continue;
         }
         $params = ['shortcutValidator' => $this->shortcutFactory->create($observer->getEvent()->getCheckoutSession())];
         if (!in_array('Bml', explode('\\', $blockInstanceName))) {
             $params['checkoutSession'] = $observer->getEvent()->getCheckoutSession();
         }
         // we believe it's \Magento\Framework\View\Element\Template
         $shortcut = $shortcutButtons->getLayout()->createBlock($blockInstanceName, '', $params);
         $shortcut->setIsInCatalogProduct($observer->getEvent()->getIsCatalogProduct())->setShowOrPosition($observer->getEvent()->getOrPosition());
         $shortcutButtons->addShortcut($shortcut);
     }
 }