Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PayflowTest.php
Go to the documentation of this file.
1 <?php
7 
16 
21 {
25  private $orderRepository;
26 
30  private $quoteRepository;
31 
35  private $order;
36 
40  protected function setUp()
41  {
42  parent::setUp();
43 
45  $filterBuilder = $this->_objectManager->get(FilterBuilder::class);
46  $filters = [
47  $filterBuilder->setField(OrderInterface::INCREMENT_ID)
48  ->setValue('100000001')
49  ->create(),
50  ];
51 
53  $searchCriteriaBuilder = $this->_objectManager->get(SearchCriteriaBuilder::class);
55  ->create();
56 
57  $this->orderRepository = $this->_objectManager->get(OrderRepositoryInterface::class);
58  $orders = $this->orderRepository->getList($searchCriteria)
59  ->getItems();
60 
62  $this->order = array_pop($orders);
63  $this->order->getPayment()->setMethod(Config::METHOD_PAYFLOWLINK);
64 
66  $quote = $this->_objectManager->create(Quote::class)->setStoreid($this->order->getStoreId());
67 
68  $this->quoteRepository = $this->_objectManager->get(CartRepositoryInterface::class);
69  $this->quoteRepository->save($quote);
70 
71  $this->order->setQuoteId($quote->getId());
72  $this->orderRepository->save($this->order);
73 
74  $session = $this->_objectManager->get(Session::class);
75  $session->setLastRealOrderId($this->order->getRealOrderId())->setLastQuoteId($this->order->getQuoteId());
76  }
77 
79  {
80  $this->dispatch('paypal/payflow/cancelpayment');
81  $this->assertContains("goToSuccessPage = ''", $this->getResponse()->getBody());
82  }
83 
85  {
86  $checkoutHelper = $this->_objectManager->create(\Magento\Paypal\Helper\Checkout::class);
87  $checkoutHelper->cancelCurrentOrder('test');
88  $this->dispatch('paypal/payflow/returnurl');
89  $this->assertContains("goToSuccessPage = ''", $this->getResponse()->getBody());
90  }
91 
93  {
94  $this->dispatch('paypal/payflow/form');
95  $this->assertContains(
96  '<form id="token_form" method="GET" action="https://payflowlink.paypal.com">',
97  $this->getResponse()->getBody()
98  );
99  // Check P3P header
100  $headerConstraints = [];
101  foreach ($this->getResponse()->getHeaders() as $header) {
102  $headerConstraints[] = new \PHPUnit\Framework\Constraint\IsEqual($header->getFieldName());
103  }
104  $constraint = new \PHPUnit\Framework\Constraint\LogicalOr();
105  $constraint->setConstraints($headerConstraints);
106  $this->assertThat('P3P', $constraint);
107  }
108 
114  public function testCancelAction(): void
115  {
116  $orderId = $this->order->getEntityId();
118  $order = $this->orderRepository->get($orderId);
120  $quote = $this->quoteRepository->get($order->getQuoteId());
121 
122  $session = $this->_objectManager->get(Session::class);
123  $session->setQuoteId($quote->getId());
124  $session->setPaypalStandardQuoteId($quote->getId())->setLastRealOrderId('100000001');
125  $this->dispatch('paypal/payflow/cancelpayment');
126 
127  $order = $this->_objectManager->create(OrderRepositoryInterface::class)->get($orderId);
128  $this->assertEquals('canceled', $order->getState());
129  $this->assertEquals($session->getQuote()->getGrandTotal(), $quote->getGrandTotal());
130  $this->assertEquals($session->getQuote()->getItemsCount(), $quote->getItemsCount());
131  }
132 }
$quote
$searchCriteria
$filters
Definition: uploader.phtml:11
$searchCriteriaBuilder