class CDNImageTestCase in CDN 7.2
Hierarchy
- class \DrupalTestCase
- class \DrupalUnitTestCase
- class \CDNUnitTestCase
- class \CDNImageTestCase
- class \CDNUnitTestCase
- class \DrupalUnitTestCase
Expanded class hierarchy of CDNImageTestCase
File
- tests/
cdn.test, line 503 - Test CDN.
View source
class CDNImageTestCase extends CDNUnitTestCase {
public static function getInfo() {
return array(
'name' => 'Image and Download Link HTML altering',
'description' => 'Verify that image and anchor link URLs inside HTML are rewritten correctly.',
'group' => 'CDN',
);
}
function setUp() {
parent::setUp();
$this
->loadFile('cdn.fallback.inc');
}
function testImage() {
$cdn = 'http://cdn-a.com';
$this
->variableSet(CDN_BASIC_MAPPING_VARIABLE, $cdn);
$this
->variableSet(CDN_MODE_VARIABLE, CDN_MODE_BASIC);
// Image altering type 1: "just image", i.e. "<img />".
$template = function ($url) {
return '<img alt="Foo!" src="' . $url . '" title="Bar!"/>';
};
// Simplest case possible.
$img_url = base_path() . 'foo/bar/image.png';
$html = $template($img_url);
cdn_html_alter_image_urls($html);
$this
->assertIdentical($template($cdn . $img_url), $html, 'Image HTML correctly altered.');
// Query strings should not be stripped
$img_url = base_path() . 'foo/bar/image.png?foobar';
$html = $template($img_url);
cdn_html_alter_image_urls($html);
$this
->assertIdentical($template($cdn . $img_url), $html, 'Image HTML correctly altered (query string not stripped).');
// In particular: not the query string used to generate image styles.
$img_url = base_path() . 'foo/bar/image.png?itok=1234abcd';
$html = $template($img_url);
cdn_html_alter_image_urls($html);
$this
->assertIdentical($template($cdn . $img_url), $html, 'Image HTML correctly altered (image style query string not stripped).');
// Edge case: a script generating an image is not (yet) supported.
$img_url = base_path() . 'foo/bar/showimage?formula=12345.png';
$html = $template($img_url);
cdn_html_alter_image_urls($html);
$this
->assertIdentical($template($cdn . $img_url), $html, 'Image HTML correctly altered (query string not stripped).');
// Image altering type 2: "linked image", i.e. "<a><img /></a>"..
$template = function ($a_url, $img_url) {
return '<a rel="gallery" href="' . $a_url . '" class="gallery-image"><img alt="Foo!" src="' . $img_url . '" title="Bar!" /></a>';
};
// Simplest case possible: a linked image linking to the same image.
$img_base_url = base_path() . 'foo/bar/image';
$a_url = $img_url = $img_base_url . '.png';
$html = $template($a_url, $img_url);
cdn_html_alter_image_urls($html);
$this
->assertIdentical($template($cdn . $a_url, $cdn . $img_url), $html, 'Linked image HTML correctly altered.');
// Slightly more complex: a linked image linking to a derivative image.
$img_url = $img_base_url . '-thumbnail.png?itok=5678wxyz';
$html = $template($a_url, $img_url);
cdn_html_alter_image_urls($html);
$this
->assertIdentical($template($cdn . $a_url, $cdn . $img_url), $html, 'Linked image HTML correctly altered.');
// Slightly more complex: a linked derivative image linking to another
// derivative image.
$a_url = $img_base_url . '-large.png?itok=9012klmn';
$img_url = $img_base_url . '-thumbnail.png?itok=5678wxyz';
$html = $template($a_url, $img_url);
cdn_html_alter_image_urls($html);
$this
->assertIdentical($template($cdn . $a_url, $cdn . $img_url), $html, 'Linked image HTML correctly altered.');
// Ensure that images linking to content (i.e. not a bigger version of the
// image) don't get their anchors modified
$a_url = base_path() . 'node';
$html = $template($a_url, $img_url);
$html = cdn_post_render_html_alter($html);
$this
->assertIdentical($template($a_url, $cdn . $img_url), $html, 'Linked image HTML correctly altered (anchor unmodified).');
// Same, but now for a link with a query string.
$a_url = base_path() . 'node?foobar';
$html = $template($a_url, $img_url);
$html = cdn_post_render_html_alter($html);
$this
->assertIdentical($template($a_url, $cdn . $img_url), $html, 'Linked image HTML correctly altered (anchor unmodified, even with query strings).');
}
function testOtherContentLink() {
$cdn = 'http://cdn-a.com';
$this
->variableSet(CDN_BASIC_MAPPING_VARIABLE, "{$cdn}|.png .pdf");
$this
->variableSet(CDN_MODE_VARIABLE, CDN_MODE_BASIC);
// Image altering type 1: "just image", i.e. "<img />".
$template = function ($url) {
return '<a href="' . $url . '">Download this!</a>';
};
// Simplest case possible.
$a_url = base_path() . 'foo/bar/image.png';
$html = $template($a_url);
$html = cdn_post_render_html_alter($html);
$this
->assertIdentical($template($cdn . $a_url), $html, 'Other content link correctly altered.');
// Query strings should not be stripped.
$a_url = base_path() . 'foo/bar/image.pdf?foobar';
$html = $template($a_url);
$html = cdn_post_render_html_alter($html);
$this
->assertIdentical($template($cdn . $a_url), $html, 'Other content link correctly altered (query string not stripped).');
// Edge case: a script generating an image is not (yet) supported.
$a_url = base_path() . 'foo/bar/image.gif';
$html = $template($a_url);
$html = cdn_post_render_html_alter($html);
$this
->assertIdentical($template($a_url), $html, 'Other content link correctly NOT altered (extension does not map).');
// Edge case: a script generating an image is not (yet) supported.
$a_url = base_path() . 'foo/bar/showimage?formula=12345.png';
$html = $template($a_url);
$html = cdn_post_render_html_alter($html);
$this
->assertIdentical($template($a_url), $html, 'Other content link correctly NOT altered (extension not pulled from query string).');
}
function testOtherContentLinkWrappingImage() {
$cdn = 'http://cdn-a.com';
$this
->variableSet(CDN_BASIC_MAPPING_VARIABLE, "{$cdn}|.png .jpeg");
$this
->variableSet(CDN_MODE_VARIABLE, CDN_MODE_BASIC);
// Image altering type 2: "linked image", i.e. "<a><img /></a>"..
$template = function ($a_url, $img_url) {
return '<a href="' . $a_url . '"><img src="' . $img_url . '" /></a>';
};
// Test that images linking to a URL with an extension that matches a
// mapped extension, even if the extension is different than the image,
// are modified.
$a_url = base_path() . 'node.jpeg';
$img_url = base_path() . 'foo/bar/image.png';
$html = $template($a_url, $img_url);
$html = cdn_post_render_html_alter($html);
$this
->assertIdentical($template($cdn . $a_url, $cdn . $img_url), $html, 'Other content link wrapping image correctly altered.');
$a_url = base_path() . 'node.gif';
$html = $template($a_url, $img_url);
$html = cdn_post_render_html_alter($html);
$this
->assertIdentical($template($a_url, $cdn . $img_url), $html, 'Other content link wrapping correctly NOT altered (extension does not map).');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CDNImageTestCase:: |
public static | function | ||
CDNImageTestCase:: |
function |
Sets up unit test environment. Overrides CDNUnitTestCase:: |
||
CDNImageTestCase:: |
function | |||
CDNImageTestCase:: |
function | |||
CDNImageTestCase:: |
function | |||
CDNUnitTestCase:: |
function | Configure HTTPS-related settings. | ||
CDNUnitTestCase:: |
function | Given a file URI, get the expanded file path. | ||
CDNUnitTestCase:: |
function | |||
CDNUnitTestCase:: |
function | Set the protocol of the current "request". | ||
CDNUnitTestCase:: |
function | Set the User-Agent of the current "request". | ||
CDNUnitTestCase:: |
function |
Overrides DrupalUnitTestCase:: |
||
CDNUnitTestCase:: |
function | Given a file URI, get its path, create the file and ensure it exists. | ||
CDNUnitTestCase:: |
function | Mock function for variable_set(). | ||
CDNUnitTestCase:: |
function | Set the default variable values for the CDN module. | ||
DrupalTestCase:: |
protected | property | Assertions thrown in that test case. | |
DrupalTestCase:: |
protected | property | The database prefix of this test run. | |
DrupalTestCase:: |
protected | property | The original file directory, before it was changed for testing purposes. | |
DrupalTestCase:: |
public | property | Current results of this test case. | |
DrupalTestCase:: |
protected | property | Flag to indicate whether the test has been set up. | |
DrupalTestCase:: |
protected | property | ||
DrupalTestCase:: |
protected | property | ||
DrupalTestCase:: |
protected | property | This class is skipped when looking for the source of an assertion. | |
DrupalTestCase:: |
protected | property | The test run ID. | |
DrupalTestCase:: |
protected | property | Time limit for the test. | |
DrupalTestCase:: |
public | property | Whether to cache the installation part of the setUp() method. | |
DrupalTestCase:: |
public | property | Whether to cache the modules installation part of the setUp() method. | |
DrupalTestCase:: |
protected | property | URL to the verbose output file directory. | |
DrupalTestCase:: |
protected | function | Internal helper: stores the assert. | |
DrupalTestCase:: |
protected | function | Check to see if two values are equal. | |
DrupalTestCase:: |
protected | function | Check to see if a value is false (an empty string, 0, NULL, or FALSE). | |
DrupalTestCase:: |
protected | function | Check to see if two values are identical. | |
DrupalTestCase:: |
protected | function | Check to see if two values are not equal. | |
DrupalTestCase:: |
protected | function | Check to see if two values are not identical. | |
DrupalTestCase:: |
protected | function | Check to see if a value is not NULL. | |
DrupalTestCase:: |
protected | function | Check to see if a value is NULL. | |
DrupalTestCase:: |
protected | function | Check to see if a value is not false (not an empty string, 0, NULL, or FALSE). | |
DrupalTestCase:: |
public static | function | Delete an assertion record by message ID. | |
DrupalTestCase:: |
protected | function | Fire an error assertion. | 1 |
DrupalTestCase:: |
public | function | Handle errors during test runs. | 1 |
DrupalTestCase:: |
protected | function | Handle exceptions. | |
DrupalTestCase:: |
protected | function | Fire an assertion that is always negative. | |
DrupalTestCase:: |
public static | function | Converts a list of possible parameters into a stack of permutations. | |
DrupalTestCase:: |
protected | function | Cycles through backtrace until the first non-assertion method is found. | |
DrupalTestCase:: |
public static | function | Returns the database connection to the site running Simpletest. | |
DrupalTestCase:: |
public static | function | Store an assertion from outside the testing context. | |
DrupalTestCase:: |
protected | function | Fire an assertion that is always positive. | |
DrupalTestCase:: |
public static | function | Generates a random string containing letters and numbers. | |
DrupalTestCase:: |
public static | function | Generates a random string of ASCII characters of codes 32 to 126. | |
DrupalTestCase:: |
public | function | Run all tests in this class. | |
DrupalTestCase:: |
protected | function | Logs a verbose message in a text file. | |
DrupalUnitTestCase:: |
function |
Constructor for DrupalUnitTestCase. Overrides DrupalTestCase:: |