GridTest.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Reports\Block\Adminhtml;
  7. use Magento\TestFramework\Helper\Bootstrap;
  8. use Magento\Framework\Locale\ResolverInterface;
  9. use Magento\Framework\App\RequestInterface;
  10. use Magento\Reports\Model\ResourceModel\Product\Sold\Collection\Initial;
  11. /**
  12. * Test class for \Magento\Reports\Block\Adminhtml\Grid
  13. * @magentoAppArea adminhtml
  14. */
  15. class GridTest extends \PHPUnit\Framework\TestCase
  16. {
  17. /**
  18. * @var $block \Magento\Reports\Block\Adminhtml\Grid
  19. */
  20. private $block;
  21. /**
  22. * @inheritDoc
  23. */
  24. protected function setUp()
  25. {
  26. $this->block = Bootstrap::getObjectManager()->get(
  27. \Magento\Reports\Block\Adminhtml\Grid::class
  28. );
  29. }
  30. public function testGetDateFormat()
  31. {
  32. $this->assertNotEmpty($this->block->getDateFormat());
  33. }
  34. /**
  35. * Test apply filtering to collection
  36. *
  37. * @param string $from
  38. * @param string $to
  39. * @param string $period
  40. * @param string $locale
  41. * @param int $expected
  42. * @dataProvider getSalesRepresentativeIdDataProvider
  43. */
  44. public function testGetPreparedCollection($from, $to, $period, $locale, $expected)
  45. {
  46. $encodedFilter = base64_encode('report_from='. $from . '&report_to=' . $to . '&report_period=' . $period);
  47. $this->block->setVarNameFilter('filtername');
  48. /** @var $request RequestInterface */
  49. $request = Bootstrap::getObjectManager()->get(RequestInterface::class);
  50. $request->setParams(['filtername' => $encodedFilter]);
  51. $request->setParams(['locale' => $locale]);
  52. /** @var $localeResolver ResolverInterface */
  53. $localeResolver = Bootstrap::getObjectManager()->get(ResolverInterface::class);
  54. $localeResolver->setLocale();
  55. /** @var $initialCollection Initial */
  56. $initialCollection = Bootstrap::getObjectManager()->create(
  57. Initial::class
  58. );
  59. $this->block->setData(['dataSource' => $initialCollection]);
  60. /** @var $collection Initial */
  61. $collection = $this->block->getPreparedCollection();
  62. $items = $collection->getItems();
  63. $this->assertCount($expected, $items);
  64. }
  65. /**
  66. * Data provider for testGetPreparedCollection method.
  67. *
  68. * @return array
  69. */
  70. public function getSalesRepresentativeIdDataProvider()
  71. {
  72. return [
  73. 'Data for US locale' => ['08/15/2018', '08/20/2018', 'day', 'en_US', 6],
  74. 'Data for Australian locale' => ['15/08/2018', '31/08/2018', 'day', 'en_AU', 17],
  75. 'Data for French locale' => ['20.08.2018', '30.08.2018', 'day', 'fr_FR', 11],
  76. ];
  77. }
  78. }