Tests changing form_cache_expiration.

File

modules/simpletest/tests/form.test, line 1480
Unit tests for the Drupal Form API.

Class

FormsFormCacheTestCase
Test cache_form.

Code

function testCacheFormCustomExpiration() {
  variable_set('form_cache_expiration', -1 * (24 * 60 * 60));
  $form = drupal_get_form('form_test_cache_form');
  $form_state = array(
    'foo' => 'bar',
    'build_info' => array(
      'baz',
    ),
  );
  form_set_cache($form['#build_id'], $form, $form_state);

  // Clear expired entries from cache_form, which should include the entry we
  // just stored. Without this, the form will still be retrieved from cache.
  cache_clear_all(NULL, 'cache_form');
  $cached_form_state = array();
  $cached_form = form_get_cache($form['#build_id'], $cached_form_state);
  $this
    ->assertNull($cached_form, 'Expired form was not returned from cache.');
  $this
    ->assertTrue(empty($cached_form_state), 'No data retrieved from cache for expired form.');
}