Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
d472f98e
Commit
d472f98e
authored
Jun 16, 2009
by
Dries Buytaert
Browse files
- Patch
#456488
by yched: better tests for field caching.
parent
2920848d
Changes
1
Hide whitespace changes
Inline
Side-by-side
modules/field/field.test
View file @
d472f98e
...
...
@@ -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'
));
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment