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

Commit 2b44fd1

Browse files
author
Dmytro Yushkin
committed
MAGETWO-65119: Create/update automated functional tests
- Reimplemented customer cleanup logic
1 parent 9568a25 commit 2b44fd1

File tree

6 files changed

+171
-93
lines changed

6 files changed

+171
-93
lines changed

Test/TestCase/DenyPaymentWithSignifydGuaranteeDeclinedTest.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@
66
namespace Magento\Signifyd\Test\TestCase;
77

88
use Magento\Mtf\TestCase\Scenario;
9-
use Magento\Sales\Test\Fixture\OrderInjectable;
10-
use Magento\Sales\Test\Page\Adminhtml\OrderIndex;
11-
use Magento\Sales\Test\Page\Adminhtml\SalesOrderView;
12-
use Magento\Sales\Test\TestStep\CancelOrderStep;
13-
use Magento\Signifyd\Test\Page\SignifydConsole\SignifydNotifications;
149

1510
/**
1611
* * Preconditions:

Test/TestStep/SignifydCancelOrderStep.php

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Signifyd\Test\TestStep;
77

8+
use Magento\Mtf\TestStep\TestStepFactory;
89
use Magento\Mtf\TestStep\TestStepInterface;
910
use Magento\Sales\Test\Fixture\OrderInjectable;
1011
use Magento\Sales\Test\Page\Adminhtml\OrderIndex;
@@ -30,7 +31,7 @@ class SignifydCancelOrderStep implements TestStepInterface
3031
*
3132
* @var OrderInjectable
3233
*/
33-
private $orderInjectable;
34+
private $order;
3435

3536
/**
3637
* Order View page.
@@ -40,48 +41,28 @@ class SignifydCancelOrderStep implements TestStepInterface
4041
private $salesOrderView;
4142

4243
/**
43-
* Cancel order step.
44+
* Test step factory.
4445
*
45-
* @var CancelOrderStep
46+
* @var TestStepFactory
4647
*/
47-
private $cancelOrderStep;
48-
49-
/**
50-
* Deny order step.
51-
*
52-
* @var DenyPaymentStep
53-
*/
54-
private $denyPaymentStep;
55-
56-
/**
57-
* Unhold order step.
58-
*
59-
* @var UnholdOrderStep
60-
*/
61-
private $unholdOrderStep;
48+
private $testStepFactory;
6249

6350
/**
6451
* @param OrderIndex $orderIndex
65-
* @param OrderInjectable $orderInjectable
52+
* @param OrderInjectable $order
6653
* @param SalesOrderView $salesOrderView
67-
* @param CancelOrderStep $cancelOrderStep
68-
* @param DenyPaymentStep $denyPaymentStep
69-
* @param UnholdOrderStep $unholdOrderStep
54+
* @param TestStepFactory $testStepFactory
7055
*/
7156
public function __construct(
7257
OrderIndex $orderIndex,
73-
OrderInjectable $orderInjectable,
58+
OrderInjectable $order,
7459
SalesOrderView $salesOrderView,
75-
CancelOrderStep $cancelOrderStep,
76-
DenyPaymentStep $denyPaymentStep,
77-
UnholdOrderStep $unholdOrderStep
60+
TestStepFactory $testStepFactory
7861
) {
7962
$this->orderIndex = $orderIndex;
80-
$this->orderInjectable = $orderInjectable;
63+
$this->order = $order;
8164
$this->salesOrderView = $salesOrderView;
82-
$this->cancelOrderStep = $cancelOrderStep;
83-
$this->denyPaymentStep = $denyPaymentStep;
84-
$this->unholdOrderStep = $unholdOrderStep;
65+
$this->testStepFactory = $testStepFactory;
8566
}
8667

8768
/**
@@ -91,20 +72,34 @@ public function run()
9172
{
9273
$this->orderIndex->open();
9374
$this->orderIndex->getSalesOrderGrid()
94-
->searchAndOpen(['id' => $this->orderInjectable->getId()]);
75+
->searchAndOpen(['id' => $this->order->getId()]);
9576

9677
switch ($this->salesOrderView->getOrderInfoBlock()->getOrderStatus()) {
9778
case 'Suspected Fraud':
98-
$this->denyPaymentStep->run();
79+
$this->getStepInstance(DenyPaymentStep::class)->run();
9980
break;
10081
case 'On Hold':
101-
$this->unholdOrderStep->run();
102-
$this->cancelOrderStep->run();
82+
$this->getStepInstance(UnholdOrderStep::class)->run();
83+
$this->getStepInstance(CancelOrderStep::class)->run();
10384
break;
10485
case 'Canceled':
10586
break;
10687
default:
107-
$this->cancelOrderStep->run();
88+
$this->getStepInstance(CancelOrderStep::class)->run();
10889
}
10990
}
91+
92+
/**
93+
* Creates test step instance with preset params.
94+
*
95+
* @param string $class
96+
* @return TestStepInterface
97+
*/
98+
private function getStepInstance($class)
99+
{
100+
return $this->testStepFactory->create(
101+
$class,
102+
['order' => $this->order]
103+
);
104+
}
110105
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Signifyd\Test\TestStep;
7+
8+
use Magento\Customer\Test\Fixture\Customer;
9+
use Magento\Customer\Test\TestStep\CreateCustomerStep;
10+
use Magento\Customer\Test\TestStep\DeleteCustomerStep;
11+
use Magento\Mtf\TestStep\TestStepFactory;
12+
use Magento\Mtf\TestStep\TestStepInterface;
13+
14+
/**
15+
* Customized create customer step with remove cleanup.
16+
*/
17+
class SignifydCreateCustomerStep implements TestStepInterface
18+
{
19+
/**
20+
* Customer fixture.
21+
*
22+
* @var Customer
23+
*/
24+
private $customer;
25+
26+
/**
27+
* Test step factory.
28+
*
29+
* @var TestStepFactory
30+
*/
31+
private $testStepFactory;
32+
33+
/**
34+
* @param Customer $customer
35+
* @param TestStepFactory $testStepFactory
36+
*/
37+
public function __construct(
38+
Customer $customer,
39+
TestStepFactory $testStepFactory
40+
) {
41+
$this->customer = $customer;
42+
$this->testStepFactory = $testStepFactory;
43+
}
44+
45+
/**
46+
* Run step flow.
47+
*
48+
* @return void
49+
*/
50+
public function run()
51+
{
52+
$this->getStepInstance(CreateCustomerStep::class)->run();
53+
}
54+
55+
/**
56+
* @return void
57+
*/
58+
public function cleanup()
59+
{
60+
$this->getStepInstance(DeleteCustomerStep::class)->run();
61+
}
62+
63+
/**
64+
* Creates test step instance with preset params.
65+
*
66+
* @param string $class
67+
* @return TestStepInterface
68+
*/
69+
private function getStepInstance($class)
70+
{
71+
return $this->testStepFactory->create(
72+
$class,
73+
['customer' => $this->customer]
74+
);
75+
}
76+
}

Test/TestStep/SignifydObserveCaseStep.php

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
*/
66
namespace Magento\Signifyd\Test\TestStep;
77

8-
use Magento\Customer\Test\TestStep\DeleteCustomerStep;
8+
use Magento\Mtf\TestStep\TestStepFactory;
99
use Magento\Mtf\TestStep\TestStepInterface;
10+
use Magento\Sales\Test\Fixture\OrderInjectable;
1011
use Magento\Signifyd\Test\Constraint\AssertCaseInfoOnSignifydConsole;
1112
use Magento\Signifyd\Test\Fixture\SignifydAddress;
1213
use Magento\Signifyd\Test\Fixture\SignifydData;
@@ -53,20 +54,6 @@ class SignifydObserveCaseStep implements TestStepInterface
5354
*/
5455
private $signifydData;
5556

56-
/**
57-
* Signifyd cancel order step.
58-
*
59-
* @var SignifydCancelOrderStep
60-
*/
61-
private $signifydCancelOrderStep;
62-
63-
/**
64-
* Delete customer step.
65-
*
66-
* @var DeleteCustomerStep
67-
*/
68-
private $deleteCustomerStep;
69-
7057
/**
7158
* Prices list.
7259
*
@@ -75,43 +62,47 @@ class SignifydObserveCaseStep implements TestStepInterface
7562
private $prices;
7663

7764
/**
78-
* Order id.
65+
* Order fixture.
7966
*
8067
* @var string
8168
*/
82-
private $orderId;
69+
private $order;
70+
71+
/**
72+
* Test step factory.
73+
*
74+
* @var TestStepFactory
75+
*/
76+
private $testStepFactory;
8377

8478
/**
8579
* @param AssertCaseInfoOnSignifydConsole $assertCaseInfoOnSignifydConsole
8680
* @param SignifydAddress $signifydAddress
8781
* @param SignifydCases $signifydCases
8882
* @param SignifydNotifications $signifydNotifications
8983
* @param SignifydData $signifydData
90-
* @param SignifydCancelOrderStep $signifydCancelOrderStep
91-
* @param DeleteCustomerStep $deleteCustomerStep
84+
* @param OrderInjectable $order
85+
* @param TestStepFactory $testStepFactory
9286
* @param array $prices
93-
* @param $orderId
9487
*/
9588
public function __construct(
9689
AssertCaseInfoOnSignifydConsole $assertCaseInfoOnSignifydConsole,
9790
SignifydAddress $signifydAddress,
9891
SignifydCases $signifydCases,
9992
SignifydNotifications $signifydNotifications,
10093
SignifydData $signifydData,
101-
SignifydCancelOrderStep $signifydCancelOrderStep,
102-
DeleteCustomerStep $deleteCustomerStep,
103-
array $prices,
104-
$orderId
94+
OrderInjectable $order,
95+
TestStepFactory $testStepFactory,
96+
array $prices
10597
) {
10698
$this->assertCaseInfo = $assertCaseInfoOnSignifydConsole;
10799
$this->signifydAddress = $signifydAddress;
108100
$this->signifydCases = $signifydCases;
109101
$this->signifydNotifications = $signifydNotifications;
110102
$this->signifydData = $signifydData;
111-
$this->signifydCancelOrderStep = $signifydCancelOrderStep;
112-
$this->deleteCustomerStep = $deleteCustomerStep;
103+
$this->order = $order;
104+
$this->testStepFactory = $testStepFactory;
113105
$this->prices = $prices;
114-
$this->orderId = $orderId;
115106
}
116107

117108
/**
@@ -130,21 +121,22 @@ public function run()
130121
$this->signifydAddress,
131122
$this->signifydData,
132123
$this->prices,
133-
$this->orderId,
124+
$this->order->getId(),
134125
$this->getCustomerFullName($this->signifydAddress)
135126
);
136127
}
137128

138129
/**
139130
* Cancel order if test fails, or in the end of variation.
140-
* Cleanup customer for next variations.
141131
*
142132
* @return void
143133
*/
144134
public function cleanup()
145135
{
146-
$this->signifydCancelOrderStep->run();
147-
$this->deleteCustomerStep->run();
136+
$this->testStepFactory->create(
137+
SignifydCancelOrderStep::class,
138+
['order' => $this->order]
139+
)->run();
148140
}
149141

150142
/**

0 commit comments

Comments
 (0)