You are here

function FlagEntityFieldQueryTestCase::testEntityFieldQuery in Flag 7.3

Test use of EntityFieldQuery with flagging entities.

File

tests/flag.test, line 1219
Tests for the Flag module.

Class

FlagEntityFieldQueryTestCase
Test use of EntityFieldQueries with flagging entities.

Code

function testEntityFieldQuery() {
  $node_settings = array(
    'title' => $this
      ->randomName(),
    'body' => array(
      LANGUAGE_NONE => array(
        array(
          'value' => $this
            ->randomName(32),
        ),
      ),
    ),
    'uid' => 1,
    'type' => 'article',
    'is_new' => TRUE,
  );
  $node = $this
    ->drupalCreateNode($node_settings);
  flag('flag', 'test_flag_1', $node->nid, $this->flag_unflag_user);
  flag('flag', 'test_flag_2', $node->nid, $this->flag_unflag_user);
  $query = new EntityFieldQuery();
  $query
    ->entityCondition('entity_type', 'flagging')
    ->entityCondition('bundle', 'test_flag_1');
  $flagged = $query
    ->execute();
  $this
    ->assertEqual(count($flagged['flagging']), 1);
  $query = new EntityFieldQuery();
  $query
    ->entityCondition('entity_type', 'flagging')
    ->entityCondition('bundle', 'test%', 'like');
  $flagged = $query
    ->execute();
  $this
    ->assertEqual(count($flagged['flagging']), 2);
  $query = new EntityFieldQuery();
  $query
    ->entityCondition('entity_type', 'flagging')
    ->entityCondition('bundle', array(
    'test_flag_1',
    'test_flag_2',
  ), 'IN');
  $this
    ->assertEqual(count($flagged['flagging']), 2);
}