11<?php
22/**
3- * Copyright © Magento, Inc. All rights reserved.
4- * See COPYING.txt for license details .
3+ * Copyright 2024 Adobe
4+ * All Rights Reserved .
55 */
66declare (strict_types=1 );
77
88namespace Magento \Reports \Controller \Adminhtml \Report \Sales ;
99
1010use Magento \Catalog \Helper \Data ;
1111use Magento \Catalog \Test \Fixture \Product as ProductFixture ;
12- use Magento \Checkout \Test \Fixture \PlaceOrder as PlaceOrderFixture ;
1312use Magento \Checkout \Test \Fixture \SetBillingAddress as SetBillingAddressFixture ;
1413use Magento \Checkout \Test \Fixture \SetDeliveryMethod as SetDeliveryMethodFixture ;
1514use Magento \Checkout \Test \Fixture \SetPaymentMethod as SetPaymentMethodFixture ;
1615use Magento \Checkout \Test \Fixture \SetShippingAddress as SetShippingAddressFixture ;
1716use Magento \Customer \Test \Fixture \Customer ;
1817use Magento \Directory \Test \Fixture \CurrencyRate ;
19- use Magento \Framework \App \Config \ScopeConfigInterface ;
20- use Magento \Framework \App \ObjectManager ;
2118use Magento \Framework \Exception \CouldNotSaveException ;
2219use Magento \Framework \Exception \LocalizedException ;
2320use Magento \Framework \Exception \NoSuchEntityException ;
2421use Magento \Framework \Exception \StateException ;
2522use Magento \Framework \View \LayoutInterface ;
23+ use Magento \Quote \Api \CartManagementInterface ;
2624use Magento \Quote \Test \Fixture \AddProductToCart as AddProductToCartFixture ;
2725use 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 ;
2929use Magento \Store \Test \Fixture \Group as StoreGroupFixture ;
3030use Magento \Store \Test \Fixture \Store as StoreFixture ;
3131use Magento \Store \Test \Fixture \Website as WebsiteFixture ;
32- use Magento \TestFramework \Fixture \AppArea ;
33- use Magento \TestFramework \Fixture \AppIsolation ;
3432use Magento \TestFramework \Fixture \Config ;
3533use Magento \TestFramework \Fixture \DataFixture ;
3634use Magento \TestFramework \Fixture \DataFixtureStorage ;
3735use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
3836use Magento \TestFramework \Fixture \DbIsolation ;
3937use Magento \TestFramework \TestCase \AbstractBackendController ;
4038
41- class AdminOrderReports extends AbstractBackendController
39+ /**
40+ * Test for order reports.
41+ */
42+ class AdminOrderReportsTest extends AbstractBackendController
4243{
4344 /**
4445 * @var DataFixtureStorage
4546 */
4647 private $ fixtures ;
4748
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+
4864 protected function setUp (): void
4965 {
5066 parent ::setUp ();
67+ $ this ->cartManagement = $ this ->_objectManager ->get (CartManagementInterface::class);
68+ $ this ->invoiceOrder = $ this ->_objectManager ->get (InvoiceOrderInterface::class);
5169 $ this ->fixtures = $ this ->_objectManager ->get (DataFixtureStorageManager::class)->getStorage ();
70+ $ this ->storeManager = $ this ->_objectManager ->get (StoreManagerInterface::class);
5271 }
5372
5473 /**
74+ * Test to verify admin order reports for multi website with different display currency.
75+ *
5576 * @throws NoSuchEntityException
5677 * @throws CouldNotSaveException
5778 * @throws StateException
@@ -63,12 +84,12 @@ protected function setUp(): void
6384 DataFixture(WebsiteFixture::class, ['code ' => 'website2 ' ], as: 'website2 ' ),
6485 DataFixture(StoreGroupFixture::class, ['website_id ' => '$website2.id$ ' ], 'group2 ' ),
6586 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 ' ),
6889 DataFixture(CurrencyRate::class, ['USD ' => ['EUR ' => '0.8 ' ]]),
6990 DataFixture(ProductFixture::class, ['website_ids ' => [1 , '$website2.id$ ' ]], as: 'p1 ' ),
7091 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 ' ),
7293 DataFixture(
7394 AddProductToCartFixture::class,
7495 ['cart_id ' => '$cart.id$ ' , 'product_id ' => '$p1.id$ ' , 'qty ' => 1 ]
@@ -77,36 +98,40 @@ protected function setUp(): void
7798 DataFixture(SetShippingAddressFixture::class, ['cart_id ' => '$cart.id$ ' ], as: 'shippingAddress ' ),
7899 DataFixture(SetDeliveryMethodFixture::class, ['cart_id ' => '$cart.id$ ' ]),
79100 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 ' ),
82101 ]
83102 public function testAdminOrderReportsForMultiWebsiteWithDifferentDisplayCurrency ()
84103 {
85- $ scopeConfig = ObjectManager::getInstance ()->get (ScopeConfigInterface::class);
86-
104+ $ cart = $ this ->fixtures ->get ('cart ' );
87105 $ websiteId = (int ) $ this ->fixtures ->get ('website2 ' )->getId ();
88106
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+
89115 $ this ->_objectManager ->create ('Magento\Sales\Model\ResourceModel\Report\Order ' )->aggregate ();
90116
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 ' ));
93119
94120 $ requestArray = [
95121 'report_type ' => 'created_at_order ' ,
96122 'period_type ' => 'day ' ,
97- 'from ' => $ beforeCurrentdate ,
98- 'to ' => $ afterCurrentdate ,
123+ 'from ' => $ beforeCurrentDate ,
124+ 'to ' => $ afterCurrentDate ,
99125 'show_order_statuses ' => '0 ' ,
100126 'show_empty_rows ' => '0 ' ,
101127 'show_actual_columns ' => '0 ' ,
102128 ];
103129 $ filterData = base64_encode (http_build_query ($ requestArray ));
104130 $ this ->dispatch ("backend/reports/report_sales/sales/website/ {$ websiteId }/filter/ {$ filterData }/ " );
105131 $ this ->assertEquals (200 , $ this ->getResponse ()->getHttpResponseCode ());
106- $ body = $ this ->getResponse ()->getBody ();
107132 $ layout = $ this ->_objectManager ->get (LayoutInterface::class);
108133 $ salesReportGrid = $ layout ->getBlock ('adminhtml_sales_sales.grid ' );
109134 $ blockHtml = $ salesReportGrid ->toHtml ();
110- $ this ->assertNotEmpty ( $ blockHtml );
135+ $ this ->assertStringContainsString ( ' € ' , $ blockHtml );
111136 }
112137}
0 commit comments