function CasTestHelper::downloadExtractPhpCas in CAS 7
Same name and namespace in other branches
- 6.3 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 53 - 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 = 'https://developer.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)) {
$local_archive = system_retrieve_file($url, $local_archive, FALSE, FILE_EXISTS_REPLACE);
}
if (!file_exists($cas_library_dir)) {
// Extract the files.
$archiver = archiver_get_archiver($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);
}