HelperTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Reports\Test\Unit\Model\ResourceModel;
  7. use Magento\Reports\Model\ResourceModel\Helper;
  8. class HelperTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @var \Magento\Reports\Model\ResourceModel\Helper
  12. */
  13. protected $helper;
  14. /**
  15. * @var \Magento\Framework\App\ResourceConnection|\PHPUnit_Framework_MockObject_MockObject
  16. */
  17. protected $resourceMock;
  18. /**
  19. * @var \Magento\Framework\DB\Adapter\AdapterInterface|\PHPUnit_Framework_MockObject_MockObject
  20. */
  21. protected $connectionMock;
  22. /**
  23. * {@inheritDoc}
  24. */
  25. protected function setUp()
  26. {
  27. $this->resourceMock = $this->getMockBuilder(\Magento\Framework\App\ResourceConnection::class)
  28. ->disableOriginalConstructor()
  29. ->getMock();
  30. $this->connectionMock = $this->getMockBuilder(\Magento\Framework\DB\Adapter\AdapterInterface::class)
  31. ->getMock();
  32. $this->resourceMock
  33. ->expects($this->any())
  34. ->method('getConnection')
  35. ->willReturn($this->connectionMock);
  36. $this->helper = new Helper(
  37. $this->resourceMock
  38. );
  39. }
  40. /**
  41. * @return void
  42. */
  43. public function testMergeVisitorProductIndex()
  44. {
  45. $mainTable = 'mainTable';
  46. $data = ['dataKey' => 'dataValue'];
  47. $matchFields = ['matchField'];
  48. $this->connectionMock
  49. ->expects($this->once())
  50. ->method('insertOnDuplicate')
  51. ->with($mainTable, $data, array_keys($data));
  52. $this->helper->mergeVisitorProductIndex($mainTable, $data, $matchFields);
  53. }
  54. /**
  55. * @param string $type
  56. * @param array $result
  57. * @dataProvider typesDataProvider
  58. * @return void
  59. */
  60. public function testUpdateReportRatingPos($type, $result)
  61. {
  62. $mainTable = 'mainTable';
  63. $column = 'column';
  64. $aggregationTable = 'aggregationTable';
  65. $selectMock = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
  66. ->disableOriginalConstructor()
  67. ->getMock();
  68. $selectMock
  69. ->expects($this->any())
  70. ->method('from')
  71. ->willReturnSelf();
  72. $selectMock
  73. ->expects($this->once())
  74. ->method('group')
  75. ->willReturnSelf();
  76. $selectMock
  77. ->expects($this->once())
  78. ->method('order')
  79. ->willReturnSelf();
  80. $selectMock
  81. ->expects($this->once())
  82. ->method('insertFromSelect')
  83. ->with($aggregationTable, $result)
  84. ->willReturnSelf();
  85. $this->connectionMock
  86. ->expects($this->any())
  87. ->method('select')
  88. ->willReturn($selectMock);
  89. $this->helper->updateReportRatingPos($this->connectionMock, $type, $column, $mainTable, $aggregationTable);
  90. }
  91. /**
  92. * @return array
  93. */
  94. public function typesDataProvider()
  95. {
  96. $mResult = ['period', 'store_id', 'product_id', 'product_name', 'product_price', 'column', 'rating_pos'];
  97. $dResult = ['period', 'store_id', 'product_id', 'product_name', 'product_price', 'id', 'column', 'rating_pos'];
  98. return [
  99. ['type' => 'year', 'result' => $mResult],
  100. ['type' => 'month', 'result' => $mResult],
  101. ['type' => 'day', 'result' => $dResult],
  102. ['type' => null, 'result' => $mResult]
  103. ];
  104. }
  105. }