function OgEntityFieldQueryFieldConditionTestCase::testEntityFieldQueryFieldConditions in Organic groups 7.2
File
- ./
og.test, line 1760
Class
- OgEntityFieldQueryFieldConditionTestCase
- EntityFieldQuery FieldConditions with multiple group content entity types.
Code
function testEntityFieldQueryFieldConditions() {
// Query for all nodes with a field value of 'red'.
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'node');
$query
->entityCondition('bundle', $this->group_content_type);
$query
->fieldCondition('list_text', 'value', 'red');
$result = $query
->execute();
$this
->assertEqual(count($result['node']), 2, "The correct number of nodes was returned for the query with only the plain field.");
// Query for group content nodes.
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'node');
$query
->entityCondition('bundle', $this->group_content_type);
// Condition on the group audience field.
$query
->fieldCondition(OG_AUDIENCE_FIELD, 'target_id', $this->group1->nid);
$result = $query
->execute();
$this
->assertEqual(count($result['node']), 1, "The correct number of nodes was returned for the query with only the OG field condition.");
// Query for nodes in group 1 with a field value of 'red'.
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'node');
$query
->entityCondition('bundle', $this->group_content_type);
// Condition on the group audience field.
$query
->fieldCondition(OG_AUDIENCE_FIELD, 'target_id', $this->group1->nid);
$query
->fieldCondition('list_text', 'value', 'red');
$result = $query
->execute();
$this
->assertEqual(count($result['node']), 1, "The correct number of nodes was returned for the query with the OG field condition first.");
// Query for nodes in group 1 with a field value of 'red', but this time
// with the field conditions the other way round.
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'node');
$query
->entityCondition('bundle', $this->group_content_type);
$query
->fieldCondition('list_text', 'value', 'red');
// Condition on the group audience field.
$query
->fieldCondition(OG_AUDIENCE_FIELD, 'target_id', $this->group1->nid);
$result = $query
->execute();
$this
->assertEqual(count($result['node']), 1, "The correct number of nodes was returned for the query with the OG field condition second.");
}