1 system.test | CustomLogoTestCase::testCustomLogo() |
Test the use of a custom logo.
File
- core/
modules/ system/ tests/ system.test, line 1075 - Tests for system.module.
Class
Code
function testCustomLogo() {
$file_public_path = config_get('system.core', 'file_public_path');
// Specify a filesystem path to be used for the logo.
$file = current($this->backdropGetTestFiles('image'));
$file_relative = strtr($file->uri, array('public://' => $file_public_path . '/'));
$default_theme_path = 'core/themes/stark';
$supported_paths = array(
// Raw stream wrapper URI.
$file->uri => array(
'form' => file_uri_target($file->uri),
'src' => file_create_url($file->uri),
),
// Relative path within the public filesystem.
file_uri_target($file->uri) => array(
'form' => file_uri_target($file->uri),
'src' => file_create_url($file->uri),
),
// Relative path to a public file.
$file_relative => array(
'form' => $file_relative,
'src' => file_create_url($file->uri),
),
// Relative path to an arbitrary file.
'core/misc/feed.png' => array(
'form' => 'core/misc/feed.png',
'src' => $GLOBALS['base_url'] . '/core/misc/feed.png',
),
// Relative path to a file in a theme.
$default_theme_path . '/screenshot.png' => array(
'form' => $default_theme_path . '/screenshot.png',
'src' => $GLOBALS['base_url'] . '/' . $default_theme_path . '/screenshot.png',
),
);
foreach ($supported_paths as $input => $expected) {
$edit = array(
'site_logo_theme' => FALSE,
'site_logo_path' => $input,
);
$this->backdropPost('admin/config/system/site-information', $edit, t('Save configuration'));
$this->assertNoText('The custom logo path is invalid.');
$this->assertFieldByName('site_logo_path', $expected['form']);
// Verify logo path examples.
$elements = $this->xpath('//div[contains(@class, :item)]/div[@class=:description]/code', array(
':item' => 'form-item-site-logo-path',
':description' => 'description',
));
// Expected default values (if all else fails).
$implicit_public_file = 'logo.png';
$explicit_file = 'public://logo.png';
$local_file = $default_theme_path . '/logo.png';
// Adjust for fully qualified stream wrapper URI in public filesystem.
if (file_uri_scheme($input) == 'public') {
$implicit_public_file = file_uri_target($input);
$explicit_file = $input;
$local_file = strtr($input, array('public://' => $file_public_path . '/'));
}
// Adjust for fully qualified stream wrapper URI elsewhere.
elseif (file_uri_scheme($input) !== FALSE) {
$explicit_file = $input;
}
// Adjust for relative path within public filesystem.
elseif ($input == file_uri_target($file->uri)) {
$implicit_public_file = $input;
$explicit_file = 'public://' . $input;
$local_file = $file_public_path . '/' . $input;
}
$this->assertEqual((string) $elements[0], $implicit_public_file);
$this->assertEqual((string) $elements[1], $explicit_file);
$this->assertEqual((string) $elements[2], $local_file);
// Verify the actual 'src' attribute of the logo being output.
$this->backdropGet('');
$elements = $this->xpath('//header//a[@rel=:rel]/img', array(
':rel' => 'home',
)
);
$this->assertEqual((string) $elements[0]['src'], $expected['src']);
}
$unsupported_paths = array(
// Stream wrapper URI to non-existing file.
'public://whatever.png',
'private://whatever.png',
'temporary://whatever.png',
// Bogus stream wrapper URIs.
'public:/whatever.png',
'://whatever.png',
':whatever.png',
'public://',
// Relative path within the public filesystem to non-existing file.
'whatever.png',
// Relative path to non-existing file in public filesystem.
$file_public_path . '/whatever.png',
// Semi-absolute path to non-existing file in public filesystem.
'/' . $file_public_path . '/whatever.png',
// Relative path to arbitrary non-existing file.
'core/misc/whatever.png',
// Semi-absolute path to arbitrary non-existing file.
'/core/misc/whatever.png',
// Absolute paths to any local file (even if it exists).
backdrop_realpath($file->uri),
);
$this->backdropGet('admin/config/system/site-information');
foreach ($unsupported_paths as $path) {
$edit = array(
'site_logo_theme' => FALSE,
'site_logo_path' => $path,
);
$this->backdropPost(NULL, $edit, t('Save configuration'));
$this->assertText('The custom logo path is invalid.');
}
// Upload a file to use for the logo.
$edit = array(
'site_logo_theme' => FALSE,
'site_logo_path' => '',
'files[site_logo_upload]' => backdrop_realpath($file->uri),
);
$this->backdropPost('admin/config/system/site-information', $edit, t('Save configuration'));
$fields = $this->xpath($this->constructFieldXpath('name', 'site_logo_path'));
$uploaded_filename = 'public://' . $fields[0]['value'];
$this->backdropGet('');
$elements = $this->xpath('//header//a[@rel=:rel]/img', array(
':rel' => 'home',
)
);
$this->assertEqual($elements[0]['src'], file_create_url($uploaded_filename));
}