public function testExecuteWithException()
 {
     $this->flag->expects($this->once())->method('lock')->will($this->throwException(new \Exception('Test exception')));
     $logger = $this->getMockBuilder('Magento\\Framework\\Logger')->setMethods(array('logException'))->disableOriginalConstructor()->getMock();
     $this->controllerArguments['context']->getObjectManager()->expects($this->at(2))->method('get')->with('Magento\\Framework\\Logger')->will($this->returnValue($logger));
     $this->controller->execute();
 }
示例#2
0
 public function testExecuteWithException()
 {
     $this->flag->expects($this->once())->method('lock')->will($this->throwException(new \Exception('Test exception')));
     $logger = $this->getMockBuilder('Psr\\Log\\LoggerInterface')->getMock();
     $this->controllerArguments['context']->getObjectManager()->expects($this->at(2))->method('get')->with('Psr\\Log\\LoggerInterface')->will($this->returnValue($logger));
     $this->controller->execute();
 }
示例#3
0
 public function testCheckSynchronizationOperations()
 {
     $this->flag->expects($this->once())->method('loadSelf')->will($this->returnSelf());
     $this->flag->expects($this->once())->method('isExpired')->will($this->returnValue(true));
     $observer = $this->objectManagerHelper->getObject('Magento\\Framework\\Event\\Observer');
     $this->notificationInterface->expects($this->once())->method('addMajor')->with('Google Shopping operation has expired.', 'One or more google shopping synchronization operations failed because of timeout.')->will($this->returnSelf());
     $this->observer->checkSynchronizationOperations($observer);
 }
 /**
  * @param string $exception
  * @return void
  * @dataProvider dataAddProductsExceptions
  */
 public function testAddProductsExceptions($exception)
 {
     $products = ['1'];
     $this->flag->expects($this->any())->method('isExpired')->will($this->returnValue(false));
     $product = $this->getMock('\\Magento\\Catalog\\Model\\Product', [], [], '', false);
     $this->productRepository->expects($this->once())->method('getById')->will($this->returnValue($product));
     $this->itemFactory->expects($this->once())->method('create')->willThrowException(new $exception(__('message')));
     $this->massOperations->setFlag($this->flag);
     $this->massOperations->addProducts($products, 1);
 }
示例#5
0
 /**
  * Check if synchronize process is finished and generate notification message
  *
  * @param  \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function checkSynchronizationOperations(\Magento\Framework\Event\Observer $observer)
 {
     $this->_flag->loadSelf();
     if ($this->_flag->isExpired()) {
         $this->_notifier->addMajor(__('Google Shopping operation has expired.'), __('One or more google shopping synchronization operations failed because of timeout.'));
         $this->_flag->unlock();
     }
     return $this;
 }
示例#6
0
 /**
  * Remove Google Content items.
  *
  * @param int[]|ItemCollection $items
  * @return $this
  * @throws \Exception|\Zend_Gdata_App_CaptchaRequiredException
  */
 public function deleteItems($items)
 {
     $totalDeleted = 0;
     $itemsCollection = $this->_getItemsCollection($items);
     $errors = array();
     if ($itemsCollection) {
         if (count($itemsCollection) < 1) {
             return $this;
         }
         foreach ($itemsCollection as $item) {
             if ($this->_flag && $this->_flag->isExpired()) {
                 break;
             }
             try {
                 $item->deleteItem()->delete();
                 // The item was removed successfully
                 $totalDeleted++;
             } catch (\Zend_Gdata_App_CaptchaRequiredException $e) {
                 throw $e;
             } catch (\Zend_Gdata_App_Exception $e) {
                 $this->_addGeneralError();
                 $errors[] = $this->_gleShoppingData->parseGdataExceptionMessage($e->getMessage(), $item->getProduct());
             } catch (\Exception $e) {
                 $this->_logger->logException($e);
                 $errors[] = __('The item "%1" hasn\'t been deleted.', $item->getProduct()->getName());
             }
         }
     } else {
         return $this;
     }
     if ($totalDeleted > 0) {
         $this->_getNotifier()->addNotice(__('Google Shopping item removal process succeded'), __('Total of %1 items(s) have been removed from Google Shopping.', $totalDeleted));
     }
     if (count($errors)) {
         $this->_getNotifier()->addMajor(__('Errors happened while deleting items from Google Shopping'), $errors);
     }
     return $this;
 }
示例#7
0
 /**
  * Remove Google Content items.
  *
  * @param int[]|ItemCollection $items
  * @return $this
  * @throws \Exception|\Zend_Gdata_App_CaptchaRequiredException
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function deleteItems($items)
 {
     $totalDeleted = 0;
     $itemsCollection = $this->_getItemsCollection($items);
     $errors = [];
     if ($itemsCollection) {
         if (count($itemsCollection) < 1) {
             return $this;
         }
         foreach ($itemsCollection as $item) {
             if ($this->_flag && $this->_flag->isExpired()) {
                 break;
             }
             try {
                 $item->deleteItem()->delete();
                 // The item was removed successfully
                 $totalDeleted++;
             } catch (\Zend_Gdata_App_CaptchaRequiredException $e) {
                 throw $e;
             } catch (\Zend_Gdata_App_Exception $e) {
                 $this->_addGeneralError();
                 $errors[] = $this->_gleShoppingData->parseGdataExceptionMessage($e->getMessage(), $item->getProduct());
             } catch (\Exception $e) {
                 $this->_logger->critical($e);
                 $errors[] = __('We can\'t update item "%1" right now.', $item->getProduct()->getName());
             }
         }
     } else {
         return $this;
     }
     if ($totalDeleted > 0) {
         $this->_notifier->addNotice(__('The Google Shopping item removal process succeeded.'), __('You removed %1 items(s) from Google Shopping.', $totalDeleted));
     }
     if (count($errors)) {
         $this->_notifier->addMajor(__('Something went wrong while deleting items from Google Shopping.'), $errors);
     }
     return $this;
 }