class ImageCacheUrlTests in ImageCache 5.2
Same name and namespace in other branches
- 6.2 tests/imagecache_create_url.test \ImageCacheUrlTests
Test class for testing imagecache_create_url() in several use cases with the different combinations of clean URLs and private/public download method.
Hierarchy
- class \DrupalTestCase extends \WebTestCase
- class \ImageCacheUrlTests
Expanded class hierarchy of ImageCacheUrlTests
File
- tests/
imagecache_create_url.test, line 7
View source
class ImageCacheUrlTests extends DrupalTestCase {
/**
* General admin user.
*/
var $admin_user;
/**
* The id of the php input format.
*/
var $input_format_id;
/**
* Drupal SimpleTest method: return metadata about the test.
*/
function get_info() {
return array(
'name' => 'ImageCache Create URL Tests',
'desc' => 'Assure that URLs are properly generated by imagecache_create_url(), as discussed at http://drupal.org/node/241541',
'group' => 'ImageCache',
);
}
/**
* SimpleTest core method: code run before each and every test method.
*/
function setUp() {
// Always call the setUp() function from the parent class.
parent::setUp();
// Make sure that the ImageCache module is enabled.
$this
->drupalModuleEnable('imagecache');
// Create admin user
$permissions = array(
'administer filters',
);
$this->admin_user = $this
->drupalCreateUserRolePerm($permissions);
// Log in with admin user.
$this
->drupalLoginUser($this->admin_user);
// Add an input format with PHP evaluator.
$edit = array(
'name' => $this
->randomName(10, 'inputformat_'),
'filters[filter/1]' => TRUE,
'roles[2]' => TRUE,
);
$this
->drupalPostRequest('admin/settings/filters/add', $edit, t('Save configuration'));
// Store the format id of the created input format.
$this->input_format_id = db_result(db_query("SELECT format FROM {filter_formats} WHERE name = '%s'", $edit['name']));
$this
->assertTrue($this->input_format_id, t('Input format id (%s)'));
}
/**
* SimpleTest core method: code run after each and every test method.
*/
function tearDown() {
// Remove input format.
$this
->drupalPostRequest('admin/settings/filters/delete/' . $this->input_format_id, array(), t('Delete'));
// Log out admin user.
$this
->drupalGet('logout');
// Always call the tearDown() function from the parent class.
parent::tearDown();
}
/**
* Test function that tests imagecache_create_url() under
* the different combinations of clean URLs and file download method
*/
function testImageCacheCreateUrl() {
// No Clean URLs + public downloads : http://example.com/?q=path/to/files/imagecache/preset/foo.jpg
$this
->_ImagecacheCreateUrlTest(false, FILE_DOWNLOADS_PUBLIC, 'path/to/files', 'preset', 'foo.jpg', 'http://example.com/?q=path/to/files/imagecache/preset/foo.jpg');
// Clean URLs + public downloads : http://example.com/path/to/files/imagecache/preset/foo.jpg
$this
->_ImagecacheCreateUrlTest(true, FILE_DOWNLOADS_PUBLIC, 'path/to/files', 'preset', 'foo.jpg', 'http://example.com/path/to/files/imagecache/preset/foo.jpg');
// No Clean URLs + private downloads : http://example.com/?q=system/files/imagecache/preset/foo.jpg
$this
->_ImagecacheCreateUrlTest(false, FILE_DOWNLOADS_PRIVATE, 'path/to/files', 'preset', 'foo.jpg', 'http://example.com/?q=system/files/imagecache/preset/foo.jpg');
// Clean URLs + private downloads : http://example.com/system/files/imagecache/preset/foo.jpg
$this
->_ImagecacheCreateUrlTest(true, FILE_DOWNLOADS_PRIVATE, 'path/to/files', 'preset', 'foo.jpg', 'http://example.com/system/files/imagecache/preset/foo.jpg');
}
/**
* Function to actually perform URL tests.
* @param $clean_url
* 'clean_url' setting for test.
* @param $file_downloads
* 'file_downloads' setting for test.
* @param $file_directory_path
* 'file_directory_path' setting for tests.
* @param $preset
* imagecache preset name to be used for test.
* @param $path
* file path to be used for generating output.
* @param $expected
* the url expected as output from imagecache_create_url
*
* Note about the implementation:
* At first sight one might think this can be easily implemented with just
* setting the Drupal settings, calling imagecache_create_url() and checking
* the result. This does not work however because the url() function, which is
* used by imagecache_create_url(), caches the clean_url setting with an
* internal static variable. This means that only one setting of clean_url
* can be evaluated per page view.
* To make testing possible, this function creates a node with the PHP
* evaluator as input filter and puts a proper call to imagecache_create_url()
* in the node body. The node view, which is a page view on its own can then
* be checked for the correctly generated URL.
*/
private function _ImagecacheCreateUrlTest($clean_url, $file_downloads, $file_directory_path, $preset, $path, $expected) {
// Drupal settings
$this
->drupalVariableSet('clean_url', $clean_url);
$this
->drupalVariableSet('file_downloads', $file_downloads);
$this
->drupalVariableSet('file_directory_path', $file_directory_path);
// Build node body (php code).
$body = "<?php\n // Change base_url\n \$GLOBALS['base_url'] = 'http://example.com';\n // Generate URL and check it.\n echo imagecache_create_url('{$preset}', '{$path}');\n ?>";
// Create node.
$node = $this
->drupalCreateNode(array(
'body' => $body,
'format' => $this->input_format_id,
));
// Show node.
$this
->drupalGet(url('node/' . $node->nid, NULL, NULL, TRUE));
// Check if expected url shows up
$this
->assertWantedRaw($expected, t('[ImageCacheUrlTests] @clean_url + @file_downloads should return "@expected"', array(
'@clean_url' => $clean_url ? 'Clean URLs' : 'No clean URLs',
'@file_downloads' => $file_downloads == FILE_DOWNLOADS_PRIVATE ? 'private downloads' : 'public downloads',
'@expected' => $expected,
)));
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
function | Will trigger a pass if both parameters refer to different objects. Fail otherwise. | ||
DrupalTestCase:: |
function | Will trigger a pass if the two parameters have the same value only. Otherwise a fail. | ||
DrupalTestCase:: |
function | Confirms that an error has occurred and optionally that the error text matches exactly. | ||
DrupalTestCase:: |
function | Confirms that an error has occurred and that the error text matches a Perl regular expression. | ||
DrupalTestCase:: |
function | Will trigger a pass if the two parameters have the same value and same type. Otherwise a fail. | ||
DrupalTestCase:: |
function | Type and class test. Will pass if class matches the type name or is a subclass or if not an object, but the type is correct. | ||
DrupalTestCase:: |
function | Confirms that no errors have occurred so far in the test method. | ||
DrupalTestCase:: |
function | Type and class mismatch test. Will pass if class name or underling type does not match the one specified. | ||
DrupalTestCase:: |
function | Will trigger a pass if the two parameters have a different value. Otherwise a fail. | ||
DrupalTestCase:: |
function | Will trigger a pass if the two parameters have the different value or different type. | ||
DrupalTestCase:: |
function | Will be true if the value is set. | ||
DrupalTestCase:: |
function | Will trigger a pass if the Perl regex pattern is not present in subject. Fail if found. | ||
DrupalTestCase:: |
function | Will trigger a pass if the raw text is NOT found on the loaded page Fail otherwise. | ||
DrupalTestCase:: |
function | Will be true if the value is null. | ||
DrupalTestCase:: |
function | Will trigger a pass if both parameters refer to the same object. Fail otherwise. | ||
DrupalTestCase:: |
function | Will trigger a pass if the Perl regex pattern is found in the subject. Fail otherwise. | ||
DrupalTestCase:: |
function | Will trigger a pass if the raw text is found on the loaded page Fail otherwise. | ||
DrupalTestCase:: |
function | Follows a link by name. Will click the first link found with this link text by default, or a later one if an index is given. Match is case insensitive with normalised space. Does make assertations if the click was sucessful or not and it does… | ||
DrupalTestCase:: |
function | @abstract Checks to see if we need to send a http-auth header to authenticate when browsing a site. | ||
DrupalTestCase:: |
function | Create a role / perm combination specified by permissions | ||
DrupalTestCase:: |
function | Creates a user / role / permissions combination specified by permissions | ||
DrupalTestCase:: |
function | @abstract Brokder for the get function adds the authentication headers if necessary @author Earnest Berry III <earnest.berry@gmail.com> | ||
DrupalTestCase:: |
function | @TODO: needs documentation | ||
DrupalTestCase:: |
function | Logs in a user with the internal browser | ||
DrupalTestCase:: |
function | Disables a drupal module | ||
DrupalTestCase:: |
function | Enables a drupal module | ||
DrupalTestCase:: |
function | Do a post request on a drupal page. It will be done as usual post request with SimpleBrowser | ||
DrupalTestCase:: |
function | @abstract Broker for the post function adds the authentication headers if necessary @author Earnest Berry III <earnest.berry@gmail.com> | ||
DrupalTestCase:: |
function | |||
DrupalTestCase:: |
function | Set a druapl variable and keep track of the changes for tearDown() | ||
DrupalTestCase:: |
function | Generates a random string, to be used as name or whatever | ||
DrupalTestCase:: |
function | Just some info for the reporter | ||
ImageCacheUrlTests:: |
property | General admin user. | ||
ImageCacheUrlTests:: |
property | The id of the php input format. | ||
ImageCacheUrlTests:: |
function | Drupal SimpleTest method: return metadata about the test. | ||
ImageCacheUrlTests:: |
function | SimpleTest core method: code run before each and every test method. | ||
ImageCacheUrlTests:: |
function |
SimpleTest core method: code run after each and every test method. Overrides DrupalTestCase:: |
||
ImageCacheUrlTests:: |
function | Test function that tests imagecache_create_url() under the different combinations of clean URLs and file download method | ||
ImageCacheUrlTests:: |
private | function | Function to actually perform URL tests. |