19
19
use Magento \Framework \Exception \LocalizedException ;
20
20
use Magento \Framework \Exception \NoSuchEntityException ;
21
21
use Magento \Framework \Exception \StateException ;
22
+ use Magento \Framework \Registry ;
22
23
use Magento \Framework \View \LayoutInterface ;
23
24
use Magento \Quote \Api \CartManagementInterface ;
24
25
use Magento \Quote \Test \Fixture \AddProductToCart as AddProductToCartFixture ;
25
26
use Magento \Quote \Test \Fixture \CustomerCart ;
26
27
use Magento \Sales \Api \InvoiceOrderInterface ;
27
- use Magento \Sales \Api \InvoiceRepositoryInterface ;
28
- use Magento \Sales \Api \OrderManagementInterface ;
29
- use Magento \Sales \Api \OrderRepositoryInterface ;
28
+ use Magento \Sales \Model \ResourceModel \Order \CollectionFactory as OrderCollectionFactory ;
29
+ use Magento \Sales \Model \ResourceModel \Order \Invoice \CollectionFactory as InvoiceCollectionFactory ;
30
30
use Magento \Store \Model \ScopeInterface ;
31
31
use Magento \Store \Model \StoreManagerInterface ;
32
32
use Magento \Store \Test \Fixture \Group as StoreGroupFixture ;
@@ -65,35 +65,40 @@ class AdminOrderReportsTest extends AbstractBackendController
65
65
*/
66
66
private $ storeManager ;
67
67
68
- /**
69
- * @var OrderRepositoryInterface
70
- */
71
- private $ orderRepository ;
72
-
73
- /**
74
- * @var OrderManagementInterface
75
- */
76
- private $ orderManagement ;
77
-
78
- /**
79
- * @var InvoiceRepositoryInterface
80
- */
81
- private $ invoiceRepository ;
82
-
83
- private int $ orderId ;
84
-
85
- private int $ invoiceId ;
86
-
87
68
protected function setUp (): void
88
69
{
89
70
parent ::setUp ();
90
71
$ this ->cartManagement = $ this ->_objectManager ->get (CartManagementInterface::class);
91
72
$ this ->invoiceOrder = $ this ->_objectManager ->get (InvoiceOrderInterface::class);
92
73
$ this ->fixtures = $ this ->_objectManager ->get (DataFixtureStorageManager::class)->getStorage ();
93
74
$ this ->storeManager = $ this ->_objectManager ->get (StoreManagerInterface::class);
94
- $ this ->orderRepository = $ this ->_objectManager ->get (OrderRepositoryInterface::class);
95
- $ this ->orderManagement = $ this ->_objectManager ->get (OrderManagementInterface::class);
96
- $ this ->invoiceRepository = $ this ->_objectManager ->get (InvoiceRepositoryInterface::class);
75
+ }
76
+
77
+ protected function tearDown (): void
78
+ {
79
+ $ store = $ this ->storeManager ->getStore ();
80
+ $ store ->setCurrentCurrencyCode ('USD ' );
81
+
82
+ $ registry = $ this ->_objectManager ->get (Registry::class);
83
+ $ registry ->unregister ('isSecureArea ' );
84
+ $ registry ->register ('isSecureArea ' , true );
85
+
86
+ $ orderCollection = $ this ->_objectManager ->create (OrderCollectionFactory::class)->create ();
87
+ foreach ($ orderCollection as $ order ) {
88
+ $ order ->delete ();
89
+ }
90
+
91
+ $ invoiceCollection = $ this ->_objectManager ->create (InvoiceCollectionFactory::class)->create ();
92
+ foreach ($ invoiceCollection as $ invoice ) {
93
+ $ invoice ->delete ();
94
+ }
95
+
96
+ $ this ->_objectManager ->create ('Magento\Sales\Model\ResourceModel\Report\Order ' )->aggregate ();
97
+
98
+ $ registry ->unregister ('isSecureArea ' );
99
+ $ registry ->register ('isSecureArea ' , false );
100
+
101
+ parent ::tearDown ();
97
102
}
98
103
99
104
/**
@@ -134,10 +139,10 @@ public function testAdminOrderReportsForMultiWebsiteWithDifferentDisplayCurrency
134
139
$ store = $ this ->storeManager ->getStore ();
135
140
$ store ->setCurrentCurrencyCode ('EUR ' );
136
141
137
- $ this -> orderId = $ this ->cartManagement ->placeOrder ($ cart ->getId ());
138
- $ this ->assertNotEmpty ($ this -> orderId );
139
- $ this -> invoiceId = $ this ->invoiceOrder ->execute ($ this -> orderId );
140
- $ this ->assertNotEmpty ($ this -> invoiceId );
142
+ $ orderId = $ this ->cartManagement ->placeOrder ($ cart ->getId ());
143
+ $ this ->assertNotEmpty ($ orderId );
144
+ $ invoiceId = $ this ->invoiceOrder ->execute ($ orderId );
145
+ $ this ->assertNotEmpty ($ invoiceId );
141
146
142
147
$ this ->_objectManager ->create ('Magento\Sales\Model\ResourceModel\Report\Order ' )->aggregate ();
143
148
@@ -161,26 +166,4 @@ public function testAdminOrderReportsForMultiWebsiteWithDifferentDisplayCurrency
161
166
$ blockHtml = $ salesReportGrid ->toHtml ();
162
167
$ this ->assertStringContainsString ('€ ' , $ blockHtml );
163
168
}
164
-
165
- /**
166
- * @inheritdoc
167
- */
168
- protected function tearDown (): void
169
- {
170
- $ store = $ this ->storeManager ->getStore ();
171
- $ store ->setCurrentCurrencyCode ('USD ' );
172
-
173
- $ order = $ this ->orderRepository ->get ($ this ->orderId );
174
- if ($ order ) {
175
- $ this ->orderManagement ->cancel ($ this ->orderId );
176
- $ this ->orderRepository ->delete ($ order );
177
- }
178
-
179
- $ invoice = $ this ->invoiceRepository ->get ($ this ->invoiceId );
180
- $ this ->invoiceRepository ->delete ($ invoice );
181
-
182
- $ this ->_objectManager ->create ('Magento\Sales\Model\ResourceModel\Report\Order ' )->aggregate ();
183
-
184
- parent ::tearDown ();
185
- }
186
169
}
0 commit comments