Commit d472f98e authored by Dries's avatar Dries
Browse files

- Patch #456488 by yched: better tests for field caching.

parent 2920848d
......@@ -712,7 +712,7 @@ class FieldAttachTestCase extends DrupalWebTestCase {
*/
function testFieldAttachCache() {
// Initialize random values and a test entity.
$entity = field_test_create_stub_entity(1, 1, $this->instance['bundle']);
$entity_init = field_test_create_stub_entity(1, 1, $this->instance['bundle']);
$values = $this->_generateTestFieldValues($this->field['cardinality']);
$noncached_type = 'test_entity';
......@@ -720,57 +720,65 @@ class FieldAttachTestCase extends DrupalWebTestCase {
// Non-cacheable entity type.
$cid = "field:$noncached_type:{$entity->ftid}";
$cid = "field:$noncached_type:{$entity_init->ftid}";
// Check that no initial cache entry is present.
$this->assertFalse(cache_get($cid, 'cache_field'), t('Non-cached: no initial cache entry'));
// Save, and check that no cache entry is present.
$entity = clone($entity_init);
$entity->{$this->field_name} = $values;
field_attach_insert($noncached_type, $entity);
$this->assertFalse(cache_get($cid, 'cache_field'), t('Non-cached: no cache entry on insert'));
// Load, and check that no cache entry is present.
$entity = clone($entity_init);
field_attach_load($noncached_type, array($entity->ftid => $entity));
$this->assertFalse(cache_get($cid, 'cache_field'), t('Non-cached: no cache entry on load'));
// Cacheable entity type.
$cid = "field:$cached_type:{$entity->ftid}";
$cid = "field:$cached_type:{$entity_init->ftid}";
// Check that no initial cache entry is present.
$this->assertFalse(cache_get($cid, 'cache_field'), t('Cached: no initial cache entry'));
// Save, and check that no cache entry is present.
$entity = clone($entity_init);
$entity->{$this->field_name} = $values;
field_attach_insert($cached_type, $entity);
$this->assertFalse(cache_get($cid, 'cache_field'), t('Cached: no cache entry on insert'));
// Load, and check that a cache entry is present with the expected values.
$entity = clone($entity_init);
field_attach_load($cached_type, array($entity->ftid => $entity));
$cache = cache_get($cid, 'cache_field');
$this->assertEqual($cache->data[$this->field_name], $values, t('Cached: correct cache entry on load'));
// Update with different values, and check that the cache entry is wiped.
$values = $this->_generateTestFieldValues($this->field['cardinality']);
$entity = clone($entity_init);
$entity->{$this->field_name} = $values;
field_attach_update($cached_type, $entity);
$this->assertFalse(cache_get($cid, 'cache_field'), t('Cached: no cache entry on update'));
// Load, and check that a cache entry is present with the expected values.
$entity = clone($entity_init);
field_attach_load($cached_type, array($entity->ftid => $entity));
$cache = cache_get($cid, 'cache_field');
$this->assertEqual($cache->data[$this->field_name], $values, t('Cached: correct cache entry on load'));
// Create a new revision, and check that the cache entry is wiped.
$entity_init = field_test_create_stub_entity(1, 2, $this->instance['bundle']);
$values = $this->_generateTestFieldValues($this->field['cardinality']);
$entity = clone($entity_init);
$entity->{$this->field_name} = $values;
$entity->ftvid = 2;
field_attach_update($cached_type, $entity);
$cache = cache_get($cid, 'cache_field');
$this->assertFalse(cache_get($cid, 'cache_field'), t('Cached: no cache entry on new revision creation'));
// Load, and check that a cache entry is present with the expected values.
$entity = clone($entity_init);
field_attach_load($cached_type, array($entity->ftid => $entity));
$cache = cache_get($cid, 'cache_field');
$this->assertEqual($cache->data[$this->field_name], $values, t('Cached: correct cache entry on load'));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment