Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
HostedproTest.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Paypal\Model;
7 
12 use Magento\Paypal\Model\Hostedpro\RequestFactory;
13 use Magento\Paypal\Model\ProFactory;
16 
21 class HostedproTest extends \PHPUnit\Framework\TestCase
22 {
26  private $objectManager;
27 
31  private $model;
32 
36  private $api;
37 
38  protected function setUp()
39  {
40  $this->objectManager = Bootstrap::getObjectManager();
41 
42  $this->api = $this->getMockBuilder(Nvp::class)
43  ->disableOriginalConstructor()
44  ->setMethods(['call'])
45  ->getMock();
46 
47  $proFactory = $this->getProFactory();
48 
49  $this->model = $this->objectManager
50  ->create(Hostedpro::class, [
51  'proFactory' => $proFactory
52  ]);
53  }
54 
59  public function testInitialize()
60  {
62  $order = $this->objectManager->create(Order::class);
63  $order->loadByIncrementId('100000001');
64  $payment = $order->getPayment();
65 
66  $this->model->setInfoInstance($payment);
67 
68  $this->api->expects(static::once())
69  ->method('call')
70  ->willReturn([
71  'EMAILLINK' => 'https://securepayments.sandbox.paypal.com/webapps/HostedSoleSolutionApp/webflow/'
72  ]);
73 
74  $state = $this->objectManager->create(DataObject::class);
75  $this->model->initialize(Config::PAYMENT_ACTION_AUTH, $state);
76 
77  static::assertEquals(Order::STATE_PENDING_PAYMENT, $state->getState());
78  static::assertEquals(Order::STATE_PENDING_PAYMENT, $state->getStatus());
79  static::assertFalse($state->getIsNotified());
80  }
81 
86  protected function getConfig()
87  {
88  $config = $this->getMockBuilder(Config::class)
89  ->disableOriginalConstructor()
90  ->setMethods(['getValue'])
91  ->getMock();
92  $config->expects(static::any())
93  ->method('getValue')
94  ->with('payment_action')
95  ->willReturn(Config::PAYMENT_ACTION_AUTH);
96  return $config;
97  }
98 
103  protected function getProFactory()
104  {
105  $pro = $this->getMockBuilder(Pro::class)
106  ->disableOriginalConstructor()
107  ->setMethods(['getApi', 'setMethod', 'getConfig', '__wakeup'])
108  ->getMock();
109 
110  $config = $this->getConfig();
111  $pro->expects(static::any())
112  ->method('getConfig')
113  ->willReturn($config);
114  $pro->expects(static::any())
115  ->method('getApi')
116  ->willReturn($this->api);
117 
118  $proFactory = $this->getMockBuilder(ProFactory::class)
119  ->disableOriginalConstructor()
120  ->setMethods(['create'])
121  ->getMock();
122  $proFactory->expects(static::once())
123  ->method('create')
124  ->willReturn($pro);
125  return $proFactory;
126  }
127 }
$config
Definition: fraud_order.php:17
$order
Definition: order.php:55
$payment
Definition: order.php:17