Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 899c9e0

Browse files
author
Dmytro Yushkin
committed
Merge branch 'develop' of github.com:magento/magento2ee into MAGETWO-63642
2 parents fef8d3f + 2360284 commit 899c9e0

File tree

3 files changed

+206
-1
lines changed

3 files changed

+206
-1
lines changed

Model/Guarantee/CancelingServiceTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,31 @@ protected function setUp()
6565
]);
6666
}
6767

68+
/**
69+
* Checks a test case, when Signifyd guarantee was canceled.
70+
*
71+
* @covers \Magento\Signifyd\Model\Guarantee\CancelingService::cancelForOrder
72+
* @magentoDataFixture Magento/Signifyd/_files/case.php
73+
* @magentoConfigFixture current_store fraud_protection/signifyd/active 1
74+
*/
75+
public function testCancelForOrderWithCanceledGuarantee()
76+
{
77+
/** @var CaseRepositoryInterface $caseRepository */
78+
$caseRepository = $this->objectManager->get(CaseRepositoryInterface::class);
79+
$caseEntity = $caseRepository->getByCaseId(self::$caseId);
80+
$caseEntity->setGuaranteeDisposition(CaseInterface::GUARANTEE_CANCELED);
81+
$caseRepository->save($caseEntity);
82+
83+
$this->gateway->expects(self::never())
84+
->method('cancelGuarantee');
85+
86+
$this->logger->expects(self::never())
87+
->method('error');
88+
89+
$result = $this->service->cancelForOrder($caseEntity->getOrderId());
90+
self::assertFalse($result);
91+
}
92+
6893
/**
6994
* Checks a test case, when Signifyd gateway throws an exception.
7095
*

Observer/PlaceOrderTest.php

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Signifyd\Observer;
7+
8+
use Magento\Framework\Api\FilterBuilder;
9+
use Magento\Framework\Api\SearchCriteriaBuilder;
10+
use Magento\Framework\App\ObjectManager;
11+
use Magento\Framework\Event;
12+
use Magento\Framework\Event\Observer;
13+
use Magento\Sales\Api\Data\OrderInterface;
14+
use Magento\Sales\Api\OrderRepositoryInterface;
15+
use Magento\Signifyd\Api\CaseCreationServiceInterface;
16+
use Magento\TestFramework\Helper\Bootstrap;
17+
use PHPUnit_Framework_MockObject_MockObject as MockObject;
18+
use Psr\Log\LoggerInterface;
19+
20+
class PlaceOrderTest extends \PHPUnit_Framework_TestCase
21+
{
22+
/**
23+
* @var CaseCreationServiceInterface|MockObject
24+
*/
25+
private $creationService;
26+
27+
/**
28+
* @var LoggerInterface|MockObject
29+
*/
30+
private $logger;
31+
32+
/**
33+
* @var PlaceOrder
34+
*/
35+
private $placeOrder;
36+
37+
/**
38+
* @var ObjectManager
39+
*/
40+
private $objectManager;
41+
42+
/**
43+
* @inheritdoc
44+
*/
45+
protected function setUp()
46+
{
47+
$this->objectManager = Bootstrap::getObjectManager();
48+
49+
$this->creationService = $this->getMockBuilder(CaseCreationServiceInterface::class)
50+
->disableOriginalConstructor()
51+
->setMethods(['createForOrder'])
52+
->getMock();
53+
54+
$this->logger = $this->getMockBuilder(LoggerInterface::class)
55+
->disableOriginalConstructor()
56+
->getMock();
57+
58+
$this->placeOrder = $this->objectManager->create(PlaceOrder::class, [
59+
'caseCreationService' => $this->creationService,
60+
'logger' => $this->logger
61+
]);
62+
}
63+
64+
/**
65+
* Checks a case when order placed with offline payment method.
66+
*
67+
* @covers \Magento\Signifyd\Observer\PlaceOrder::execute
68+
* @magentoConfigFixture current_store fraud_protection/signifyd/active 1
69+
* @magentoDataFixture Magento/Signifyd/_files/order_with_customer_and_two_simple_products.php
70+
*/
71+
public function testExecuteWithOfflinePayment()
72+
{
73+
$order = $this->getOrder('100000005');
74+
$this->creationService->expects(self::never())
75+
->method('createForOrder');
76+
77+
$event = $this->objectManager->create(
78+
Event::class,
79+
[
80+
'data' => ['order' => $order]
81+
]
82+
);
83+
84+
/** @var Observer $observer */
85+
$observer = $this->objectManager->get(Observer::class);
86+
$observer->setEvent($event);
87+
88+
$this->placeOrder->execute($observer);
89+
}
90+
91+
/**
92+
* Checks a test case when order placed with online payment method.
93+
*
94+
* @covers \Magento\Signifyd\Observer\PlaceOrder::execute
95+
* @magentoConfigFixture current_store fraud_protection/signifyd/active 1
96+
* @magentoDataFixture Magento/Signifyd/_files/order_with_customer_and_two_simple_products.php
97+
*/
98+
public function testExecute()
99+
{
100+
$order = $this->getOrder('100000001');
101+
102+
$this->creationService->expects(self::once())
103+
->method('createForOrder')
104+
->with(self::equalTo($order->getEntityId()));
105+
106+
$event = $this->objectManager->create(
107+
Event::class,
108+
[
109+
'data' => ['order' => $order]
110+
]
111+
);
112+
113+
/** @var Observer $observer */
114+
$observer = $this->objectManager->get(Observer::class);
115+
$observer->setEvent($event);
116+
117+
$this->placeOrder->execute($observer);
118+
}
119+
120+
/**
121+
* Checks a test case when observer event contains two orders:
122+
* one order with offline payment and one order with online payment.
123+
*
124+
* @covers \Magento\Signifyd\Observer\PlaceOrder::execute
125+
* @magentoConfigFixture current_store fraud_protection/signifyd/active 1
126+
* @magentoDataFixture Magento/Signifyd/_files/order_with_customer_and_two_simple_products.php
127+
*/
128+
public function testExecuteWithMultipleOrders()
129+
{
130+
$orderWithOnlinePayment = $this->getOrder('100000001');
131+
$orderWithOfflinePayment = $this->getOrder('100000005');
132+
133+
// this service mock should be called only once for the order with online payment method.
134+
$this->creationService->expects(self::once())
135+
->method('createForOrder')
136+
->with(self::equalTo($orderWithOnlinePayment->getEntityId()));
137+
138+
$event = $this->objectManager->create(
139+
Event::class,
140+
[
141+
'data' => ['orders' => [$orderWithOfflinePayment, $orderWithOnlinePayment]]
142+
]
143+
);
144+
145+
/** @var Observer $observer */
146+
$observer = $this->objectManager->get(Observer::class);
147+
$observer->setEvent($event);
148+
149+
$this->placeOrder->execute($observer);
150+
}
151+
152+
/**
153+
* Gets stored order.
154+
*
155+
* @param string $incrementId
156+
* @return OrderInterface
157+
*/
158+
private function getOrder($incrementId)
159+
{
160+
/** @var FilterBuilder $filterBuilder */
161+
$filterBuilder = $this->objectManager->get(FilterBuilder::class);
162+
$filters = [
163+
$filterBuilder->setField(OrderInterface::INCREMENT_ID)
164+
->setValue($incrementId)
165+
->create()
166+
];
167+
168+
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
169+
$searchCriteriaBuilder = $this->objectManager->get(SearchCriteriaBuilder::class);
170+
$searchCriteria = $searchCriteriaBuilder->addFilters($filters)
171+
->create();
172+
173+
$orderRepository = $this->objectManager->get(OrderRepositoryInterface::class);
174+
$orders = $orderRepository->getList($searchCriteria)
175+
->getItems();
176+
177+
$order = array_pop($orders);
178+
179+
return $order;
180+
}
181+
}

_files/order_with_customer_and_two_simple_products.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
$addressData = include __DIR__ . '/../../../Magento/Sales/_files/address_data.php';
1818

19-
2019
$objectManager = Bootstrap::getObjectManager();
2120

2221
$billingAddress = $objectManager->create(Address::class, ['data' => $addressData]);

0 commit comments

Comments
 (0)