/**
  * Tests if shop validation works.
  */
 public function testIsShopValid()
 {
     $this->assertFalse($this->service->isShopValid(null));
     $this->assertFalse($this->service->isShopValid('invalid_id'));
     $this->assertTrue($this->service->isShopValid(1));
     $default = $this->service->getActiveShopId();
     $this->assertTrue($this->service->isShopValid($default));
 }
 /**
  * Sets last_sync_date in bin log format or sets last_sync_position.
  *
  * @param \DateTime|int $from
  * @param int           $startType
  */
 private function setLastSync($from, $startType)
 {
     /** @var PairStorage $pairStorage */
     $pairStorage = $this->getServiceContainer()->get('ongr_connections.pair_storage');
     if ($startType == BinlogParser::START_TYPE_DATE) {
         // Sometimes, mysql, php and server timezone could differ, we need convert time seen by php
         // to the same time in the same timezone as is used in mysqlbinlog.
         // This issue is for tests only, should not affect live website.
         $result = $this->managerMysql->getConnection()->executeQuery('SELECT @@global.time_zone');
         $time_zone = $result->fetchAll()[0]['@@global.time_zone'];
         // If mysql timezone is the same as systems, string 'SYSTEM' is returned, which is not what we want.
         if ($time_zone == 'SYSTEM') {
             $result = $this->managerMysql->getConnection()->executeQuery('SELECT @@system_time_zone');
             $time_zone = $result->fetchAll()[0]['@@system_time_zone'];
         }
         $from->setTimezone(new \DateTimeZone($time_zone));
         $pairStorage->set(BinlogDiffProvider::LAST_SYNC_DATE_PARAM, $from->format('Y-m-d H:i:s'));
     } elseif ($startType == BinlogParser::START_TYPE_POSITION) {
         $pairStorage->set(BinlogDiffProvider::LAST_SYNC_POSITION_PARAM, $from);
     }
 }
 /**
  * Test if extract is able to add data to the storage for item delete action.
  */
 public function testExtractForDeleteItem()
 {
     $category = 'product';
     $id = 123;
     $timestamp = new DateTime('-1 hour 20 minutes');
     $deleteDiffItem = new DeleteDiffItem();
     $deleteDiffItem->setCategory($category);
     $deleteDiffItem->setItemId($id);
     $deleteDiffItem->setTimestamp($timestamp);
     $this->extractor->extract($deleteDiffItem);
     foreach ($this->shopIds as $shopId) {
         $actual = (object) $this->getConnection()->fetchAssoc('SELECT * FROM ' . $this->storageManager->getTableName($shopId) . ' WHERE
                 `type` = :operationType
                 AND `document_type` = :documentType
                 AND `document_id` = :documentId
                 AND `status` = :status', ['operationType' => ActionTypes::DELETE, 'documentType' => $category, 'documentId' => $id, 'status' => 0]);
         $this->assertTrue(!empty($actual->id));
         $this->assertEquals(ActionTypes::DELETE, $actual->type);
         $this->assertEquals($category, $actual->document_type);
         $this->assertEquals($id, $actual->document_id);
         $this->assertEquals($timestamp, new DateTime($actual->timestamp));
     }
 }
 /**
  * Test possible SQL injection in shop id.
  */
 public function testInvalidShopId()
 {
     $id = '\';inject';
     $this->setExpectedException('InvalidArgumentException', "Shop id \"{$id}\" is invalid.");
     $this->service->getTableName($id);
 }