1
1
<?php
2
2
/**
3
- * Copyright © Magento, Inc. All rights reserved.
4
- * See COPYING.txt for license details .
3
+ * Copyright 2024 Adobe
4
+ * All Rights Reserved .
5
5
*/
6
6
declare (strict_types=1 );
7
7
8
8
namespace Magento \Reports \Controller \Adminhtml \Report \Sales ;
9
9
10
10
use Magento \Catalog \Helper \Data ;
11
11
use Magento \Catalog \Test \Fixture \Product as ProductFixture ;
12
- use Magento \Checkout \Test \Fixture \PlaceOrder as PlaceOrderFixture ;
13
12
use Magento \Checkout \Test \Fixture \SetBillingAddress as SetBillingAddressFixture ;
14
13
use Magento \Checkout \Test \Fixture \SetDeliveryMethod as SetDeliveryMethodFixture ;
15
14
use Magento \Checkout \Test \Fixture \SetPaymentMethod as SetPaymentMethodFixture ;
16
15
use Magento \Checkout \Test \Fixture \SetShippingAddress as SetShippingAddressFixture ;
17
16
use Magento \Customer \Test \Fixture \Customer ;
18
17
use Magento \Directory \Test \Fixture \CurrencyRate ;
19
- use Magento \Framework \App \Config \ScopeConfigInterface ;
20
- use Magento \Framework \App \ObjectManager ;
21
18
use Magento \Framework \Exception \CouldNotSaveException ;
22
19
use Magento \Framework \Exception \LocalizedException ;
23
20
use Magento \Framework \Exception \NoSuchEntityException ;
24
21
use Magento \Framework \Exception \StateException ;
25
22
use Magento \Framework \View \LayoutInterface ;
23
+ use Magento \Quote \Api \CartManagementInterface ;
26
24
use Magento \Quote \Test \Fixture \AddProductToCart as AddProductToCartFixture ;
27
25
use Magento \Quote \Test \Fixture \CustomerCart ;
28
- use Magento \Sales \Test \Fixture \Invoice as InvoiceFixture ;
26
+ use Magento \Sales \Api \InvoiceOrderInterface ;
27
+ use Magento \Store \Model \ScopeInterface ;
28
+ use Magento \Store \Model \StoreManagerInterface ;
29
29
use Magento \Store \Test \Fixture \Group as StoreGroupFixture ;
30
30
use Magento \Store \Test \Fixture \Store as StoreFixture ;
31
31
use Magento \Store \Test \Fixture \Website as WebsiteFixture ;
32
- use Magento \TestFramework \Fixture \AppArea ;
33
- use Magento \TestFramework \Fixture \AppIsolation ;
34
32
use Magento \TestFramework \Fixture \Config ;
35
33
use Magento \TestFramework \Fixture \DataFixture ;
36
34
use Magento \TestFramework \Fixture \DataFixtureStorage ;
37
35
use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
38
36
use Magento \TestFramework \Fixture \DbIsolation ;
39
37
use Magento \TestFramework \TestCase \AbstractBackendController ;
40
38
41
- class AdminOrderReports extends AbstractBackendController
39
+ /**
40
+ * Test for order reports.
41
+ */
42
+ class AdminOrderReportsTest extends AbstractBackendController
42
43
{
43
44
/**
44
45
* @var DataFixtureStorage
45
46
*/
46
47
private $ fixtures ;
47
48
49
+ /**
50
+ * @var CartManagementInterface
51
+ */
52
+ private $ cartManagement ;
53
+
54
+ /**
55
+ * @var InvoiceOrderInterface
56
+ */
57
+ private $ invoiceOrder ;
58
+
59
+ /**
60
+ * @var StoreManagerInterface
61
+ */
62
+ private $ storeManager ;
63
+
48
64
protected function setUp (): void
49
65
{
50
66
parent ::setUp ();
67
+ $ this ->cartManagement = $ this ->_objectManager ->get (CartManagementInterface::class);
68
+ $ this ->invoiceOrder = $ this ->_objectManager ->get (InvoiceOrderInterface::class);
51
69
$ this ->fixtures = $ this ->_objectManager ->get (DataFixtureStorageManager::class)->getStorage ();
70
+ $ this ->storeManager = $ this ->_objectManager ->get (StoreManagerInterface::class);
52
71
}
53
72
54
73
/**
74
+ * Test to verify admin order reports for multi website with different display currency.
75
+ *
55
76
* @throws NoSuchEntityException
56
77
* @throws CouldNotSaveException
57
78
* @throws StateException
@@ -63,12 +84,12 @@ protected function setUp(): void
63
84
DataFixture(WebsiteFixture::class, ['code ' => 'website2 ' ], as: 'website2 ' ),
64
85
DataFixture(StoreGroupFixture::class, ['website_id ' => '$website2.id$ ' ], 'group2 ' ),
65
86
DataFixture(StoreFixture::class, ['store_group_id ' => '$group2.id$ ' ], 'store2 ' ),
66
- Config('currency/options/default ' , 'EUR ' , ' website ' , 'website2 ' ),
67
- Config('currency/options/allow ' , 'EUR ' , ' website ' , 'website2 ' ),
87
+ Config('currency/options/default ' , 'EUR ' , ScopeInterface:: SCOPE_WEBSITE , 'website2 ' ),
88
+ Config('currency/options/allow ' , 'EUR ' , ScopeInterface:: SCOPE_WEBSITE , 'website2 ' ),
68
89
DataFixture(CurrencyRate::class, ['USD ' => ['EUR ' => '0.8 ' ]]),
69
90
DataFixture(ProductFixture::class, ['website_ids ' => [1 , '$website2.id$ ' ]], as: 'p1 ' ),
70
91
DataFixture(Customer::class, ['store_id ' => '$store2.id$ ' , 'website_id ' => '$website2.id$ ' ], as: 'customer ' ),
71
- DataFixture(CustomerCart::class, ['customer_id ' => '$customer.id$ ' , ' currency ' => ' EUR ' ], as: 'cart ' , scope: 'store2 ' ),
92
+ DataFixture(CustomerCart::class, ['customer_id ' => '$customer.id$ ' ], as: 'cart ' , scope: 'store2 ' ),
72
93
DataFixture(
73
94
AddProductToCartFixture::class,
74
95
['cart_id ' => '$cart.id$ ' , 'product_id ' => '$p1.id$ ' , 'qty ' => 1 ]
@@ -77,36 +98,40 @@ protected function setUp(): void
77
98
DataFixture(SetShippingAddressFixture::class, ['cart_id ' => '$cart.id$ ' ], as: 'shippingAddress ' ),
78
99
DataFixture(SetDeliveryMethodFixture::class, ['cart_id ' => '$cart.id$ ' ]),
79
100
DataFixture(SetPaymentMethodFixture::class, ['cart_id ' => '$cart.id$ ' ]),
80
- DataFixture(PlaceOrderFixture::class, ['cart_id ' => '$cart.id$ ' ], 'order ' ),
81
- DataFixture(InvoiceFixture::class, ['order_id ' => '$order.id$ ' ], 'invoice ' ),
82
101
]
83
102
public function testAdminOrderReportsForMultiWebsiteWithDifferentDisplayCurrency ()
84
103
{
85
- $ scopeConfig = ObjectManager::getInstance ()->get (ScopeConfigInterface::class);
86
-
104
+ $ cart = $ this ->fixtures ->get ('cart ' );
87
105
$ websiteId = (int ) $ this ->fixtures ->get ('website2 ' )->getId ();
88
106
107
+ $ store = $ this ->storeManager ->getStore ();
108
+ $ store ->setCurrentCurrencyCode ('EUR ' );
109
+
110
+ $ orderId = $ this ->cartManagement ->placeOrder ($ cart ->getId ());
111
+ $ this ->assertNotEmpty ($ orderId );
112
+ $ invoiceId = $ this ->invoiceOrder ->execute ($ orderId );
113
+ $ this ->assertNotEmpty ($ invoiceId );
114
+
89
115
$ this ->_objectManager ->create ('Magento\Sales\Model\ResourceModel\Report\Order ' )->aggregate ();
90
116
91
- $ beforeCurrentdate = date ('m-d-Y ' , strtotime ('-1 day ' ));
92
- $ afterCurrentdate = date ('m-d-Y ' , strtotime ('+1 day ' ));
117
+ $ beforeCurrentDate = date ('m-d-Y ' , strtotime ('-1 day ' ));
118
+ $ afterCurrentDate = date ('m-d-Y ' , strtotime ('+1 day ' ));
93
119
94
120
$ requestArray = [
95
121
'report_type ' => 'created_at_order ' ,
96
122
'period_type ' => 'day ' ,
97
- 'from ' => $ beforeCurrentdate ,
98
- 'to ' => $ afterCurrentdate ,
123
+ 'from ' => $ beforeCurrentDate ,
124
+ 'to ' => $ afterCurrentDate ,
99
125
'show_order_statuses ' => '0 ' ,
100
126
'show_empty_rows ' => '0 ' ,
101
127
'show_actual_columns ' => '0 ' ,
102
128
];
103
129
$ filterData = base64_encode (http_build_query ($ requestArray ));
104
130
$ this ->dispatch ("backend/reports/report_sales/sales/website/ {$ websiteId }/filter/ {$ filterData }/ " );
105
131
$ this ->assertEquals (200 , $ this ->getResponse ()->getHttpResponseCode ());
106
- $ body = $ this ->getResponse ()->getBody ();
107
132
$ layout = $ this ->_objectManager ->get (LayoutInterface::class);
108
133
$ salesReportGrid = $ layout ->getBlock ('adminhtml_sales_sales.grid ' );
109
134
$ blockHtml = $ salesReportGrid ->toHtml ();
110
- $ this ->assertNotEmpty ( $ blockHtml );
135
+ $ this ->assertStringContainsString ( ' € ' , $ blockHtml );
111
136
}
112
137
}
0 commit comments