Example #1
0
        $content2 = $response->getContent();
        $contentType2 = $response->getContentType();
        $headers2 = $response->getHttpHeaders();
        $b->test()->is($content1, $content2, 'response content is the same');
        $b->test()->is($contentType1, $contentType2, 'response content type is the same');
        $b->test()->is($headers1, $headers2, 'response http headers are the same');
    }
}
$b = new myTestBrowser();
// non HTML cache
$image = file_get_contents(__DIR__ . '/fixtures/apps/cache/modules/cache/data/ok48.png');
sfConfig::set('sf_web_debug', true);
$b->get('/cache/imageWithLayoutCacheWithLayout')->with('view_cache')->isCached(true, true)->checkResponseContent($image, 'image (with layout/page cache) in cache is not decorated when web_debug is on')->get('/cache/imageWithLayoutCacheWithLayout')->with('view_cache')->isCached(true, true)->checkResponseContent($image, 'image (with layout/page cache) in cache is not decorated when web_debug is on')->get('/cache/imageWithLayoutCacheNoLayout')->with('view_cache')->isCached(true)->checkResponseContent($image, 'image (with layout/action cache) in cache is not decorated when web_debug is on')->get('/cache/imageWithLayoutCacheNoLayout')->with('view_cache')->isCached(true)->checkResponseContent($image, 'image (with layout/action cache) in cache is not decorated when web_debug is on')->get('/cache/imageNoLayoutCacheWithLayout')->with('view_cache')->isCached(true, true)->checkResponseContent($image, 'image (no layout/page cache) in cache is not decorated when web_debug is on')->get('/cache/imageNoLayoutCacheWithLayout')->with('view_cache')->isCached(true, true)->checkResponseContent($image, 'image (no layout/page cache) in cache is not decorated when web_debug is on')->get('/cache/imageNoLayoutCacheNoLayout')->with('view_cache')->isCached(true)->checkResponseContent($image, 'image (no layout/action cache) in cache is not decorated when web_debug is on')->get('/cache/imageNoLayoutCacheNoLayout')->with('view_cache')->isCached(true)->checkResponseContent($image, 'image (no layout/action cache) in cache is not decorated when web_debug is on');
sfConfig::set('sf_web_debug', false);
// check stylesheets, javascripts inclusions
sfToolkit::clearDirectory(sfConfig::get('sf_app_cache_dir'));
$b->get('/cache/multiBis')->with('request')->begin()->isParameter('module', 'cache')->isParameter('action', 'multiBis')->end()->with('response')->begin()->isStatusCode(200)->checkElement('link[href*="/main_css"]')->checkElement('script[src*="/main_js"]')->checkElement('link[href*="/partial_css"]')->checkElement('script[src*="/partial_js"]')->checkElement('link[href*="/another_partial_css"]')->checkElement('script[src*="/another_partial_js"]')->checkElement('link[href*="/component_css"]')->checkElement('script[src*="/component_js"]')->checkElement('#partial_slot_content', 'Partial')->checkElement('#another_partial_slot_content', 'Another Partial')->checkElement('#component_slot_content', 'Component')->end()->get('/cache/multiBis')->with('response')->begin()->checkElement('link[href*="/main_css"]')->checkElement('script[src*="/main_js"]')->checkElement('link[href*="/partial_css"]')->checkElement('script[src*="/partial_js"]')->checkElement('link[href*="/another_partial_css"]')->checkElement('script[src*="/another_partial_js"]')->checkElement('link[href*="/component_css"]')->checkElement('script[src*="/component_js"]')->checkElement('#partial_slot_content', 'Partial')->checkElement('#another_partial_slot_content', 'Another Partial')->checkElement('#component_slot_content', 'Component')->end();
$b->get('/cache/partial')->with('request')->begin()->isParameter('module', 'cache')->isParameter('action', 'partial')->end()->with('response')->begin()->isStatusCode(200)->checkElement('link[href*="/main_css"]', false)->checkElement('script[src*="/main_js"]', false)->checkElement('link[href*="/partial_css"]')->checkElement('script[src*="/partial_js"]')->checkElement('link[href*="/another_partial_css"]')->checkElement('script[src*="/another_partial_js"]')->checkElement('link[href*="/component_css"]', false)->checkElement('script[src*="/component_js"]', false)->checkElement('#partial_slot_content', 'Partial')->checkElement('#another_partial_slot_content', 'Another Partial')->checkElement('#component_slot_content', '')->end()->get('/cache/anotherPartial')->with('request')->begin()->isParameter('module', 'cache')->isParameter('action', 'anotherPartial')->end()->with('response')->begin()->isStatusCode(200)->checkElement('link[href*="/main_css"]', false)->checkElement('script[src*="/main_js"]', false)->checkElement('link[href*="/partial_css"]', false)->checkElement('script[src*="/partial_js"]', false)->checkElement('link[href*="/another_partial_css"]')->checkElement('script[src*="/another_partial_js"]')->checkElement('link[href*="/component_css"]', false)->checkElement('script[src*="/component_js"]', false)->checkElement('#partial_slot_content', '')->checkElement('#another_partial_slot_content', 'Another Partial')->checkElement('#component_slot_content', '')->end()->get('/cache/component')->with('request')->begin()->isParameter('module', 'cache')->isParameter('action', 'component')->end()->with('response')->begin()->isStatusCode(200)->checkElement('link[href*="/main_css"]', false)->checkElement('script[src*="/main_js"]', false)->checkElement('link[href*="/partial_css"]', false)->checkElement('script[src*="/partial_js"]', false)->checkElement('link[href*="/another_partial_css"]', false)->checkElement('script[src*="/another_partial_js"]', false)->checkElement('link[href*="/component_css"]')->checkElement('script[src*="/component_js"]')->checkElement('#partial_slot_content', '')->checkElement('#another_partial_slot_content', '')->checkElement('#component_slot_content', 'Component')->end();
$b->get('/')->with('view_cache')->isUriCached('cache/list', false)->get('/cache/list')->with('view_cache')->isUriCached('cache/list', true)->with('view_cache')->isUriCached('cache/list?page=10', false)->get('/cache/list?page=10')->with('response')->checkElement('#page', '10')->with('view_cache')->isUriCached('cache/list?page=10', true)->with('view_cache')->isUriCached('cache/list?page=20', false)->get('/cache/list?page=20')->with('response')->checkElement('#page', '20')->with('view_cache')->isUriCached('cache/list?page=20', true);
// check for 304 response
sfConfig::set('LAST_MODIFIED', strtotime('2010-01-01'));
$b->get('/cache/lastModifiedResponse')->with('response')->isStatusCode(200);
$b->setHttpHeader('If-Modified-Since', sfWebResponse::getDate(sfConfig::get('LAST_MODIFIED')))->get('/cache/lastModifiedResponse')->with('response')->isStatusCode(304);
// test with sfFileCache class (default)
$b->launch();
// test with sfSQLiteCache class
if (extension_loaded('SQLite') || extension_loaded('pdo_SQLite')) {
    sfConfig::set('sf_factory_view_cache', 'sfSQLiteCache');
    sfConfig::set('sf_factory_view_cache_parameters', array('database' => sfConfig::get('sf_template_cache_dir') . DIRECTORY_SEPARATOR . 'cache.db'));
    $b->launch();
}
Example #2
0
  ->with('view_cache')->isUriCached('cache/list?page=10', true)

  // include different GET parameters
  ->with('view_cache')->isUriCached('cache/list?page=20', false)
  ->get('/cache/list?page=20')
  ->with('response')->checkElement('#page', '20')
  ->with('view_cache')->isUriCached('cache/list?page=20', true)
;

// check for 304 response
sfConfig::set('LAST_MODIFIED', strtotime('2010-01-01'));
$b->get('/cache/lastModifiedResponse')
  ->with('response')->isStatusCode(200)
;

$b->setHttpHeader('If-Modified-Since', sfWebResponse::getDate(sfConfig::get('LAST_MODIFIED')))
  ->get('/cache/lastModifiedResponse')
  ->with('response')->isStatusCode(304)
;

// test with sfFileCache class (default)
$b->launch();

// test with sfSQLiteCache class
if (extension_loaded('SQLite') || extension_loaded('pdo_SQLite'))
{
  sfConfig::set('sf_factory_view_cache', 'sfSQLiteCache');
  sfConfig::set('sf_factory_view_cache_parameters', array('database' => sfConfig::get('sf_template_cache_dir').DIRECTORY_SEPARATOR.'cache.db'));
  $b->launch();
}