function BootstrapPageCacheTestCase::testPageCompression

Test page compression.

The test should pass even if zlib.output_compression is enabled in php.ini, .htaccess or similar, or if compression is done outside PHP, e.g. by the mod_deflate Apache module.

Archivo

drupal-7.x/modules/simpletest/tests/bootstrap.test, line 200

Class

BootstrapPageCacheTestCase

Código

function testPageCompression() {
  variable_set('cache', 1);

  // Fill the cache and verify that output is compressed.
  $this->drupalGet('', array(), array('Accept-Encoding: gzip,deflate'));
  $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS', 'Page was not cached.');
  $this->drupalSetContent(gzinflate(substr($this->drupalGetContent(), 10, -8)));
  $this->assertRaw('</html>', 'Page was gzip compressed.');

  // Verify that cached output is compressed.
  $this->drupalGet('', array(), array('Accept-Encoding: gzip,deflate'));
  $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', 'Page was cached.');
  $this->assertEqual($this->drupalGetHeader('Content-Encoding'), 'gzip', 'A Content-Encoding header was sent.');
  $this->drupalSetContent(gzinflate(substr($this->drupalGetContent(), 10, -8)));
  $this->assertRaw('</html>', 'Page was gzip compressed.');

  // Verify that a client without compression support gets an uncompressed page.
  $this->drupalGet('');
  $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', 'Page was cached.');
  $this->assertFalse($this->drupalGetHeader('Content-Encoding'), 'A Content-Encoding header was not sent.');
  $this->assertTitle(t('Welcome to @site-name | @site-name', array('@site-name' => variable_get('site_name', 'Drupal'))), 'Site title matches.');
  $this->assertRaw('</html>', 'Page was not compressed.');
}