Exemple #1
0
 /**
  * Get the origin image path, if is a remote image, will store in temp dir first.
  *
  * @param   string $url  The image URL.
  * @param   string $hash Not available now..
  *
  * @return  string  Image path.
  */
 public function getImagePath($url, $hash = null)
 {
     $self = \JUri::getInstance();
     $url = new \JUri($url);
     // Is same host?
     if ($self->getHost() == $url->getHost()) {
         $url = $url->toString();
         $path = str_replace(\JURI::root(), JPATH_ROOT . '/', $url);
         $path = \JPath::clean($path);
     } elseif (!$url->getHost()) {
         $url = $url->toString();
         $path = \JPath::clean(JPATH_ROOT . '/' . $url);
     } else {
         $handler = $this->hashHandler;
         $path = $this->config['path.temp'] . '/' . $handler(basename($url)) . '.jpg';
         if (!is_file($path)) {
             CurlHelper::download((string) $url, $path);
         }
     }
     return $path;
 }
 /**
  * Method to test download().
  *
  * @return void
  *
  * @covers Windwalker\Helper\CurlHelper::download
  */
 public function testDownload()
 {
     ini_set('allow_url_fopen', true);
     // We use static file README.md as our test file.
     $fileName = 'README.md';
     $testFileName = 'test' . $fileName;
     $filePath = __DIR__ . '/../../' . $fileName;
     $testFilePath = __DIR__ . '/../../' . $testFileName;
     $filePath = str_replace('\\', '/', $filePath);
     // Read file on local
     $oriFileContent = file_get_contents($filePath);
     // Download file by CurlHelper
     $success = CurlHelper::download('file://' . $filePath, $testFileName);
     if (!isset($success->errorCode)) {
         // Read the downloaded file
         $downloadFileContent = file_get_contents($fileName);
         // Assert two file
         $this->assertEquals($oriFileContent, $downloadFileContent);
         // Remove temporary downloaded file.
         unlink($testFilePath);
     } else {
         $this->fail(sprintf('Download: %s fail', $filePath));
     }
 }