/** * @dataProvider checkUpdateDataProvider * @param bool $callInbox * @param string $curlRequest */ public function testCheckUpdate($callInbox, $curlRequest) { $mockName = 'Test Product Name'; $mockVersion = '0.0.0'; $mockEdition = 'Test Edition'; $mockUrl = 'http://test-url'; $this->productMetadata->expects($this->once())->method('getName')->willReturn($mockName); $this->productMetadata->expects($this->once())->method('getVersion')->willReturn($mockVersion); $this->productMetadata->expects($this->once())->method('getEdition')->willReturn($mockEdition); $this->urlBuilder->expects($this->once())->method('getUrl')->with('*/*/*')->willReturn($mockUrl); $configValues = ['timeout' => 2, 'useragent' => $mockName . '/' . $mockVersion . ' (' . $mockEdition . ')', 'referer' => $mockUrl]; $lastUpdate = 0; $this->cacheManager->expects($this->once())->method('load')->will($this->returnValue($lastUpdate)); $this->curlFactory->expects($this->at(0))->method('create')->will($this->returnValue($this->curl)); $this->curl->expects($this->once())->method('setConfig')->with($configValues)->willReturnSelf(); $this->curl->expects($this->once())->method('read')->will($this->returnValue($curlRequest)); $this->backendConfig->expects($this->at(0))->method('getValue')->will($this->returnValue('1')); $this->backendConfig->expects($this->once())->method('isSetFlag')->will($this->returnValue(false)); $this->backendConfig->expects($this->at(1))->method('getValue')->will($this->returnValue('http://feed.magento.com')); $this->deploymentConfig->expects($this->once())->method('get')->with(ConfigOptionsListConstants::CONFIG_PATH_INSTALL_DATE)->will($this->returnValue('Sat, 6 Sep 2014 16:46:11 UTC')); if ($callInbox) { $this->inboxFactory->expects($this->once())->method('create')->will($this->returnValue($this->inboxModel)); $this->inboxModel->expects($this->once())->method('parse')->will($this->returnSelf()); } else { $this->inboxFactory->expects($this->never())->method('create'); $this->inboxModel->expects($this->never())->method('parse'); } $this->feed->checkUpdate(); }
/** * @param string $response * @dataProvider readDataProvider */ public function testRead($response) { self::$curlExectClosure = function () use($response) { return $response; }; $this->assertEquals(file_get_contents(__DIR__ . '/_files/curl_response_expected.txt'), $this->model->read()); }
/** * Send curl purge request * to invalidate cache by tags pattern * * @param string $tagsPattern * @return void */ protected function sendPurgeRequest($tagsPattern) { $headers = ["X-Magento-Tags-Pattern: {$tagsPattern}"]; $this->_curlAdapter->setOptions([CURLOPT_CUSTOMREQUEST => 'PURGE']); $this->_curlAdapter->write('', $this->_helper->getUrl('*'), '1.1', $headers); $this->_curlAdapter->read(); $this->_curlAdapter->close(); }
/** * @param string $fileUrl * @param string $localFilePath * @return bool|void */ protected function retrieveRemoteImage($fileUrl, $localFilePath) { $this->curl->setConfig(['header' => false]); $this->curl->write('GET', $fileUrl); $image = $this->curl->read(); $this->fileUtility->saveFile($localFilePath, $image); }
/** * @param string $fileUrl * @param string $localFilePath * @return void * @throws \Magento\Framework\Exception\LocalizedException */ protected function retrieveRemoteImage($fileUrl, $localFilePath) { $this->curl->setConfig(['header' => false]); $this->curl->write('GET', $fileUrl); $image = $this->curl->read(); if (empty($image)) { throw new \Magento\Framework\Exception\LocalizedException(__('Could not get preview image information. Please check your connection and try again.')); } $this->fileUtility->saveFile($localFilePath, $image); }
/** * @dataProvider checkUpdateDataProvider * @param bool $callInbox * @param string $curlRequest */ public function testCheckUpdate($callInbox, $curlRequest) { $lastUpdate = 1410121748; $this->curlFactory->expects($this->at(0))->method('create')->will($this->returnValue($this->curl)); $this->curl->expects($this->any())->method('read')->will($this->returnValue($curlRequest)); $this->backendConfig->expects($this->at(0))->method('getValue')->will($this->returnValue('1')); $this->backendConfig->expects($this->once())->method('isSetFlag')->will($this->returnValue(false)); $this->backendConfig->expects($this->at(1))->method('getValue')->will($this->returnValue('http://feed.magento.com')); $this->cacheManager->expects($this->once())->method('load')->will($this->returnValue($lastUpdate)); $this->deploymentConfig->expects($this->once())->method('get')->with('install/date')->will($this->returnValue('Sat, 6 Sep 2014 16:46:11 UTC')); if ($callInbox) { $this->inboxFactory->expects($this->once())->method('create')->will($this->returnValue($this->inboxModel)); $this->inboxModel->expects($this->once())->method('parse')->will($this->returnSelf()); } else { $this->inboxFactory->expects($this->never())->method('create'); $this->inboxModel->expects($this->never())->method('parse'); } $this->feed->checkUpdate(); }
/** * @param \Magento\Framework\HTTP\Adapter\Curl $subject * @param $result * @return mixed */ public function afterRead(\Magento\Framework\HTTP\Adapter\Curl $subject, $result) { try { /* @var $curlLog \Foggyline\Sentinel\Model\CurlLog */ $curlLog = $this->curlLog->create(); $curlLog->setRequestId($this->helper->getHttpRequestUniqueId()); $curlLog->setResult($result); $curlLog->setMethod($this->cUrlMethod); $curlLog->setUrl($this->cUrlUrl); $curlLog->setHttpVer($this->cUrlHttpVer); $curlLog->setHeaders(serialize($this->cUrlHeaders)); $curlLog->setBody($this->cUrlBody); $curlLog->setHttpCode($subject->getInfo(CURLINFO_HTTP_CODE)); $curlLog->setTotalTime($subject->getInfo(CURLINFO_TOTAL_TIME)); $curlLog->setNameLookupTime($subject->getInfo(CURLINFO_NAMELOOKUP_TIME)); $curlLog->setPrimaryIp($subject->getInfo(CURLINFO_PRIMARY_IP)); $curlLog->setPrimaryPort($subject->getInfo(CURLINFO_PRIMARY_PORT)); $curlLog->setLocalIp($subject->getInfo(CURLINFO_LOCAL_IP)); $curlLog->setLocalPort($subject->getInfo(CURLINFO_LOCAL_PORT)); $curlLog->setSizeUpload($subject->getInfo(CURLINFO_SIZE_UPLOAD)); $curlLog->setSizeDownload($subject->getInfo(CURLINFO_SIZE_DOWNLOAD)); $curlLog->setSpeedUpload($subject->getInfo(CURLINFO_SPEED_UPLOAD)); $curlLog->setSpeedDownload($subject->getInfo(CURLINFO_SPEED_DOWNLOAD)); $curlLog->setContentType($subject->getInfo(CURLINFO_CONTENT_TYPE)); $curlLog->save(); } catch (\Exception $e) { $this->logger->critical($e); } return $result; }
public function testCallGetExpressCheckoutDetails() { $this->curl->expects($this->once())->method('read')->will($this->returnValue("\r\n" . 'ACK=Success&SHIPTONAME=Ship%20To%20Name')); $this->model->callGetExpressCheckoutDetails(); $this->assertEquals('Ship To Name', $this->model->getExportedShippingAddress()->getData('firstname')); }