function CasTestHelper::downloadExtractPhpCas in CAS 6.3
Same name and namespace in other branches
- 7 cas.test \CasTestHelper::downloadExtractPhpCas()
Download and extract phpCAS.
Sets the 'cas_library_dir' variable to the directory where phpCAS is downloaded.
Parameters
$version: The phpCAS version number to download and extract.
1 call to CasTestHelper::downloadExtractPhpCas()
- CasTestHelper::setUp in ./
cas.test - Helper class for CAS tests.
File
- ./
cas.test, line 50 - Tests for cas.module.
Class
- CasTestHelper
- @file Tests for cas.module.
Code
function downloadExtractPhpCas($version) {
// Find the most URL of the most recent phpCAS version.
$directory = 'CAS-' . $version;
$filename = 'CAS-' . $version . '.tgz';
$url = 'http://downloads.jasig.org/cas-clients/php/' . $version . '/' . $filename;
// Avoid downloading the file dozens of times
$simpletest_cache = $this->originalFileDirectory . '/simpletest/cas';
if (!file_exists($simpletest_cache)) {
mkdir($simpletest_cache);
}
// Local archive name.
$local_archive = $simpletest_cache . '/' . $filename;
$cas_library_dir = $simpletest_cache . '/' . $directory;
// 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_archive)) {
$result = drupal_http_request($url);
file_put_contents($local_archive, $result->data);
}
if (!file_exists($cas_library_dir)) {
// Get Archive_Tar. @see http://drupal.org/node/1113618.
$archive_tar = $simpletest_cache . '/archive_tar.inc';
$result = drupal_http_request('http://drupal.org/files/issues/system.tar_.inc_.txt');
file_put_contents($archive_tar, $result->data);
include_once $archive_tar;
// Extract the files.
$archiver = new Archive_Tar($local_archive);
$archiver
->extract($simpletest_cache);
}
if (function_exists('sem_get')) {
sem_release($semaphore);
}
// End single threaded code.
// Verify that files were successfully extracted.
$this
->assertTrue(file_exists($cas_library_dir . '/CAS.php'), t('CAS.php found in @cas_library_dir.', array(
'@cas_library_dir' => $cas_library_dir,
)));
// Set the CAS library directory.
variable_set('cas_library_dir', $cas_library_dir);
}