public function FeedsWebTestCase::downloadExtractSimplePie in Feeds 7.2
Download and extract SimplePIE.
Sets the 'feeds_simplepie_library_dir' variable to the directory where SimplePie is downloaded.
2 calls to FeedsWebTestCase::downloadExtractSimplePie()
- FeedsMapperFileTestCase::requireSimplePie in tests/
feeds_mapper_file.test - Checks if SimplePie is available and eventually downloads it.
- FeedsSyndicationParserTestCase::test in tests/
feeds_parser_syndication.test - Run tests.
File
- tests/
feeds.test, line 717 - Common functionality for all Feeds tests.
Class
- FeedsWebTestCase
- Test basic Data API functionality.
Code
public function downloadExtractSimplePie($version) {
$url = "https://codeload.github.com/simplepie/simplepie/zip/{$version}";
// 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);
}
// Local file name.
$local_file = $library_dir . '/simplepie/library/SimplePie.php';
$zip_file = $library_dir . '/simplepie.zip';
// Begin single threaded code.
if (function_exists('sem_get')) {
$semaphore = sem_get(ftok(__FILE__, 1));
sem_acquire($semaphore);
}
// Download the archive, but only in one thread.
if (!file_exists($local_file)) {
if (!file_exists($zip_file)) {
$zip_file = system_retrieve_file($url, $zip_file, FALSE, FILE_EXISTS_REPLACE);
}
// Extract the archive.
$zip = new ZipArchive();
if ($zip
->open($zip_file) === TRUE) {
$zip
->extractTo($library_dir);
$zip
->close();
}
// Rename directory.
rename($library_dir . '/simplepie-' . $version, $simplepie_library_dir);
}
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);
}