123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- <?php
- namespace Dotdigitalgroup\Email\Tests\Integration\Adminhtml\Developer;
- class HistoricalReviewDataRefreshTest extends \Magento\TestFramework\TestCase\AbstractBackendController
- {
- /**
- * @var \Magento\Framework\ObjectManagerInterface
- */
- public $objectManager;
- /**
- * @var string
- */
- public $model = \Dotdigitalgroup\Email\Model\Review::class;
- /**
- * @var string
- */
- public $url = 'backend/dotdigitalgroup_email/run/reviewsreset';
- /**
- * @return void
- */
- public function setUp()
- {
- parent::setUp();
- $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
- $this->uri = $this->url;
- $this->resource = 'Dotdigitalgroup_Email::config';
- $params = [
- 'from' => '',
- 'to' => ''
- ];
- $this->getRequest()->setParams($params);
- }
- /**
- * @param string $from
- * @param string $to
- * @param string $dispatchUrl
- * @return void
- */
- public function runReset($from, $to, $dispatchUrl)
- {
- $params = [
- 'from' => $from,
- 'to' => $to
- ];
- $this->getRequest()->setParams($params);
- $this->dispatch($dispatchUrl);
- }
- /**
- * @return void
- */
- public function testReviewResetSuccessfulGivenDateRange()
- {
- $this->emptyTable();
- $data = [
- 'review_id' => '1',
- 'customer_id' => '1',
- 'store_id' => '1',
- 'review_imported' => '1',
- 'created_at' => '2017-02-09'
- ];
- $this->createEmailData($data);
- $collection = $this->objectManager->create($this->model)
- ->getCollection();
- $collection->addFieldToFilter('review_imported', ['null' => true]);
- $this->runReset('2017-02-09', '2017-02-10', $this->url);
- $this->assertEquals(1, $collection->getSize());
- }
- /**
- * @return void
- */
- public function testReviewresetNotSuccessfulWrongDateRange()
- {
- $this->emptyTable();
- $data = [
- 'review_id' => '1',
- 'customer_id' => '1',
- 'store_id' => '1',
- 'review_imported' => '1',
- 'created_at' => '2017-02-09'
- ];
- $this->createEmailData($data);
- $collection = $this->objectManager->create($this->model)
- ->getCollection();
- $collection->addFieldToFilter('review_imported', ['null' => true]);
- $this->runReset('2017-02-09', '2017-01-10', $this->url);
- $this->assertSessionMessages(
- $this->equalTo(['To Date cannot be earlier then From Date.']),
- \Magento\Framework\Message\MessageInterface::TYPE_ERROR
- );
- $this->assertEquals(0, $collection->getSize());
- }
- /**
- * @return void
- */
- public function testReviewresetNotSuccessfulInvalidDateRange()
- {
- $this->emptyTable();
- $data = [
- 'review_id' => '1',
- 'customer_id' => '1',
- 'store_id' => '1',
- 'review_imported' => '1',
- 'created_at' => '2017-02-09'
- ];
- $this->createEmailData($data);
- $collection = $this->objectManager->create($this->model)
- ->getCollection();
- $collection->addFieldToFilter('review_imported', ['null' => true]);
- $this->runReset('2017-02-09', 'not valid', $this->url);
- $this->assertSessionMessages(
- $this->equalTo(['From or To date is not a valid date.']),
- \Magento\Framework\Message\MessageInterface::TYPE_ERROR
- );
- $this->assertEquals(0, $collection->getSize());
- }
- /**
- * @return void
- */
- public function testReviewFullResetSuccsesfulWithoutDateRange()
- {
- $this->emptyTable();
- $data = [
- [
- 'review_id' => '1',
- 'customer_id' => '1',
- 'store_id' => '1',
- 'review_imported' => '1',
- 'created_at' => '2017-02-09'
- ],
- [
- 'review_id' => '2',
- 'customer_id' => '2',
- 'store_id' => '1',
- 'review_imported' => '1',
- 'created_at' => '2017-02-11'
- ]
- ];
- foreach ($data as $item) {
- $this->createEmailData($item);
- }
- $collection = $this->objectManager->create($this->model)
- ->getCollection();
- $collection->addFieldToFilter('review_imported', ['null' => true]);
- $this->runReset('', '', $this->url);
- $this->assertEquals(2, $collection->getSize());
- }
- /**
- * @return void
- */
- public function testReviewFullResetSuccessWithFromDateOnly()
- {
- $this->emptyTable();
- $data = [
- 'review_id' => '1',
- 'customer_id' => '1',
- 'store_id' => '1',
- 'review_imported' => '1',
- 'created_at' => '2017-02-09'
- ];
- $this->createEmailData($data);
- $collection = $this->objectManager->create($this->model)
- ->getCollection();
- $collection->addFieldToFilter('review_imported', ['null' => true]);
- $this->runReset('2017-02-10', '', $this->url);
- $this->assertEquals(1, $collection->getSize());
- }
- /**
- * @return void
- */
- public function testReviewFullResetSuccessWithToDateOnly()
- {
- $this->emptyTable();
- $data = [
- 'review_id' => '1',
- 'customer_id' => '1',
- 'store_id' => '1',
- 'review_imported' => '1',
- 'created_at' => '2017-02-09'
- ];
- $this->createEmailData($data);
- $collection = $this->objectManager->create($this->model)
- ->getCollection();
- $collection->addFieldToFilter('review_imported', ['null' => true]);
- $this->runReset('', '2017-02-10', $this->url);
- $this->assertEquals(1, $collection->getSize());
- }
- /**
- * @param array $data
- * @return void
- */
- public function createEmailData($data)
- {
- $emailModel = $this->objectManager->create($this->model);
- $emailModel->addData($data)->save();
- }
- /**
- * @return void
- */
- public function emptyTable()
- {
- $resourceModel = $this->objectManager->create(\Dotdigitalgroup\Email\Model\ResourceModel\Review::class);
- $resourceModel->getConnection()->truncateTable($resourceModel->getMainTable());
- }
- }
|