You are here

public function FaviconDeliveryTestCase::testDelivery in Favicon 7.2

File

tests/FaviconDeliveryTestCase.test, line 23

Class

FaviconDeliveryTestCase

Code

public function testDelivery() {
  $favicon_contents = file_get_contents(DrupalFavicon::DEFAULT_URI);
  $account = $this
    ->drupalCreateUser(array(
    'administer site configuration',
  ));

  // Set the delivery back to the default method.
  $this
    ->drupalLogin($account);
  $this
    ->drupalPost('admin/config/system/favicon', array(), 'Save configuration');
  $this
    ->drupalGet('favicon.ico');
  $this
    ->assertUrl('favicon.ico');
  $this
    ->assertIdentical($this
    ->drupalGetContent(), $favicon_contents);

  // Hit favicon.ico as an anonymous user. This should cause the page to be cached.
  $this
    ->drupalLogout();
  $this
    ->drupalGet('favicon.ico');
  $this
    ->assertUrl('favicon.ico');
  $this
    ->assertIdentical($this
    ->drupalGetContent(), $favicon_contents);
  $this
    ->drupalLogin($account);
  $edit = array(
    'favicon_delivery_callback' => 'DrupalFavicon::deliverFileRedirect',
  );
  $this
    ->drupalPost('admin/config/system/favicon', $edit, 'Save configuration');
  $this
    ->drupalGet('favicon.ico');
  $this
    ->assertUrl(file_create_url('misc/favicon.ico'));
  $this
    ->assertIdentical($this
    ->drupalGetContent(), $favicon_contents);

  // Test that the earlier page cache was cleared.
  $this
    ->drupalLogout();
  $this
    ->drupalGet('favicon.ico');
  $this
    ->assertUrl(file_create_url('misc/favicon.ico'));
  $this
    ->assertIdentical($this
    ->drupalGetContent(), $favicon_contents);

  // @todo Add testing for page cache being skipped if file is too large.
  // @todo Add testing for integration with Redirect module.
}