class CDNOriginPullTestCase in CDN 7.2
Hierarchy
- class \DrupalTestCase
- class \DrupalUnitTestCase
- class \CDNUnitTestCase
- class \CDNOriginPullTestCase
- class \CDNUnitTestCase
- class \DrupalUnitTestCase
Expanded class hierarchy of CDNOriginPullTestCase
File
- tests/
cdn.test, line 210 - Test CDN.
View source
class CDNOriginPullTestCase extends CDNUnitTestCase {
public static function getInfo() {
return array(
'name' => 'Origin Pull mode',
'description' => 'Verify Origin Pull mode-related functionality.',
'group' => 'CDN',
);
}
function setUp() {
parent::setUp();
$this
->loadFile('cdn.basic.inc');
$this
->loadFile('cdn.basic.farfuture.inc');
$this
->variableSet(CDN_MODE_VARIABLE, CDN_MODE_BASIC);
}
/**
* Assert a CDN mapping (and optionally set a mapping).
*
* @param $mapping
* The mapping to set; if FALSE, no new mapping will be set.
* @param $parsed_reference
* The reference the parsed mapping will be compared to.
* @param $domains_reference
* The reference the domains (as returned by cdn_get_domains()) will be
* compared to.
*/
function assertMapping($mapping, $parsed_reference, $domains_reference) {
if ($mapping !== FALSE) {
$this
->variableSet(CDN_BASIC_MAPPING_VARIABLE, $mapping);
}
$this
->assertEqual($parsed_reference, _cdn_basic_parse_raw_mapping(cdn_basic_get_mapping()), 'CDN mapping parsed correctly.');
$domains = cdn_get_domains();
sort($domains);
$this
->assertEqual($domains_reference, $domains, 'CDN domains parsed correctly.');
}
function testMapping() {
$this
->setRequestProtocol('http');
$this
->assertEqual('', cdn_basic_get_mapping(), 'The default CDN mapping is empty.');
// Ensure the parsing of the raw mapping works correctly.
$this
->assertMapping('', array(), array());
$this
->assertMapping('http://cdn-a.com', array(
'*' => array(
'http://cdn-a.com',
),
), array(
'cdn-a.com',
));
$this
->assertMapping('http://cdn-a.com/', array(
'*' => array(
'http://cdn-a.com',
),
), array(
'cdn-a.com',
));
$this
->assertMapping('//cdn-a.com', array(
'*' => array(
'//cdn-a.com',
),
), array(
'cdn-a.com',
));
$this
->assertMapping('//cdn-a.com/', array(
'*' => array(
'//cdn-a.com',
),
), array(
'cdn-a.com',
));
$parsed_mapping = array(
'css' => array(
'http://cdn-a.com',
),
'jpg' => array(
'http://cdn-a.com',
),
'jpeg' => array(
'http://cdn-a.com',
),
'png' => array(
'http://cdn-a.com',
),
'zip' => array(
'http://cdn-b.com',
),
'*' => array(
'http://cdn-c.com',
),
);
$domains = array(
'cdn-a.com',
'cdn-b.com',
'cdn-c.com',
);
$this
->assertMapping("http://cdn-a.com|.css .jpg .jpeg .png\nhttp://cdn-b.com|.zip\nhttp://cdn-c.com", $parsed_mapping, $domains);
$parsed_mapping = array(
'css' => array(
'http://cdn-a.com',
'http://cdn-d.com',
),
'jpg' => array(
'http://cdn-a.com',
'http://cdn-d.com',
),
'jpeg' => array(
'http://cdn-a.com',
'http://cdn-d.com',
),
'png' => array(
'http://cdn-a.com',
'http://cdn-d.com',
'http://cdn-b.com',
),
'*' => array(
'http://cdn-c.com',
),
);
$domains = array(
'cdn-a.com',
'cdn-b.com',
'cdn-c.com',
'cdn-d.com',
);
$this
->assertMapping("http://cdn-a.com http://cdn-d.com|.css .jpg .jpeg .png\nhttp://cdn-b.com|.png\nhttp://cdn-c.com", $parsed_mapping, $domains);
// When a HTTPS request is performed and the CDN is not marked to support
// HTTPS, then it should fall back to the default CDN mapping.
$this
->setRequestProtocol('https');
$this
->assertMapping(FALSE, $parsed_mapping, $domains);
// When a HTTPS request is performed and the CDN *is* marked to support
// HTTPS, then it should still fall back to the default CDN mapping. (When
// file URLs are actually altered, it will then replace `http://` with
// `https://` -- this will be tested in a different test.)
$this
->configureHTTPS(TRUE);
$this
->assertMapping(FALSE, $parsed_mapping, $domains);
// When a HTTPS request is performed *and* the CDN is marked to support
// HTTPS *and* there's a HTTPS-specific CDN mapping, that mapping should
// be used instead!
$this
->configureHTTPS(TRUE, "https://cdn-a.com|.css .jpg .jpeg .png\nhttps://cdn-b.com|.zip\nhttps://cdn-c.com");
$this
->assertMapping(FALSE, array(
'css' => array(
'https://cdn-a.com',
),
'jpg' => array(
'https://cdn-a.com',
),
'jpeg' => array(
'https://cdn-a.com',
),
'png' => array(
'https://cdn-a.com',
),
'zip' => array(
'https://cdn-b.com',
),
'*' => array(
'https://cdn-c.com',
),
), array(
'cdn-a.com',
'cdn-b.com',
'cdn-c.com',
));
// Ensure the default CDN mapping is used whenever a HTTP request occurs
// and the CDN is marked to suppport HTTPS and there's a HTTPS-specific
// CDN mapping.
$this
->configureHTTPS(FALSE);
$this
->assertMapping(FALSE, $parsed_mapping, $domains);
}
function testFileUrlAlterHook() {
// Provide a very basic CDN mapping.
$this
->variableSet(CDN_BASIC_MAPPING_VARIABLE, 'http://cdn-a.com');
$filename = 'újjáépítésérol — 100% in B&W.jpg';
$uri = "public://{$filename}";
$this
->touchFile($uri);
cdn_file_url_alter($uri);
$expected = 'http://cdn-a.com' . base_path() . variable_get('file_public_path', conf_path() . '/files') . '/' . drupal_encode_path($filename);
$this
->assertIdentical($uri, $expected, 'cdn_file_url_alter() works correctly.');
// Test that private:// file URLs are not altered.
$uri = "private://{$filename}";
$expected = $uri;
cdn_file_url_alter($uri);
$this
->assertIdentical($uri, $expected, 'cdn_file_url_alter() excludes private:// files.');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CDNOriginPullTestCase:: |
function | Assert a CDN mapping (and optionally set a mapping). | ||
CDNOriginPullTestCase:: |
public static | function | ||
CDNOriginPullTestCase:: |
function |
Sets up unit test environment. Overrides CDNUnitTestCase:: |
||
CDNOriginPullTestCase:: |
function | |||
CDNOriginPullTestCase:: |
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:: |