You are here

class CDNOriginPullTestCase in CDN 7.2

Hierarchy

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

Namesort descending Modifiers Type Description Overrides
CDNOriginPullTestCase::assertMapping function Assert a CDN mapping (and optionally set a mapping).
CDNOriginPullTestCase::getInfo public static function
CDNOriginPullTestCase::setUp function Sets up unit test environment. Overrides CDNUnitTestCase::setUp
CDNOriginPullTestCase::testFileUrlAlterHook function
CDNOriginPullTestCase::testMapping function
CDNUnitTestCase::configureHTTPS function Configure HTTPS-related settings.
CDNUnitTestCase::getExpandedFilePath function Given a file URI, get the expanded file path.
CDNUnitTestCase::loadFile function
CDNUnitTestCase::setRequestProtocol function Set the protocol of the current "request".
CDNUnitTestCase::setUserAgent function Set the User-Agent of the current "request".
CDNUnitTestCase::tearDown function Overrides DrupalUnitTestCase::tearDown
CDNUnitTestCase::touchFile function Given a file URI, get its path, create the file and ensure it exists.
CDNUnitTestCase::variableSet function Mock function for variable_set().
CDNUnitTestCase::variableSetDefaults function Set the default variable values for the CDN module.
DrupalTestCase::$assertions protected property Assertions thrown in that test case.
DrupalTestCase::$databasePrefix protected property The database prefix of this test run.
DrupalTestCase::$originalFileDirectory protected property The original file directory, before it was changed for testing purposes.
DrupalTestCase::$results public property Current results of this test case.
DrupalTestCase::$setup protected property Flag to indicate whether the test has been set up.
DrupalTestCase::$setupDatabasePrefix protected property
DrupalTestCase::$setupEnvironment protected property
DrupalTestCase::$skipClasses protected property This class is skipped when looking for the source of an assertion.
DrupalTestCase::$testId protected property The test run ID.
DrupalTestCase::$timeLimit protected property Time limit for the test.
DrupalTestCase::$useSetupInstallationCache public property Whether to cache the installation part of the setUp() method.
DrupalTestCase::$useSetupModulesCache public property Whether to cache the modules installation part of the setUp() method.
DrupalTestCase::$verboseDirectoryUrl protected property URL to the verbose output file directory.
DrupalTestCase::assert protected function Internal helper: stores the assert.
DrupalTestCase::assertEqual protected function Check to see if two values are equal.
DrupalTestCase::assertFalse protected function Check to see if a value is false (an empty string, 0, NULL, or FALSE).
DrupalTestCase::assertIdentical protected function Check to see if two values are identical.
DrupalTestCase::assertNotEqual protected function Check to see if two values are not equal.
DrupalTestCase::assertNotIdentical protected function Check to see if two values are not identical.
DrupalTestCase::assertNotNull protected function Check to see if a value is not NULL.
DrupalTestCase::assertNull protected function Check to see if a value is NULL.
DrupalTestCase::assertTrue protected function Check to see if a value is not false (not an empty string, 0, NULL, or FALSE).
DrupalTestCase::deleteAssert public static function Delete an assertion record by message ID.
DrupalTestCase::error protected function Fire an error assertion. 1
DrupalTestCase::errorHandler public function Handle errors during test runs. 1
DrupalTestCase::exceptionHandler protected function Handle exceptions.
DrupalTestCase::fail protected function Fire an assertion that is always negative.
DrupalTestCase::generatePermutations public static function Converts a list of possible parameters into a stack of permutations.
DrupalTestCase::getAssertionCall protected function Cycles through backtrace until the first non-assertion method is found.
DrupalTestCase::getDatabaseConnection public static function Returns the database connection to the site running Simpletest.
DrupalTestCase::insertAssert public static function Store an assertion from outside the testing context.
DrupalTestCase::pass protected function Fire an assertion that is always positive.
DrupalTestCase::randomName public static function Generates a random string containing letters and numbers.
DrupalTestCase::randomString public static function Generates a random string of ASCII characters of codes 32 to 126.
DrupalTestCase::run public function Run all tests in this class.
DrupalTestCase::verbose protected function Logs a verbose message in a text file.
DrupalUnitTestCase::__construct function Constructor for DrupalUnitTestCase. Overrides DrupalTestCase::__construct