Test basic functionality.
function testEntityQuery() {
$greetings = $this->greetings;
$figures = $this->figures;
$this->queryResults = $this->factory
->get('entity_test_mulrev')
->exists($greetings, 'tr')
->condition("{$figures}.color", 'red')
->sort('id')
->execute();
// As unit 0 was the red triangle and unit 2 was the turkish greeting,
// bit 0 and bit 2 needs to be set.
$this
->assertResult(5, 7, 13, 15);
$query = $this->factory
->get('entity_test_mulrev', 'OR')
->exists($greetings, 'tr')
->condition("{$figures}.color", 'red')
->sort('id');
$count_query = clone $query;
$this
->assertEqual(12, $count_query
->count()
->execute());
$this->queryResults = $query
->execute();
// Now bit 0 (1, 3, 5, 7, 9, 11, 13, 15) or bit 2 (4, 5, 6, 7, 12, 13, 14,
// 15) needs to be set.
$this
->assertResult(1, 3, 4, 5, 6, 7, 9, 11, 12, 13, 14, 15);
// Test cloning of query conditions.
$query = $this->factory
->get('entity_test_mulrev')
->condition("{$figures}.color", 'red')
->sort('id');
$cloned_query = clone $query;
$cloned_query
->condition("{$figures}.shape", 'circle');
// Bit 0 (1, 3, 5, 7, 9, 11, 13, 15) needs to be set.
$this->queryResults = $query
->execute();
$this
->assertResult(1, 3, 5, 7, 9, 11, 13, 15);
// No red color has a circle shape.
$this->queryResults = $cloned_query
->execute();
$this
->assertResult();
$query = $this->factory
->get('entity_test_mulrev');
$group = $query
->orConditionGroup()
->exists($greetings, 'tr')
->condition("{$figures}.color", 'red');
$this->queryResults = $query
->condition($group)
->condition("{$greetings}.value", 'sie', 'STARTS_WITH')
->sort('revision_id')
->execute();
// Bit 3 and (bit 0 or 2) -- the above 8 part of the above.
$this
->assertResult(9, 11, 12, 13, 14, 15);
// No figure has both the colors blue and red at the same time.
$this->queryResults = $this->factory
->get('entity_test_mulrev')
->condition("{$figures}.color", 'blue')
->condition("{$figures}.color", 'red')
->sort('id')
->execute();
$this
->assertResult();
// But an entity might have a red and a blue figure both.
$query = $this->factory
->get('entity_test_mulrev');
$group_blue = $query
->andConditionGroup()
->condition("{$figures}.color", 'blue');
$group_red = $query
->andConditionGroup()
->condition("{$figures}.color", 'red');
$this->queryResults = $query
->condition($group_blue)
->condition($group_red)
->sort('revision_id')
->execute();
// Unit 0 and unit 1, so bits 0 1.
$this
->assertResult(3, 7, 11, 15);
$this->queryResults = $this->factory
->get('entity_test_mulrev')
->exists("{$figures}.color")
->notExists("{$greetings}.value")
->sort('id')
->execute();
// Bit 0 or 1 is on but 2 and 3 are not.
$this
->assertResult(1, 2, 3);
// Now update the 'merhaba' string to xsiemax which is not a meaningful
// word but allows us to test revisions and string operations.
$ids = $this->factory
->get('entity_test_mulrev')
->condition("{$greetings}.value", 'merhaba')
->execute();
$entities = entity_load_multiple('entity_test_mulrev', $ids);
foreach ($entities as $entity) {
$entity
->setNewRevision();
$entity
->getTranslation('tr')->{$greetings}->value = 'xsiemax';
$entity
->save();
}
// When querying current revisions, this string is no longer found.
$this->queryResults = $this->factory
->get('entity_test_mulrev')
->condition("{$greetings}.value", 'merhaba')
->execute();
$this
->assertResult();
$this->queryResults = $this->factory
->get('entity_test_mulrev')
->condition("{$greetings}.value", 'merhaba')
->age(FIELD_LOAD_REVISION)
->sort('revision_id')
->execute();
// Bit 2 needs to be set.
// The keys must be 16-23 because the first batch stopped at 15 so the
// second started at 16 and eight entities were saved.
$assert = $this
->assertRevisionResult(range(16, 23), array(
4,
5,
6,
7,
12,
13,
14,
15,
));
$results = $this->factory
->get('entity_test_mulrev')
->condition("{$greetings}.value", 'siema', 'CONTAINS')
->sort('id')
->execute();
// This is the same as the previous one because xsiemax replaced merhaba
// but also it contains the entities that siema originally but not
// merhaba.
$assert = array_slice($assert, 0, 4, TRUE) + array(
8 => '8',
9 => '9',
10 => '10',
11 => '11',
) + array_slice($assert, 4, 4, TRUE);
$this
->assertIdentical($results, $assert);
$results = $this->factory
->get('entity_test_mulrev')
->condition("{$greetings}.value", 'siema', 'STARTS_WITH')
->execute();
// Now we only get the ones that originally were siema, entity id 8 and
// above.
$this
->assertIdentical($results, array_slice($assert, 4, 8, TRUE));
$results = $this->factory
->get('entity_test_mulrev')
->condition("{$greetings}.value", 'a', 'ENDS_WITH')
->execute();
// It is very important that we do not get the ones which only have
// xsiemax despite originally they were merhaba, ie. ended with a.
$this
->assertIdentical($results, array_slice($assert, 4, 8, TRUE));
$results = $this->factory
->get('entity_test_mulrev')
->condition("{$greetings}.value", 'a', 'ENDS_WITH')
->age(FIELD_LOAD_REVISION)
->sort('id')
->execute();
// Now we get everything.
$this
->assertIdentical($results, $assert);
}