This commit is contained in:
2026-09-15 10:26:34 +08:00
commit ecf36afa56
10493 changed files with 1404888 additions and 0 deletions
@@ -0,0 +1,57 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Reports\Block\Adminhtml\Config\Form\Field;
use Magento\TestFramework\TestCase\AbstractBackendController;
/**
* Test for \Magento\Reports\Block\Adminhtml\Config\Form\Field\YtdStart.
*
* @magentoAppArea adminhtml
*/
class YtdStartTest extends AbstractBackendController
{
/**
* @var array
*/
private $monthNumbers = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
/**
* Test Get Month and Day Element renderer
*
* @return void
* @magentoAppIsolation enabled
* @magentoDbIsolation enabled
*/
public function testGetElementHtml(): void
{
$this->dispatch('backend/admin/system_config/edit/section/reports/');
$body = $this->getResponse()->getBody();
$this->assertOptionSelected('01', $body);
}
/**
* Assert that given option is selected.
*
* @param string $option Option value.
* @param string $content HTML content
* @return void
*/
private function assertOptionSelected(string $option, string $content): void
{
foreach ($this->monthNumbers as $monthNumber) {
$regEx = "\<option[^\>]+value\=\\\"$monthNumber\\\"[^\>]*?";
if ($monthNumber === $option) {
$regEx .= 'selected\=\"selected\"[^\>]*?';
}
$regEx .= "\>$monthNumber\<\/option\>";
$this->assertMatchesRegularExpression("#$regEx#", $content);
}
}
}
@@ -0,0 +1,39 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Reports\Block\Adminhtml\Filter;
/**
* Test class for \Magento\Reports\Block\Adminhtml\Filter\Form
* @magentoAppArea adminhtml
*/
class FormTest extends \PHPUnit\Framework\TestCase
{
/**
* @magentoAppIsolation enabled
*/
public function testPrepareForm()
{
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Framework\View\DesignInterface::class
)->setArea(
\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE
)->setDefaultDesignTheme();
$layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Framework\View\Layout::class
);
$block = $layout->addBlock(\Magento\Reports\Block\Adminhtml\Filter\Form::class);
$prepareFormMethod = new \ReflectionMethod(\Magento\Reports\Block\Adminhtml\Filter\Form::class, '_prepareForm');
$prepareFormMethod->setAccessible(true);
$prepareFormMethod->invoke($block);
$form = $block->getForm();
foreach (['from', 'to'] as $id) {
$element = $form->getElement($id);
$this->assertNotNull($element);
$this->assertNotEmpty($element->getDateFormat());
}
}
}
@@ -0,0 +1,88 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Reports\Block\Adminhtml;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\Framework\Locale\ResolverInterface;
use Magento\Framework\App\RequestInterface;
use Magento\Reports\Model\ResourceModel\Product\Sold\Collection\Initial;
/**
* Test class for \Magento\Reports\Block\Adminhtml\Grid
* @magentoAppArea adminhtml
*/
class GridTest extends \PHPUnit\Framework\TestCase
{
/**
* @var $block \Magento\Reports\Block\Adminhtml\Grid
*/
private $block;
/**
* @inheritDoc
*/
protected function setUp(): void
{
$this->block = Bootstrap::getObjectManager()->get(
\Magento\Reports\Block\Adminhtml\Grid::class
);
}
public function testGetDateFormat()
{
$this->assertNotEmpty($this->block->getDateFormat());
}
/**
* Test apply filtering to collection
*
* @param string $from
* @param string $to
* @param string $period
* @param string $locale
* @param int $expected
* @dataProvider getSalesRepresentativeIdDataProvider
*/
public function testGetPreparedCollection($from, $to, $period, $locale, $expected)
{
$encodedFilter = base64_encode('report_from='. $from . '&report_to=' . $to . '&report_period=' . $period);
$this->block->setVarNameFilter('filtername');
/** @var $request RequestInterface */
$request = Bootstrap::getObjectManager()->get(RequestInterface::class);
$request->setParams(['filtername' => $encodedFilter]);
$request->setParams(['locale' => $locale]);
/** @var $localeResolver ResolverInterface */
$localeResolver = Bootstrap::getObjectManager()->get(ResolverInterface::class);
$localeResolver->setLocale();
/** @var $initialCollection Initial */
$initialCollection = Bootstrap::getObjectManager()->create(
Initial::class
);
$this->block->setData(['dataSource' => $initialCollection]);
/** @var $collection Initial */
$collection = $this->block->getPreparedCollection();
$items = $collection->getItems();
$this->assertCount($expected, $items);
}
/**
* Data provider for testGetPreparedCollection method.
*
* @return array
*/
public function getSalesRepresentativeIdDataProvider()
{
return [
'Data for US locale' => ['08/15/2018', '08/20/2018', 'day', 'en_US', 6],
'Data for Australian locale' => ['15/08/2018', '31/08/2018', 'day', 'en_AU', 17],
'Data for French locale' => ['20.08.2018', '30.08.2018', 'day', 'fr_FR', 11],
];
}
}
@@ -0,0 +1,33 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Reports\Block\Adminhtml\Sales\Bestsellers;
/**
* @magentoAppArea adminhtml
*/
class GridTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Reports\Block\Adminhtml\Sales\Bestsellers\Grid
*/
protected $_block;
protected function setUp(): void
{
parent::setUp();
$this->_block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Framework\View\LayoutInterface::class
)->createBlock(
\Magento\Reports\Block\Adminhtml\Sales\Bestsellers\Grid::class
);
}
public function testGetResourceCollectionName()
{
$collectionName = $this->_block->getResourceCollectionName();
$this->assertTrue(class_exists($collectionName));
}
}
@@ -0,0 +1,60 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Reports\Block\Adminhtml\Sales\Coupons;
/**
* @magentoAppArea adminhtml
*/
class GridTest extends \PHPUnit\Framework\TestCase
{
/**
* Creates and inits block
*
* @param string|null $reportType
* @return \Magento\Reports\Block\Adminhtml\Sales\Coupons\Grid
*/
protected function _createBlock($reportType = null)
{
$block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Framework\View\LayoutInterface::class
)->createBlock(
\Magento\Reports\Block\Adminhtml\Sales\Coupons\Grid::class
);
$filterData = new \Magento\Framework\DataObject();
if ($reportType) {
$filterData->setReportType($reportType);
}
$block->setFilterData($filterData);
return $block;
}
/**
* @return string
*/
public function testGetResourceCollectionNameNormal()
{
$block = $this->_createBlock();
$normalCollection = $block->getResourceCollectionName();
$this->assertTrue(class_exists($normalCollection));
return $normalCollection;
}
/**
* @depends testGetResourceCollectionNameNormal
* @param string $normalCollection
*/
public function testGetResourceCollectionNameWithFilter($normalCollection)
{
$block = $this->_createBlock('updated_at_order');
$filteredCollection = $block->getResourceCollectionName();
$this->assertTrue(class_exists($filteredCollection));
$this->assertNotEquals($normalCollection, $filteredCollection);
}
}
@@ -0,0 +1,60 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Reports\Block\Adminhtml\Sales\Invoiced;
/**
* @magentoAppArea adminhtml
*/
class GridTest extends \PHPUnit\Framework\TestCase
{
/**
* Creates and inits block
*
* @param string|null $reportType
* @return \Magento\Reports\Block\Adminhtml\Sales\Invoiced\Grid
*/
protected function _createBlock($reportType = null)
{
$block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Framework\View\LayoutInterface::class
)->createBlock(
\Magento\Reports\Block\Adminhtml\Sales\Invoiced\Grid::class
);
$filterData = new \Magento\Framework\DataObject();
if ($reportType) {
$filterData->setReportType($reportType);
}
$block->setFilterData($filterData);
return $block;
}
/**
* @return string
*/
public function testGetResourceCollectionNameNormal()
{
$block = $this->_createBlock();
$normalCollection = $block->getResourceCollectionName();
$this->assertTrue(class_exists($normalCollection));
return $normalCollection;
}
/**
* @depends testGetResourceCollectionNameNormal
* @param string $normalCollection
*/
public function testGetResourceCollectionNameWithFilter($normalCollection)
{
$block = $this->_createBlock('created_at_invoice');
$filteredCollection = $block->getResourceCollectionName();
$this->assertTrue(class_exists($filteredCollection));
$this->assertNotEquals($normalCollection, $filteredCollection);
}
}
@@ -0,0 +1,60 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Reports\Block\Adminhtml\Sales\Refunded;
/**
* @magentoAppArea adminhtml
*/
class GridTest extends \PHPUnit\Framework\TestCase
{
/**
* Creates and inits block
*
* @param string|null $reportType
* @return \Magento\Reports\Block\Adminhtml\Sales\Refunded\Grid
*/
protected function _createBlock($reportType = null)
{
$block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Framework\View\LayoutInterface::class
)->createBlock(
\Magento\Reports\Block\Adminhtml\Sales\Refunded\Grid::class
);
$filterData = new \Magento\Framework\DataObject();
if ($reportType) {
$filterData->setReportType($reportType);
}
$block->setFilterData($filterData);
return $block;
}
/**
* @return string
*/
public function testGetResourceCollectionNameNormal()
{
$block = $this->_createBlock();
$normalCollection = $block->getResourceCollectionName();
$this->assertTrue(class_exists($normalCollection));
return $normalCollection;
}
/**
* @depends testGetResourceCollectionNameNormal
* @param string $normalCollection
*/
public function testGetResourceCollectionNameWithFilter($normalCollection)
{
$block = $this->_createBlock('created_at_refunded');
$filteredCollection = $block->getResourceCollectionName();
$this->assertTrue(class_exists($filteredCollection));
$this->assertNotEquals($normalCollection, $filteredCollection);
}
}
@@ -0,0 +1,100 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Reports\Block\Adminhtml\Sales\Sales;
/**
* @magentoAppArea adminhtml
*/
class GridTest extends \PHPUnit\Framework\TestCase
{
/**
* Creates and inits block
*
* @param string|null $reportType
* @return \Magento\Reports\Block\Adminhtml\Sales\Sales\Grid
*/
protected function _createBlock($reportType = null)
{
$block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Framework\View\LayoutInterface::class
)->createBlock(
\Magento\Reports\Block\Adminhtml\Sales\Sales\Grid::class
);
$filterData = new \Magento\Framework\DataObject();
if ($reportType) {
$filterData->setReportType($reportType);
}
$block->setFilterData($filterData);
return $block;
}
/**
* @return string
*/
public function testGetResourceCollectionNameNormal()
{
$block = $this->_createBlock();
$normalCollection = $block->getResourceCollectionName();
$this->assertTrue(class_exists($normalCollection));
return $normalCollection;
}
/**
* @depends testGetResourceCollectionNameNormal
* @param string $normalCollection
*/
public function testGetResourceCollectionNameWithFilter($normalCollection)
{
$block = $this->_createBlock('updated_at_order');
$filteredCollection = $block->getResourceCollectionName();
$this->assertTrue(class_exists($filteredCollection));
$this->assertNotEquals($normalCollection, $filteredCollection);
}
/**
* Check that grid does not contain unnecessary totals row
*
* @param $from string
* @param $to string
* @param $expectedResult bool
*
* @dataProvider getCountTotalsDataProvider
* @magentoDataFixture Magento/Reports/_files/orders.php
*/
public function testGetCountTotals($from, $to, $expectedResult)
{
$block = $this->_createBlock();
$filterData = new \Magento\Framework\DataObject();
$filterData->setReportType('updated_at_order');
$filterData->setPeriodType('day');
$filterData->setData('from', $from);
$filterData->setData('to', $to);
$block->setFilterData($filterData);
$block->toHtml();
$this->assertEquals($expectedResult, $block->getCountTotals());
}
/**
* Data provider for testGetCountTotals
*
* @return array
*/
public function getCountTotalsDataProvider()
{
$time = time();
return [
[date("Y-m-d", $time + 48 * 60 * 60), date("Y-m-d", $time + 72 * 60 * 60), false],
[date("Y-m-d", $time - 48 * 60 * 60), date("Y-m-d", $time + 48 * 60 * 60), true],
[null, null, false],
];
}
}
@@ -0,0 +1,60 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Reports\Block\Adminhtml\Sales\Shipping;
/**
* @magentoAppArea adminhtml
*/
class GridTest extends \PHPUnit\Framework\TestCase
{
/**
* Creates and inits block
*
* @param string|null $reportType
* @return \Magento\Reports\Block\Adminhtml\Sales\Shipping\Grid
*/
protected function _createBlock($reportType = null)
{
$block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Framework\View\LayoutInterface::class
)->createBlock(
\Magento\Reports\Block\Adminhtml\Sales\Shipping\Grid::class
);
$filterData = new \Magento\Framework\DataObject();
if ($reportType) {
$filterData->setReportType($reportType);
}
$block->setFilterData($filterData);
return $block;
}
/**
* @return string
*/
public function testGetResourceCollectionNameNormal()
{
$block = $this->_createBlock();
$normalCollection = $block->getResourceCollectionName();
$this->assertTrue(class_exists($normalCollection));
return $normalCollection;
}
/**
* @depends testGetResourceCollectionNameNormal
* @param string $normalCollection
*/
public function testGetResourceCollectionNameWithFilter($normalCollection)
{
$block = $this->_createBlock('created_at_shipment');
$filteredCollection = $block->getResourceCollectionName();
$this->assertTrue(class_exists($filteredCollection));
$this->assertNotEquals($normalCollection, $filteredCollection);
}
}
@@ -0,0 +1,60 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Reports\Block\Adminhtml\Sales\Tax;
/**
* @magentoAppArea adminhtml
*/
class GridTest extends \PHPUnit\Framework\TestCase
{
/**
* Creates and inits block
*
* @param string|null $reportType
* @return \Magento\Reports\Block\Adminhtml\Sales\Tax\Grid
*/
protected function _createBlock($reportType = null)
{
$block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Framework\View\LayoutInterface::class
)->createBlock(
\Magento\Reports\Block\Adminhtml\Sales\Tax\Grid::class
);
$filterData = new \Magento\Framework\DataObject();
if ($reportType) {
$filterData->setReportType($reportType);
}
$block->setFilterData($filterData);
return $block;
}
/**
* @return string
*/
public function testGetResourceCollectionNameNormal()
{
$block = $this->_createBlock();
$normalCollection = $block->getResourceCollectionName();
$this->assertTrue(class_exists($normalCollection));
return $normalCollection;
}
/**
* @depends testGetResourceCollectionNameNormal
* @param string $normalCollection
*/
public function testGetResourceCollectionNameWithFilter($normalCollection)
{
$block = $this->_createBlock('updated_at_order');
$filteredCollection = $block->getResourceCollectionName();
$this->assertTrue(class_exists($filteredCollection));
$this->assertNotEquals($normalCollection, $filteredCollection);
}
}
@@ -0,0 +1,54 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Reports\Block\Adminhtml\Shopcart\Abandoned;
use Magento\Quote\Model\Quote;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\Framework\View\LayoutInterface;
/**
* Test class for \Magento\Reports\Block\Adminhtml\Shopcart\Abandoned\Grid
*
* @magentoAppArea adminhtml
* @magentoDataFixture Magento/Sales/_files/quote.php
* @magentoDataFixture Magento/Customer/_files/customer.php
*/
class GridTest extends \Magento\Reports\Block\Adminhtml\Shopcart\GridTestAbstract
{
/**
* @return void
*/
public function testGridContent(): void
{
/** @var LayoutInterface $layout */
$layout = Bootstrap::getObjectManager()->get(LayoutInterface::class);
/** @var Grid $grid */
$grid = $layout->createBlock(Grid::class);
$grid->getRequest()->setParams(['filter' => base64_encode(urlencode('email=customer@example.com'))]);
$result = $grid->getPreparedCollection();
$this->assertCount(1, $result->getItems());
/** @var Quote $quote */
$quote = $result->getFirstItem();
$this->assertEquals('customer@example.com', $quote->getCustomerEmail());
$this->assertEquals(10.00, $quote->getSubtotal());
}
/**
* @return void
*/
public function testPageSizeIsSetToNullWhenExportCsvFile(): void
{
/** @var LayoutInterface $layout */
$layout = Bootstrap::getObjectManager()->get(LayoutInterface::class);
/** @var Grid $grid */
$grid = $layout->createBlock(Grid::class);
$grid->getCsvFile();
$this->assertNull($grid->getCollection()->getPageSize());
}
}
@@ -0,0 +1,32 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Reports\Block\Adminhtml\Shopcart;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\Quote\Model\Quote;
abstract class GridTestAbstract extends \PHPUnit\Framework\TestCase
{
/**
* {@inheritDoc}
*/
protected function setUp(): void
{
parent::setUp();
$objectManager = Bootstrap::getObjectManager();
/** @var \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository */
$customerRepository = $objectManager->create(\Magento\Customer\Api\CustomerRepositoryInterface::class);
$customerData = $customerRepository->getById(1);
/** @var Quote $quoteFixture */
$quoteFixture = $objectManager->create(\Magento\Quote\Model\Quote::class);
$quoteFixture->load('test01', 'reserved_order_id');
$quoteFixture->setIsActive(true);
$quoteFixture->setCustomer($customerData);
$quoteFixture->save();
}
}
@@ -0,0 +1,39 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Reports\Block\Adminhtml\Shopcart\Product;
use Magento\Quote\Model\Quote\Item;
use Magento\TestFramework\Helper\Bootstrap;
/**
* Test class for \Magento\Reports\Block\Adminhtml\Shopcart\Product\Grid
*
* @magentoAppArea adminhtml
* @magentoDataFixture Magento/Sales/_files/quote.php
* @magentoDataFixture Magento/Customer/_files/customer.php
*/
class GridTest extends \Magento\Reports\Block\Adminhtml\Shopcart\GridTestAbstract
{
/**
* @return void
*/
public function testGridContent()
{
/** @var \Magento\Framework\View\LayoutInterface $layout */
$layout = Bootstrap::getObjectManager()->get(\Magento\Framework\View\LayoutInterface::class);
/** @var Grid $grid */
$grid = $layout->createBlock(\Magento\Reports\Block\Adminhtml\Shopcart\Product\Grid::class);
$result = $grid->getPreparedCollection();
$this->assertCount(1, $result->getItems());
/** @var Item $quoteItem */
$quoteItem = $result->getFirstItem();
$this->assertInstanceOf(\Magento\Quote\Model\Quote\Item::class, $quoteItem);
$this->assertGreaterThan(0, (int)$quoteItem->getProductId());
$this->assertEquals('Simple Product', $quoteItem->getName());
}
}