|
5 | 5 | */
|
6 | 6 | namespace Magento\Reports\Block\Adminhtml;
|
7 | 7 |
|
| 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 | + |
8 | 13 | /**
|
9 | 14 | * Test class for \Magento\Reports\Block\Adminhtml\Grid
|
10 | 15 | * @magentoAppArea adminhtml
|
11 | 16 | */
|
12 | 17 | class GridTest extends \PHPUnit\Framework\TestCase
|
13 | 18 | {
|
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() |
15 | 28 | {
|
16 |
| - /** @var $block \Magento\Reports\Block\Adminhtml\Grid */ |
17 |
| - $block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( |
| 29 | + $this->block = Bootstrap::getObjectManager()->get( |
18 | 30 | \Magento\Reports\Block\Adminhtml\Grid::class
|
19 | 31 | );
|
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 | + ]; |
21 | 87 | }
|
22 | 88 | }
|
0 commit comments