private function ImageCacheUrlTests::_ImagecacheCreateUrlTest in ImageCache 5.2
Same name and namespace in other branches
- 6.2 tests/imagecache_create_url.test \ImageCacheUrlTests::_ImagecacheCreateUrlTest()
Function to actually perform URL tests.
Parameters
$clean_url: 'clean_url' setting for test.
$file_downloads: 'file_downloads' setting for test.
$file_directory_path: 'file_directory_path' setting for tests.
$preset: imagecache preset name to be used for test.
$path: file path to be used for generating output.
$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.
1 call to ImageCacheUrlTests::_ImagecacheCreateUrlTest()
- ImageCacheUrlTests::testImageCacheCreateUrl in tests/
imagecache_create_url.test - Test function that tests imagecache_create_url() under the different combinations of clean URLs and file download method
File
- tests/
imagecache_create_url.test, line 137
Class
- ImageCacheUrlTests
- Test class for testing imagecache_create_url() in several use cases with the different combinations of clean URLs and private/public download method.
Code
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,
)));
}