public function AuthcacheElementCacheabilityAPITestCase::testElementCacheabilityAPI in Authenticated User Page Caching (Authcache) 7.2
Test cacheability API for render elements.
File
- ./
authcache.test, line 1668 - Tests for system.module.
Class
- AuthcacheElementCacheabilityAPITestCase
- Test API for suspecting and testing render-elements for cacheability.
Code
public function testElementCacheabilityAPI() {
// Ensure that unsuspicous elements are left alone.
$this
->resetTestVariables();
$element = array(
'#markup' => t('Does not contain personalized content'),
);
variable_set('authcache_test_record', TRUE);
$output = render($element);
$this
->assertEqual(t('Does not contain personalized content'), $output);
$this
->assertAuthcacheNotCanceled();
// Ensure that rendering of empty suspected elements are left alone.
$this
->resetTestVariables();
$element = array(
'#markup' => '',
);
authcache_element_suspect($element);
variable_set('authcache_test_record', TRUE);
$output = render($element);
$this
->assertFalse($output);
$this
->assertAuthcacheNotCanceled();
// Ensure that rendering of suspected elements trigger cancelation with
// generic message.
$this
->resetTestVariables();
$element = array(
'#markup' => t('Some personalized content'),
);
authcache_element_suspect($element);
variable_set('authcache_test_record', TRUE);
$output = render($element);
$this
->assertEqual(t('Some personalized content'), $output);
$this
->assertAuthcacheCanceled(t('Non cacheable render element on page'));
// Ensure that cancelation message can be customized.
$this
->resetTestVariables();
$element = array(
'#markup' => t('Some personalized content'),
);
authcache_element_suspect($element, t('Customized cancelation message'));
variable_set('authcache_test_record', TRUE);
$output = render($element);
$this
->assertEqual(t('Some personalized content'), $output);
$this
->assertAuthcacheCanceled(t('Customized cancelation message'));
// Ensure that rendering of empty suspected elements trigger cancelation if
// strict mode is enabled.
$this
->resetTestVariables();
$element = array(
'#markup' => '',
);
authcache_element_suspect($element, t('Customized cancelation message'), TRUE);
variable_set('authcache_test_record', TRUE);
$output = render($element);
$this
->assertFalse($output);
$this
->assertAuthcacheCanceled(t('Customized cancelation message'));
// Ensure that value elements trigger cancelation.
$this
->resetTestVariables();
$element = array(
'#type' => 'value',
'#value' => 42,
);
authcache_element_suspect($element);
variable_set('authcache_test_record', TRUE);
$output = render($element);
$this
->assertFalse($output);
$this
->assertAuthcacheCanceled(t('Non cacheable render element on page'));
// Ensure that suspicous elements can be marked as being cacheable.
$this
->resetTestVariables();
$element = array(
'#markup' => t('Some personalized content'),
);
authcache_element_suspect($element);
authcache_element_set_cacheable($element);
variable_set('authcache_test_record', TRUE);
$output = render($element);
$this
->assertEqual(t('Some personalized content'), $output);
$this
->assertAuthcacheNotCanceled();
}