Error message
You are browsing documentation for drupal 7.x, which is not supported anymore. Read the updated version of this page for drupal 11.x (the latest version).function EntityFieldQueryTestCase::testEntityFieldQueryRouting
Tests the routing feature of EntityFieldQuery.
File
-
modules/
simpletest/ tests/ entity_query.test, line 1308
Class
- EntityFieldQueryTestCase
- Tests EntityFieldQuery.
Code
function testEntityFieldQueryRouting() {
// Entity-only query.
$query = new EntityFieldQuery ();
$query->entityCondition ('entity_type', 'test_entity_bundle_key');
$this->assertIdentical ($query->queryCallback (), array(
$query,
'propertyQuery',
), 'Entity-only queries are handled by the propertyQuery handler.');
// Field-only query.
$query = new EntityFieldQuery ();
$query->fieldCondition ($this->fields [0], 'value', '3');
$this->assertIdentical ($query->queryCallback (), 'field_sql_storage_field_storage_query', 'Pure field queries are handled by the Field storage handler.');
// Mixed entity and field query.
$query = new EntityFieldQuery ();
$query->entityCondition ('entity_type', 'test_entity_bundle_key')
->fieldCondition ($this->fields [0], 'value', '3');
$this->assertIdentical ($query->queryCallback (), 'field_sql_storage_field_storage_query', 'Mixed queries are handled by the Field storage handler.');
// Overriding with $query->executeCallback.
$query = new EntityFieldQuery ();
$query->entityCondition ('entity_type', 'test_entity_bundle_key');
$query->executeCallback = 'field_test_dummy_field_storage_query';
$this->assertEntityFieldQuery ($query, array(
array(
'user',
1,
),
), 'executeCallback can override the query handler.');
// Overriding with $query->executeCallback via hook_entity_query_alter().
$query = new EntityFieldQuery ();
$query->entityCondition ('entity_type', 'test_entity_bundle_key');
// Add a flag that will be caught by field_test_entity_query_alter().
variable_set ('field_test_entity_query_alter_execute_callback', TRUE);
$this->assertEntityFieldQuery ($query, array(
array(
'user',
1,
),
), 'executeCallback can override the query handler when set in a hook_entity_query_alter().');
variable_set ('field_test_entity_query_alter_execute_callback', FALSE);
// Mixed-storage queries.
$query = new EntityFieldQuery ();
$query->fieldCondition ($this->fields [0], 'value', '3')
->fieldCondition ($this->fields [1], 'shape', 'squ', 'STARTS_WITH');
// Alter the storage of the field.
$query->fields [1]['storage']['module'] = 'dummy_storage';
try {
$query->queryCallback ();
} catch (EntityFieldQueryException $exception) {
$pass = $exception->getMessage() == t ("Can't handle more than one field storage engine");
}
$this->assertTrue ($pass, 'Cannot query across field storage engines.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.