Skip to content

Commit d7cbe9f

Browse files
author
Oleksandr Dubovyk
committed
Merge branch 'MAGETWO-94119' into chaika_sept_23
2 parents 0eda9b8 + adec384 commit d7cbe9f

File tree

2 files changed

+72
-6
lines changed
  • app/code/Magento/Reports/Block/Adminhtml
  • dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml

2 files changed

+72
-6
lines changed

app/code/Magento/Reports/Block/Adminhtml/Grid.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ protected function _prepareCollection()
127127
* Validate from and to date
128128
*/
129129
try {
130-
$from = $this->_localeDate->scopeDate(null, $this->getFilter('report_from'), false);
131-
$to = $this->_localeDate->scopeDate(null, $this->getFilter('report_to'), false);
130+
$from = $this->_localeDate->date($this->getFilter('report_from'), null, false, false);
131+
$to = $this->_localeDate->date($this->getFilter('report_to'), null, false, false);
132132

133133
$collection->setInterval($from, $to);
134134
} catch (\Exception $e) {

dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/GridTest.php

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,84 @@
55
*/
66
namespace Magento\Reports\Block\Adminhtml;
77

8+
use Magento\TestFramework\Helper\Bootstrap;
9+
use Magento\Framework\Locale\ResolverInterface;
10+
use Magento\Framework\App\RequestInterface;
11+
use Magento\Reports\Model\ResourceModel\Product\Sold\Collection\Initial;
12+
813
/**
914
* Test class for \Magento\Reports\Block\Adminhtml\Grid
1015
* @magentoAppArea adminhtml
1116
*/
1217
class GridTest extends \PHPUnit\Framework\TestCase
1318
{
14-
public function testGetDateFormat()
19+
/**
20+
* @var $block \Magento\Reports\Block\Adminhtml\Grid
21+
*/
22+
private $block;
23+
24+
/**
25+
* @inheritDoc
26+
*/
27+
protected function setUp()
1528
{
16-
/** @var $block \Magento\Reports\Block\Adminhtml\Grid */
17-
$block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
29+
$this->block = Bootstrap::getObjectManager()->get(
1830
\Magento\Reports\Block\Adminhtml\Grid::class
1931
);
20-
$this->assertNotEmpty($block->getDateFormat());
32+
}
33+
34+
public function testGetDateFormat()
35+
{
36+
$this->assertNotEmpty($this->block->getDateFormat());
37+
}
38+
39+
/**
40+
* Test apply filtering to collection
41+
*
42+
* @param string $from
43+
* @param string $to
44+
* @param string $period
45+
* @param string $locale
46+
* @param int $expected
47+
* @dataProvider getSalesRepresentativeIdDataProvider
48+
*/
49+
public function testGetPreparedCollection($from, $to, $period, $locale, $expected)
50+
{
51+
$encodedFilter = base64_encode('report_from='. $from . '&report_to=' . $to . '&report_period=' . $period);
52+
53+
$this->block->setVarNameFilter('filtername');
54+
/** @var $request RequestInterface */
55+
$request = Bootstrap::getObjectManager()->get(RequestInterface::class);
56+
$request->setParams(['filtername' => $encodedFilter]);
57+
$request->setParams(['locale' => $locale]);
58+
59+
/** @var $localeResolver ResolverInterface */
60+
$localeResolver = Bootstrap::getObjectManager()->get(ResolverInterface::class);
61+
$localeResolver->setLocale();
62+
63+
/** @var $initialCollection Initial */
64+
$initialCollection = Bootstrap::getObjectManager()->create(
65+
Initial::class
66+
);
67+
$this->block->setData(['dataSource' => $initialCollection]);
68+
69+
/** @var $collection Initial */
70+
$collection = $this->block->getPreparedCollection();
71+
$items = $collection->getItems();
72+
$this->assertCount($expected, $items);
73+
}
74+
75+
/**
76+
* Data provider for testGetPreparedCollection method.
77+
*
78+
* @return array
79+
*/
80+
public function getSalesRepresentativeIdDataProvider()
81+
{
82+
return [
83+
'Data for US locale' => ['08/15/2018', '08/20/2018', 'day', 'en_US', 6],
84+
'Data for Australian locale' => ['15/08/2018', '31/08/2018', 'day', 'en_AU', 17],
85+
'Data for French locale' => ['20.08.2018', '30.08.2018', 'day', 'fr_FR', 11],
86+
];
2187
}
2288
}

0 commit comments

Comments
 (0)