You are here

function FeedsWebTestBase::downloadExtractSimplePie in Feeds 8.2

Download and extract SimplePIE.

Sets the 'feeds_simplepie_library_dir' variable to the directory where SimplePie is downloaded.

1 call to FeedsWebTestBase::downloadExtractSimplePie()
FeedsMapperFileTest::test in lib/Drupal/feeds/Tests/FeedsMapperFileTest.php
Basic test loading a single entry CSV file.

File

lib/Drupal/feeds/Tests/FeedsWebTestBase.php, line 557
Common functionality for all Feeds tests.

Class

FeedsWebTestBase
Test basic Data API functionality.

Namespace

Drupal\feeds\Tests

Code

function downloadExtractSimplePie($version) {
  $url = "http://simplepie.org/downloads/simplepie_{$version}.mini.php";
  $filename = 'simplepie.mini.php';

  // Avoid downloading the file dozens of times
  $library_dir = DRUPAL_ROOT . '/' . $this->originalFileDirectory . '/simpletest/feeds';
  $simplepie_library_dir = $library_dir . '/simplepie';
  if (!file_exists($library_dir)) {
    drupal_mkdir($library_dir);
  }
  if (!file_exists($simplepie_library_dir)) {
    drupal_mkdir($simplepie_library_dir);
  }

  // Local file name.
  $local_file = $simplepie_library_dir . '/' . $filename;

  // Begin single threaded code.
  if (function_exists('sem_get')) {
    $semaphore = sem_get(ftok(__FILE__, 1));
    sem_acquire($semaphore);
  }

  // Download and extact the archive, but only in one thread.
  if (!file_exists($local_file)) {
    $local_file = system_retrieve_file($url, $local_file, FALSE, FILE_EXISTS_REPLACE);
  }
  if (function_exists('sem_get')) {
    sem_release($semaphore);
  }

  // End single threaded code.
  // Verify that files were successfully extracted.
  $this
    ->assertTrue(file_exists($local_file), t('@file found.', array(
    '@file' => $local_file,
  )));

  // Set the simpletest library directory.
  variable_set('feeds_library_dir', $library_dir);
}