public function ImagecacheExternalTestCase::testCachingExternalWhitelistValidation in Imagecache External 7.2
Test the behaviour of imagecache_external_validate_host().
File
- ./
imagecache_external.test, line 238 - Tests for Imagecache External.
Class
- ImagecacheExternalTestCase
- Tests the functions for working with public/private file schemes.
Code
public function testCachingExternalWhitelistValidation() {
variable_set('imagecache_external_option', 'white');
// Ensure that special regex characters are properly escaped.
variable_set('imagecache_external_hosts', 'http://drupal.org');
// This fails because the host has a different hostname.
$failed_validation = imagecache_external_validate_host('http://example.org/drupal');
$this
->assertFalse($failed_validation, t('Whitelist validation failed for http://example.org/drupal.'));
// This fails because the whitelist host has a protocol.
$successful_validation = imagecache_external_validate_host('http://drupal.org/drupal');
$this
->assertFalse($successful_validation, t('Whitelist validation failed for http://drupal.org/drupal.'));
// Check that hosts without protocols work for both http and https.
variable_set('imagecache_external_hosts', 'drupal.org');
foreach (array(
'http://drupal.org',
'https://drupal.org',
) as $host) {
$validation = imagecache_external_validate_host($host);
$this
->assertTrue($validation, t('Whitelist validation passed for @host.', array(
'@host' => $host,
)));
}
// Check that the matching doesn't exhibit regex-like behaviour.
$regex_validation = imagecache_external_validate_host('http://drupallorg.org');
$this
->assertFalse($regex_validation, t('Whitelist validation failed for http://drupallorg.org.'));
}