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