From 83a6b9f19c4811a884d0bd2061397a64d2def00b Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Tue, 1 May 2012 12:45:50 +0900
Subject: [PATCH] Issue #1550454 by tim.plunkett, xjm: Fixed Regression:
 Following taxonomy entity conversion, Taxonomy EFQ causes warnings and
 notices.

---
 core/modules/entity/entity.module   | 11 ++++-----
 core/modules/taxonomy/taxonomy.test | 37 +++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 6 deletions(-)

diff --git a/core/modules/entity/entity.module b/core/modules/entity/entity.module
index b4e5b9b62087..a6599ebf73d5 100644
--- a/core/modules/entity/entity.module
+++ b/core/modules/entity/entity.module
@@ -177,17 +177,16 @@ function entity_extract_ids($entity_type, $entity) {
  *   An entity object, initialized with the IDs provided.
  */
 function entity_create_stub_entity($entity_type, $ids) {
-  $values = array();
+  $entity = new stdClass();
   $info = entity_get_info($entity_type);
-  $values[$info['entity keys']['id']] = $ids[0];
+  $entity->{$info['entity keys']['id']} = $ids[0];
   if (!empty($info['entity keys']['revision']) && isset($ids[1])) {
-    $values[$info['entity keys']['revision']] = $ids[1];
+    $entity->{$info['entity keys']['revision']} = $ids[1];
   }
   if (!empty($info['entity keys']['bundle']) && isset($ids[2])) {
-    $values[$info['entity keys']['bundle']] = $ids[2];
+    $entity->{$info['entity keys']['bundle']} = $ids[2];
   }
-  // @todo Once all entities are converted, just rely on entity_create().
-  return isset($info['entity class']) ? entity_create($entity_type, $values) : (object) $values;
+  return $entity;
 }
 
 /**
diff --git a/core/modules/taxonomy/taxonomy.test b/core/modules/taxonomy/taxonomy.test
index f352c7510ca1..a26d15f3e2a7 100644
--- a/core/modules/taxonomy/taxonomy.test
+++ b/core/modules/taxonomy/taxonomy.test
@@ -1913,3 +1913,40 @@ class TaxonomyThemeTestCase extends TaxonomyWebTestCase {
   }
 
 }
+
+/**
+ * Tests the functionality of EntityFieldQuery for taxonomy entities.
+ */
+class TaxonomyEFQTestCase extends TaxonomyWebTestCase {
+  public static function getInfo() {
+    return array(
+      'name' => 'Taxonomy EntityFieldQuery',
+      'description' => 'Verifies operation of a taxonomy-based EntityFieldQuery.',
+      'group' => 'Taxonomy',
+    );
+  }
+
+  function setUp() {
+    parent::setUp();
+    $this->admin_user = $this->drupalCreateUser(array('administer taxonomy'));
+    $this->drupalLogin($this->admin_user);
+    $this->vocabulary = $this->createVocabulary();
+  }
+
+  /**
+   * Tests that a basic taxonomy EntityFieldQuery works.
+   */
+  function testTaxonomyEFQ() {
+    $terms = array();
+    for ($i = 0; $i < 5; $i++) {
+      $term = $this->createTerm($this->vocabulary);
+      $terms[$term->tid] = $term;
+    }
+    $query = new EntityFieldQuery();
+    $query->entityCondition('entity_type', 'taxonomy_term');
+    $result = $query->execute();
+    $result = $result['taxonomy_term'];
+    asort($result);
+    $this->assertEqual(array_keys($terms), array_keys($result), 'Taxonomy terms were retrieved by EntityFieldQuery.');
+  }
+}
-- 
GitLab