1.20.x entity_query.test EntityFieldQueryTestCase::testEntityFieldQueryTranslatable()

Tests querying translatable fields.

File

modules/entity/tests/entity_query.test, line 1045
Unit test file for the entity API.

Class

EntityFieldQueryTestCase
Tests EntityFieldQuery.

Code

function testEntityFieldQueryTranslatable() {

  // Make a test field translatable AND cardinality one.
  $this->fields[0]['translatable'] = TRUE;
  $this->fields[0]['cardinality'] = 1;
  field_update_field($this->fields[0]);
  field_test_entity_info_translatable('test_entity', TRUE);

  // Create more items with different languages.
  $entity = entity_create('test_entity', array());
  $entity->ftid = 1;
  $entity->ftvid = 1;
  $entity->fttype = 'test_bundle';

  // Set fields in two languages with one field value.
  foreach (array(LANGUAGE_NONE, 'en') as $langcode) {
    $entity->{$this->field_names[0]}[$langcode][0]['value'] = 1234;
  }

  field_attach_update('test_entity', $entity);

  // Look up number of results when querying a single entity with multilingual
  // field values.
  $query = new EntityFieldQuery();
  $query_count = $query
  ->entityCondition('entity_type', 'test_entity')
    ->entityCondition('bundle', 'test_bundle')
    ->entityCondition('entity_id', '1')
    ->fieldCondition($this->fields[0])
    ->count()
    ->execute();

  $this->assertEqual($query_count, 1, "Count on translatable cardinality one field is correct.");
}