HistoricalReviewDataRefreshTest.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <?php
  2. namespace Dotdigitalgroup\Email\Tests\Integration\Adminhtml\Developer;
  3. class HistoricalReviewDataRefreshTest extends \Magento\TestFramework\TestCase\AbstractBackendController
  4. {
  5. /**
  6. * @var \Magento\Framework\ObjectManagerInterface
  7. */
  8. public $objectManager;
  9. /**
  10. * @var string
  11. */
  12. public $model = \Dotdigitalgroup\Email\Model\Review::class;
  13. /**
  14. * @var string
  15. */
  16. public $url = 'backend/dotdigitalgroup_email/run/reviewsreset';
  17. /**
  18. * @return void
  19. */
  20. public function setUp()
  21. {
  22. parent::setUp();
  23. $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
  24. $this->uri = $this->url;
  25. $this->resource = 'Dotdigitalgroup_Email::config';
  26. $params = [
  27. 'from' => '',
  28. 'to' => ''
  29. ];
  30. $this->getRequest()->setParams($params);
  31. }
  32. /**
  33. * @param string $from
  34. * @param string $to
  35. * @param string $dispatchUrl
  36. * @return void
  37. */
  38. public function runReset($from, $to, $dispatchUrl)
  39. {
  40. $params = [
  41. 'from' => $from,
  42. 'to' => $to
  43. ];
  44. $this->getRequest()->setParams($params);
  45. $this->dispatch($dispatchUrl);
  46. }
  47. /**
  48. * @return void
  49. */
  50. public function testReviewResetSuccessfulGivenDateRange()
  51. {
  52. $this->emptyTable();
  53. $data = [
  54. 'review_id' => '1',
  55. 'customer_id' => '1',
  56. 'store_id' => '1',
  57. 'review_imported' => '1',
  58. 'created_at' => '2017-02-09'
  59. ];
  60. $this->createEmailData($data);
  61. $collection = $this->objectManager->create($this->model)
  62. ->getCollection();
  63. $collection->addFieldToFilter('review_imported', ['null' => true]);
  64. $this->runReset('2017-02-09', '2017-02-10', $this->url);
  65. $this->assertEquals(1, $collection->getSize());
  66. }
  67. /**
  68. * @return void
  69. */
  70. public function testReviewresetNotSuccessfulWrongDateRange()
  71. {
  72. $this->emptyTable();
  73. $data = [
  74. 'review_id' => '1',
  75. 'customer_id' => '1',
  76. 'store_id' => '1',
  77. 'review_imported' => '1',
  78. 'created_at' => '2017-02-09'
  79. ];
  80. $this->createEmailData($data);
  81. $collection = $this->objectManager->create($this->model)
  82. ->getCollection();
  83. $collection->addFieldToFilter('review_imported', ['null' => true]);
  84. $this->runReset('2017-02-09', '2017-01-10', $this->url);
  85. $this->assertSessionMessages(
  86. $this->equalTo(['To Date cannot be earlier then From Date.']),
  87. \Magento\Framework\Message\MessageInterface::TYPE_ERROR
  88. );
  89. $this->assertEquals(0, $collection->getSize());
  90. }
  91. /**
  92. * @return void
  93. */
  94. public function testReviewresetNotSuccessfulInvalidDateRange()
  95. {
  96. $this->emptyTable();
  97. $data = [
  98. 'review_id' => '1',
  99. 'customer_id' => '1',
  100. 'store_id' => '1',
  101. 'review_imported' => '1',
  102. 'created_at' => '2017-02-09'
  103. ];
  104. $this->createEmailData($data);
  105. $collection = $this->objectManager->create($this->model)
  106. ->getCollection();
  107. $collection->addFieldToFilter('review_imported', ['null' => true]);
  108. $this->runReset('2017-02-09', 'not valid', $this->url);
  109. $this->assertSessionMessages(
  110. $this->equalTo(['From or To date is not a valid date.']),
  111. \Magento\Framework\Message\MessageInterface::TYPE_ERROR
  112. );
  113. $this->assertEquals(0, $collection->getSize());
  114. }
  115. /**
  116. * @return void
  117. */
  118. public function testReviewFullResetSuccsesfulWithoutDateRange()
  119. {
  120. $this->emptyTable();
  121. $data = [
  122. [
  123. 'review_id' => '1',
  124. 'customer_id' => '1',
  125. 'store_id' => '1',
  126. 'review_imported' => '1',
  127. 'created_at' => '2017-02-09'
  128. ],
  129. [
  130. 'review_id' => '2',
  131. 'customer_id' => '2',
  132. 'store_id' => '1',
  133. 'review_imported' => '1',
  134. 'created_at' => '2017-02-11'
  135. ]
  136. ];
  137. foreach ($data as $item) {
  138. $this->createEmailData($item);
  139. }
  140. $collection = $this->objectManager->create($this->model)
  141. ->getCollection();
  142. $collection->addFieldToFilter('review_imported', ['null' => true]);
  143. $this->runReset('', '', $this->url);
  144. $this->assertEquals(2, $collection->getSize());
  145. }
  146. /**
  147. * @return void
  148. */
  149. public function testReviewFullResetSuccessWithFromDateOnly()
  150. {
  151. $this->emptyTable();
  152. $data = [
  153. 'review_id' => '1',
  154. 'customer_id' => '1',
  155. 'store_id' => '1',
  156. 'review_imported' => '1',
  157. 'created_at' => '2017-02-09'
  158. ];
  159. $this->createEmailData($data);
  160. $collection = $this->objectManager->create($this->model)
  161. ->getCollection();
  162. $collection->addFieldToFilter('review_imported', ['null' => true]);
  163. $this->runReset('2017-02-10', '', $this->url);
  164. $this->assertEquals(1, $collection->getSize());
  165. }
  166. /**
  167. * @return void
  168. */
  169. public function testReviewFullResetSuccessWithToDateOnly()
  170. {
  171. $this->emptyTable();
  172. $data = [
  173. 'review_id' => '1',
  174. 'customer_id' => '1',
  175. 'store_id' => '1',
  176. 'review_imported' => '1',
  177. 'created_at' => '2017-02-09'
  178. ];
  179. $this->createEmailData($data);
  180. $collection = $this->objectManager->create($this->model)
  181. ->getCollection();
  182. $collection->addFieldToFilter('review_imported', ['null' => true]);
  183. $this->runReset('', '2017-02-10', $this->url);
  184. $this->assertEquals(1, $collection->getSize());
  185. }
  186. /**
  187. * @param array $data
  188. * @return void
  189. */
  190. public function createEmailData($data)
  191. {
  192. $emailModel = $this->objectManager->create($this->model);
  193. $emailModel->addData($data)->save();
  194. }
  195. /**
  196. * @return void
  197. */
  198. public function emptyTable()
  199. {
  200. $resourceModel = $this->objectManager->create(\Dotdigitalgroup\Email\Model\ResourceModel\Review::class);
  201. $resourceModel->getConnection()->truncateTable($resourceModel->getMainTable());
  202. }
  203. }