diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php
index c7f4275..29fe81c 100644
--- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php
+++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php
@@ -35,13 +35,6 @@
   const TRANSLATION_CREATED = 2;
 
   /**
-   * Local cache holding the value of the bundle field.
-   *
-   * @var string
-   */
-  protected $bundle;
-
-  /**
    * The plain data values of the contained fields.
    *
    * This always holds the original, unchanged values of the entity. The values
@@ -129,11 +122,18 @@
   protected $isDefaultRevision = TRUE;
 
   /**
+   * Holds entity keys like the ID, bundle and revision ID.
+   *
+   * @var array
+   */
+  protected $entityKeysCache = array();
+
+  /**
    * Overrides Entity::__construct().
    */
   public function __construct(array $values, $entity_type, $bundle = FALSE, $translations = array()) {
     $this->entityTypeId = $entity_type;
-    $this->bundle = $bundle ? $bundle : $this->entityTypeId;
+    $this->entityKeysCache['bundle'] = $bundle ? $bundle : $this->entityTypeId;
     $this->languages = language_list(Language::STATE_ALL);
 
     foreach ($values as $key => $value) {
@@ -190,7 +190,7 @@ public function isDefaultRevision($new_value = NULL) {
    * {@inheritdoc}
    */
   public function getRevisionId() {
-    return NULL;
+    return $this->getFromEntityKeyCache('revision');
   }
 
   /**
@@ -353,21 +353,21 @@ public function __wakeup() {
    * {@inheritdoc}
    */
   public function id() {
-    return $this->id->value;
+    return $this->getFromEntityKeyCache('id');
   }
 
   /**
    * {@inheritdoc}
    */
   public function bundle() {
-    return $this->bundle;
+    return $this->getFromEntityKeyCache('bundle');
   }
 
   /**
-   * Overrides Entity::uuid().
+   * {inheritdoc}
    */
   public function uuid() {
-    return $this->get('uuid')->value;
+    return $this->getFromEntityKeyCache('uuid');
   }
 
   /**
@@ -485,7 +485,7 @@ public function getPropertyDefinition($name) {
    */
   public function getPropertyDefinitions() {
     if (!isset($this->fieldDefinitions)) {
-      $bundle = $this->bundle != $this->entityTypeId ? $this->bundle : NULL;
+      $bundle = $this->bundle() != $this->entityTypeId ? $this->bundle() : NULL;
       $this->fieldDefinitions = \Drupal::entityManager()->getFieldDefinitions($this->entityTypeId, $bundle);
     }
     return $this->fieldDefinitions;
@@ -602,6 +602,9 @@ public function onChange($name) {
       }
       $this->updateFieldLangcodes($this->defaultLangcode);
     }
+    if (isset($this->entityKeysCache[$name])) {
+      unset($this->entityKeysCache[$name]);
+    }
   }
 
   /**
@@ -717,7 +720,7 @@ public function addTranslation($langcode, array $values = array()) {
     // Instantiate a new empty entity so default values will be populated in the
     // specified language.
     $info = $this->getEntityType();
-    $default_values = array($info->getKey('bundle') => $this->bundle, 'langcode' => $langcode);
+    $default_values = array($info->getKey('bundle') => $this->bundle(), 'langcode' => $langcode);
     $entity = \Drupal::entityManager()
       ->getStorageController($this->getEntityTypeId())
       ->create($default_values);
@@ -987,4 +990,28 @@ public function referencedEntities() {
     return $referenced_entities;
   }
 
+  /**
+   * Returns the value of the given entity key, if defined.
+   *
+   * @param $key
+   *   Name of the entity key, for example id, revision or bundle.
+   *
+   * @return mixed
+   *   The value of the entity key, NULL if not defined.
+   */
+  protected function getFromEntityKeyCache($key) {
+    if (!isset($this->entityKeysCache[$key]) || !array_key_exists($key, $this->entityKeysCache)) {
+      if ($this->getEntityType()->hasKey($key)) {
+        $field_item = $this->get($this->getEntityType()->getKey($key))->first();
+        $property = $field_item->getMainPropertyName();
+        $this->entityKeysCache[$key] = $field_item->$property;
+      }
+      else {
+        $this->entityKeysCache[$key] = NULL;
+      }
+
+    }
+    return $this->entityKeysCache[$key];
+  }
+
 }
diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php
index 714aeeb..c656316 100644
--- a/core/lib/Drupal/Core/Entity/Entity.php
+++ b/core/lib/Drupal/Core/Entity/Entity.php
@@ -16,6 +16,13 @@
 abstract class Entity implements EntityInterface {
 
   /**
+   * Local cache holding the value of the ID key name from annotation.
+   *
+   * @var string
+   */
+  protected $idKeyName;
+
+  /**
    * The language code of the entity's default language.
    *
    * @var string
@@ -64,7 +71,10 @@ public function __construct(array $values, $entity_type) {
    * {@inheritdoc}
    */
   public function id() {
-    return isset($this->id) ? $this->id : NULL;
+    if (!isset($this->idKeyName)) {
+      $this->idKeyName = $this->getEntityType()->getKey('id');
+    }
+    return isset($this->{$this->idKeyName}) ? $this->{$this->idKeyName} : NULL;
   }
 
   /**
diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Entity/Feed.php b/core/modules/aggregator/lib/Drupal/aggregator/Entity/Feed.php
index 61eae79..a384862 100644
--- a/core/modules/aggregator/lib/Drupal/aggregator/Entity/Feed.php
+++ b/core/modules/aggregator/lib/Drupal/aggregator/Entity/Feed.php
@@ -46,13 +46,6 @@
 class Feed extends ContentEntityBase implements FeedInterface {
 
   /**
-   * Implements Drupal\Core\Entity\EntityInterface::id().
-   */
-  public function id() {
-    return $this->get('fid')->value;
-  }
-
-  /**
    * Implements Drupal\Core\Entity\EntityInterface::label().
    */
   public function label() {
diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Entity/Item.php b/core/modules/aggregator/lib/Drupal/aggregator/Entity/Item.php
index e48e45d9..f20bf9d 100644
--- a/core/modules/aggregator/lib/Drupal/aggregator/Entity/Item.php
+++ b/core/modules/aggregator/lib/Drupal/aggregator/Entity/Item.php
@@ -33,13 +33,6 @@
 class Item extends ContentEntityBase implements ItemInterface {
 
   /**
-   * Implements Drupal\Core\Entity\EntityInterface::id().
-   */
-  public function id() {
-    return $this->get('iid')->value;
-  }
-
-  /**
    * Implements Drupal\Core\Entity\EntityInterface::label().
    */
   public function label() {
diff --git a/core/modules/comment/lib/Drupal/comment/Entity/Comment.php b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php
index 906e6e7..b291c5a 100644
--- a/core/modules/comment/lib/Drupal/comment/Entity/Comment.php
+++ b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php
@@ -209,13 +209,6 @@ protected function init() {
   }
 
   /**
-   * Implements Drupal\Core\Entity\EntityInterface::id().
-   */
-  public function id() {
-    return $this->get('cid')->value;
-  }
-
-  /**
    * {@inheritdoc}
    */
   public function preSave(EntityStorageControllerInterface $storage_controller) {
diff --git a/core/modules/contact/lib/Drupal/contact/Entity/Message.php b/core/modules/contact/lib/Drupal/contact/Entity/Message.php
index 573b304..c03d5ea 100644
--- a/core/modules/contact/lib/Drupal/contact/Entity/Message.php
+++ b/core/modules/contact/lib/Drupal/contact/Entity/Message.php
@@ -37,7 +37,7 @@
 class Message extends ContentEntityBase implements MessageInterface {
 
   /**
-   * Overrides Drupal\Core\Entity\Entity::id().
+   * {@inheritdoc}
    */
   public function id() {
     return NULL;
diff --git a/core/modules/editor/lib/Drupal/editor/Entity/Editor.php b/core/modules/editor/lib/Drupal/editor/Entity/Editor.php
index 27346c9..1d6bbd6 100644
--- a/core/modules/editor/lib/Drupal/editor/Entity/Editor.php
+++ b/core/modules/editor/lib/Drupal/editor/Entity/Editor.php
@@ -58,13 +58,6 @@ class Editor extends ConfigEntityBase implements EditorInterface {
   public $image_upload = array();
 
   /**
-   * Overrides Drupal\Core\Entity\Entity::id().
-   */
-  public function id() {
-    return $this->format;
-  }
-
-  /**
    * Overrides Drupal\Core\Entity\Entity::__construct()
    */
   public function __construct(array $values, $entity_type) {
diff --git a/core/modules/file/lib/Drupal/file/Entity/File.php b/core/modules/file/lib/Drupal/file/Entity/File.php
index 62a754b..104c39e 100644
--- a/core/modules/file/lib/Drupal/file/Entity/File.php
+++ b/core/modules/file/lib/Drupal/file/Entity/File.php
@@ -48,13 +48,6 @@ class File extends ContentEntityBase implements FileInterface {
   /**
    * {@inheritdoc}
    */
-  public function id() {
-    return $this->get('fid')->value;
-  }
-
-  /**
-   * {@inheritdoc}
-   */
   public function getFilename() {
     return $this->get('filename')->value;
   }
diff --git a/core/modules/filter/lib/Drupal/filter/Entity/FilterFormat.php b/core/modules/filter/lib/Drupal/filter/Entity/FilterFormat.php
index fb6292b..3c2a5ec 100644
--- a/core/modules/filter/lib/Drupal/filter/Entity/FilterFormat.php
+++ b/core/modules/filter/lib/Drupal/filter/Entity/FilterFormat.php
@@ -136,13 +136,6 @@ class FilterFormat extends ConfigEntityBase implements FilterFormatInterface {
   /**
    * {@inheritdoc}
    */
-  public function id() {
-    return $this->format;
-  }
-
-  /**
-   * {@inheritdoc}
-   */
   public function filters($instance_id = NULL) {
     if (!isset($this->filterBag)) {
       $this->filterBag = new FilterBag(\Drupal::service('plugin.manager.filter'), $this->filters);
diff --git a/core/modules/image/lib/Drupal/image/Entity/ImageStyle.php b/core/modules/image/lib/Drupal/image/Entity/ImageStyle.php
index 506f660..14cedd6 100644
--- a/core/modules/image/lib/Drupal/image/Entity/ImageStyle.php
+++ b/core/modules/image/lib/Drupal/image/Entity/ImageStyle.php
@@ -90,13 +90,6 @@ class ImageStyle extends ConfigEntityBase implements ImageStyleInterface {
   protected $effectsBag;
 
   /**
-   * Overrides Drupal\Core\Entity\Entity::id().
-   */
-  public function id() {
-    return $this->name;
-  }
-
-  /**
    * {@inheritdoc}
    */
   public function postSave(EntityStorageControllerInterface $storage_controller, $update = TRUE) {
diff --git a/core/modules/node/lib/Drupal/node/Entity/Node.php b/core/modules/node/lib/Drupal/node/Entity/Node.php
index 017e89c..dd07482 100644
--- a/core/modules/node/lib/Drupal/node/Entity/Node.php
+++ b/core/modules/node/lib/Drupal/node/Entity/Node.php
@@ -63,13 +63,6 @@
 class Node extends ContentEntityBase implements NodeInterface {
 
   /**
-   * Implements Drupal\Core\Entity\EntityInterface::id().
-   */
-  public function id() {
-    return $this->get('nid')->value;
-  }
-
-  /**
    * Overrides Drupal\Core\Entity\Entity::getRevisionId().
    */
   public function getRevisionId() {
diff --git a/core/modules/node/lib/Drupal/node/Entity/NodeType.php b/core/modules/node/lib/Drupal/node/Entity/NodeType.php
index 2b36eb5..49d068d 100644
--- a/core/modules/node/lib/Drupal/node/Entity/NodeType.php
+++ b/core/modules/node/lib/Drupal/node/Entity/NodeType.php
@@ -137,13 +137,6 @@ class NodeType extends ConfigEntityBase implements NodeTypeInterface {
   /**
    * {@inheritdoc}
    */
-  public function id() {
-    return $this->type;
-  }
-
-  /**
-   * {@inheritdoc}
-   */
   public function getModuleSettings($module) {
     if (isset($this->settings[$module]) && is_array($this->settings[$module])) {
       return $this->settings[$module];
diff --git a/core/modules/rest/tests/Drupal/rest/Tests/CollectRoutesTest.php b/core/modules/rest/tests/Drupal/rest/Tests/CollectRoutesTest.php
index 05c6d5d..c15a238 100644
--- a/core/modules/rest/tests/Drupal/rest/Tests/CollectRoutesTest.php
+++ b/core/modules/rest/tests/Drupal/rest/Tests/CollectRoutesTest.php
@@ -30,6 +30,13 @@ class CollectRoutesTest extends UnitTestCase {
    */
   protected $routes;
 
+  /**
+   * The mocked entity manager.
+   *
+   * @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
+   */
+  protected $entityManager;
+
   public static function getInfo() {
     return array(
       'name' => 'routes: REST export plugin',
@@ -57,16 +64,6 @@ protected function setUp() {
     $container->set('content_negotiation', $content_negotiation);
     $container->set('request', $request);
 
-    $this->view = $this->getMock('\Drupal\views\Entity\View', array('initHandlers'), array(
-      array('id' => 'test_view'),
-      'view',
-    ));
-
-    $view_executable = $this->getMock('\Drupal\views\ViewExecutable', array('initHandlers'), array(), '', FALSE);
-
-    $view_executable->storage = $this->view;
-    $view_executable->argument = array();
-
     $display_manager = $this->getMockBuilder('\Drupal\views\Plugin\ViewsPluginManager')
       ->disableOriginalConstructor()
       ->getMock();
@@ -90,8 +87,34 @@ protected function setUp() {
       ->getMock();
     $container->set('plugin.manager.views.style', $style_manager);
 
+    $entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
+
+    $entity_type = $this->getMock('Drupal\Core\Entity\EntityTypeInterface');
+    $entity_type->expects($this->any())
+      ->method('getKey')
+      ->with('id')
+      ->will($this->returnValue('id'));
+
+    $entity_manager
+      ->expects($this->any())
+      ->method('getDefinition')
+      ->with('view')
+      ->will($this->returnValue($entity_type));
+    $container->set('entity.manager', $entity_manager);
+
     \Drupal::setContainer($container);
 
+    $this->view = $this->getMock('\Drupal\views\Entity\View', array('initHandlers'), array(
+      array('id' => 'test_view'),
+      'view',
+    ));
+
+    $view_executable = $this->getMock('\Drupal\views\ViewExecutable', array('initHandlers'), array(), '', FALSE);
+
+    $view_executable->storage = $this->view;
+    $view_executable->argument = array();
+
+
     $this->restExport = RestExport::create($container, array(), "test_routes", array());
     $this->restExport->view = $view_executable;
 
diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Term.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Term.php
index 32e0e9c..78275fb 100644
--- a/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Term.php
+++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Term.php
@@ -120,13 +120,6 @@ class Term extends ContentEntityBase implements TermInterface {
   public $parent;
 
   /**
-   * Implements Drupal\Core\Entity\EntityInterface::id().
-   */
-  public function id() {
-    return $this->get('tid')->value;
-  }
-
-  /**
    * {@inheritdoc}
    */
   protected function init() {
diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Vocabulary.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Vocabulary.php
index 7857c07..89bb621 100644
--- a/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Vocabulary.php
+++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Vocabulary.php
@@ -96,13 +96,6 @@ class Vocabulary extends ConfigEntityBase implements VocabularyInterface {
   /**
    * {@inheritdoc}
    */
-  public function id() {
-    return $this->vid;
-  }
-
-  /**
-   * {@inheritdoc}
-   */
   public function postSave(EntityStorageControllerInterface $storage_controller, $update = TRUE) {
     parent::postSave($storage_controller, $update);
 
diff --git a/core/modules/user/lib/Drupal/user/Entity/User.php b/core/modules/user/lib/Drupal/user/Entity/User.php
index f9db482..432aa36 100644
--- a/core/modules/user/lib/Drupal/user/Entity/User.php
+++ b/core/modules/user/lib/Drupal/user/Entity/User.php
@@ -54,13 +54,6 @@ class User extends ContentEntityBase implements UserInterface {
   /**
    * {@inheritdoc}
    */
-  public function id() {
-    return $this->get('uid')->value;
-  }
-
-  /**
-   * {@inheritdoc}
-   */
   public function isNew() {
     return !empty($this->enforceIsNew) || $this->id() === NULL;
   }
diff --git a/core/modules/user/tests/Drupal/user/Tests/Views/Argument/RolesRidTest.php b/core/modules/user/tests/Drupal/user/Tests/Views/Argument/RolesRidTest.php
index a5c9226..600062f 100644
--- a/core/modules/user/tests/Drupal/user/Tests/Views/Argument/RolesRidTest.php
+++ b/core/modules/user/tests/Drupal/user/Tests/Views/Argument/RolesRidTest.php
@@ -34,6 +34,24 @@ public static function getInfo() {
    * @see \Drupal\user\Plugin\views\argument\RolesRid::title_query()
    */
   public function testTitleQuery() {
+    $entity_type = $this->getMock('Drupal\Core\Entity\EntityTypeInterface');
+    $entity_type->expects($this->any())
+      ->method('getKey')
+      ->will($this->returnValueMap(array(array('id', 'id'), array('label', 'label'))));
+
+    $entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
+    $entity_manager->expects($this->any())
+      ->method('getDefinition')
+      ->with($this->equalTo('user_role'))
+      ->will($this->returnValue($entity_type));
+
+    // @todo \Drupal\Core\Entity\Entity::entityType() uses a global call to
+    //   entity_get_info(), which in turn wraps \Drupal::entityManager(). Set
+    //   the entity manager until this is fixed.
+    $container = new ContainerBuilder();
+    $container->set('entity.manager', $entity_manager);
+    \Drupal::setContainer($container);
+
     $role1 = new Role(array(
       'id' => 'test_rid_1',
       'label' => 'test rid 1'
@@ -53,31 +71,12 @@ public function testTitleQuery() {
         array(array('test_rid_1', 'test_rid_2'), array('test_rid_1' => $role1, 'test_rid_2' => $role2)),
       )));
 
-    $entity_type = $this->getMock('Drupal\Core\Entity\EntityTypeInterface');
-    $entity_type->expects($this->any())
-      ->method('getKey')
-      ->with('label')
-      ->will($this->returnValue('label'));
-
-    $entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
-    $entity_manager->expects($this->any())
-      ->method('getDefinition')
-      ->with($this->equalTo('user_role'))
-      ->will($this->returnValue($entity_type));
-
     $entity_manager
       ->expects($this->once())
       ->method('getStorageController')
       ->with($this->equalTo('user_role'))
       ->will($this->returnValue($role_storage_controller));
 
-    // @todo \Drupal\Core\Entity\Entity::entityType() uses a global call to
-    //   entity_get_info(), which in turn wraps \Drupal::entityManager(). Set
-    //   the entity manager until this is fixed.
-    $container = new ContainerBuilder();
-    $container->set('entity.manager', $entity_manager);
-    \Drupal::setContainer($container);
-
     $roles_rid_argument = new RolesRid(array(), 'users_roles_rid', array(), $entity_manager);
 
     $roles_rid_argument->value = array();
diff --git a/core/modules/views/tests/Drupal/views/Tests/Plugin/field/CounterTest.php b/core/modules/views/tests/Drupal/views/Tests/Plugin/field/CounterTest.php
index 50028a4..3b8bbeb 100644
--- a/core/modules/views/tests/Drupal/views/Tests/Plugin/field/CounterTest.php
+++ b/core/modules/views/tests/Drupal/views/Tests/Plugin/field/CounterTest.php
@@ -8,6 +8,7 @@
 namespace Drupal\views\Tests\Plugin\field;
 
 use Drupal\Component\Utility\String;
+use Drupal\Core\DependencyInjection\ContainerBuilder;
 use Drupal\Tests\UnitTestCase;
 use Drupal\views\Entity\View;
 use Drupal\views\Plugin\views\field\Counter;
@@ -71,6 +72,22 @@ public static function getInfo() {
   protected function setUp() {
     parent::setUp();
 
+    $entity_type = $this->getMock('Drupal\Core\Entity\EntityTypeInterface');
+    $entity_type->expects($this->any())
+      ->method('getKey')
+      ->with('id')
+      ->will($this->returnValue('id'));
+
+    $entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
+    $entity_manager->expects($this->any())
+      ->method('getDefinition')
+      ->with($this->equalTo('view'))
+      ->will($this->returnValue($entity_type));
+
+    $container = new ContainerBuilder();
+    $container->set('entity.manager', $entity_manager);
+    \Drupal::setContainer($container);
+
     // Setup basic stuff like the view and the display.
     $config = array();
     $config['display']['default'] = array(
diff --git a/core/modules/views/tests/Drupal/views/Tests/ViewExecutableUnitTest.php b/core/modules/views/tests/Drupal/views/Tests/ViewExecutableUnitTest.php
index 6a18691..dd22a6f 100644
--- a/core/modules/views/tests/Drupal/views/Tests/ViewExecutableUnitTest.php
+++ b/core/modules/views/tests/Drupal/views/Tests/ViewExecutableUnitTest.php
@@ -7,6 +7,7 @@
 
 namespace Drupal\views\Tests;
 
+use Drupal\Core\DependencyInjection\ContainerBuilder;
 use Drupal\Tests\UnitTestCase;
 use Drupal\views\Entity\View;
 use Drupal\views\ViewExecutable;
@@ -30,6 +31,22 @@ public static function getInfo() {
    * Tests the buildThemeFunctions() method.
    */
   public function testBuildThemeFunctions() {
+    $entity_type = $this->getMock('Drupal\Core\Entity\EntityTypeInterface');
+    $entity_type->expects($this->any())
+      ->method('getKey')
+      ->with('id')
+      ->will($this->returnValue('id'));
+
+    $entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
+    $entity_manager->expects($this->any())
+      ->method('getDefinition')
+      ->with($this->equalTo('view'))
+      ->will($this->returnValue($entity_type));
+
+    $container = new ContainerBuilder();
+    $container->set('entity.manager', $entity_manager);
+    \Drupal::setContainer($container);
+
     $config = array(
       'id' => 'test_view',
       'tag' => 'OnE, TWO, and three',
diff --git a/core/modules/views/tests/Drupal/views/Tests/ViewsTest.php b/core/modules/views/tests/Drupal/views/Tests/ViewsTest.php
index 9466c0b..58441a3 100644
--- a/core/modules/views/tests/Drupal/views/Tests/ViewsTest.php
+++ b/core/modules/views/tests/Drupal/views/Tests/ViewsTest.php
@@ -33,6 +33,22 @@ protected function setUp() {
     $user = $this->getMock('Drupal\Core\Session\AccountInterface');
     $container->set('views.executable', new ViewExecutableFactory($user));
 
+    $entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
+    $container->set('entity.manager', $entity_manager);
+
+    $entity_type = $this->getMock('Drupal\Core\Entity\EntityTypeInterface');
+    $entity_type->expects($this->any())
+      ->method('getKey')
+      ->with('id')
+      ->will($this->returnValue('id'));
+
+    $entity_manager->expects($this->any())
+      ->method('getDefinition')
+      ->with($this->equalTo('view'))
+      ->will($this->returnValue($entity_type));
+
+    \Drupal::setContainer($container);
+
     $this->view = new View(array('id' => 'test_view'), 'view');
 
     $view_storage_controller = $this->getMockBuilder('Drupal\views\ViewStorageController')
@@ -43,14 +59,11 @@ protected function setUp() {
       ->with('test_view')
       ->will($this->returnValue($this->view));
 
-    $entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
     $entity_manager->expects($this->once())
       ->method('getStorageController')
       ->with('view')
       ->will($this->returnValue($view_storage_controller));
-    $container->set('entity.manager', $entity_manager);
 
-    \Drupal::setContainer($container);
   }
 
   /**
diff --git a/core/modules/views_ui/tests/Drupal/views_ui/Tests/ViewListControllerTest.php b/core/modules/views_ui/tests/Drupal/views_ui/Tests/ViewListControllerTest.php
index 534f824..c2c7b6b 100644
--- a/core/modules/views_ui/tests/Drupal/views_ui/Tests/ViewListControllerTest.php
+++ b/core/modules/views_ui/tests/Drupal/views_ui/Tests/ViewListControllerTest.php
@@ -121,6 +121,20 @@ public function testBuildRowEntityList() {
     $container->set('plugin.manager.views.display', $display_manager);
     \Drupal::setContainer($container);
 
+    $entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
+    $container->set('entity.manager', $entity_manager);
+
+    $entity_type = $this->getMock('Drupal\Core\Entity\EntityTypeInterface');
+    $entity_type->expects($this->any())
+      ->method('getKey')
+      ->with('id')
+      ->will($this->returnValue('id'));
+
+    $entity_manager->expects($this->any())
+      ->method('getDefinition')
+      ->with($this->equalTo('view'))
+      ->will($this->returnValue($entity_type));
+
     // Setup a view list controller with a mocked buildOperations method,
     // because t() is called on there.
     $entity_type = $this->getMock('Drupal\Core\Entity\EntityTypeInterface');
diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php
index 96f482d..1020e39 100644
--- a/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php
@@ -62,8 +62,6 @@ protected function setUp() {
    * @dataProvider providerTestUrlInfo
    */
   public function testUrlInfo($entity_class, $link_template, $expected) {
-    /** @var $entity \Drupal\Core\Entity\EntityInterface */
-    $entity = new $entity_class(array('id' => 'test_entity_id'), 'test_entity_type');
 
     $entity_type = $this->getMock('Drupal\Core\Entity\EntityTypeInterface');
     $entity_type->expects($this->once())
@@ -72,12 +70,20 @@ public function testUrlInfo($entity_class, $link_template, $expected) {
         'edit-form' => 'test_entity_type.edit',
       )));
 
+    $entity_type->expects($this->any())
+      ->method('getKey')
+      ->with('id')
+      ->will($this->returnValue('id'));
+
     $this->entityManager
       ->expects($this->any())
       ->method('getDefinition')
       ->with('test_entity_type')
       ->will($this->returnValue($entity_type));
 
+    /** @var $entity \Drupal\Core\Entity\EntityInterface */
+    $entity = new $entity_class(array('id' => 'test_entity_id'), 'test_entity_type');
+
     // If no link template is given, call without a value to test the default.
     if ($link_template) {
       $uri = $entity->urlInfo($link_template);
@@ -120,6 +126,19 @@ public function providerTestUrlInfo() {
    * @expectedException \Drupal\Core\Entity\EntityMalformedException
    */
   public function testUrlInfoForNewEntity() {
+    $entity_type = $this->getMock('Drupal\Core\Entity\EntityTypeInterface');
+
+    $entity_type->expects($this->any())
+      ->method('getKey')
+      ->with('id')
+      ->will($this->returnValue('id'));
+
+    $this->entityManager
+      ->expects($this->once())
+      ->method('getDefinition')
+      ->with('test_entity_type')
+      ->will($this->returnValue($entity_type));
+
     $entity = new TestEntity(array(), 'test_entity_type');
     $entity->urlInfo();
   }
@@ -137,8 +156,13 @@ public function testUrl() {
         'canonical' => 'test_entity_type.view',
       )));
 
+    $entity_type->expects($this->any())
+      ->method('getKey')
+      ->with('id')
+      ->will($this->returnValue('id'));
+
     $this->entityManager
-      ->expects($this->exactly(4))
+      ->expects($this->exactly(7))
       ->method('getDefinition')
       ->with('test_entity_type')
       ->will($this->returnValue($entity_type));
@@ -189,8 +213,13 @@ public function testUrlForAdminForm() {
       ->method('getBundleEntityType')
       ->will($this->returnValue('test_entity_type_bundle'));
 
+    $entity_type->expects($this->any())
+      ->method('getKey')
+      ->with('id')
+      ->will($this->returnValue('id'));
+
     $this->entityManager
-      ->expects($this->exactly(3))
+      ->expects($this->exactly(4))
       ->method('getDefinition')
       ->with('test_entity_type')
       ->will($this->returnValue($entity_type));
@@ -223,8 +252,13 @@ public function testGetSystemPath() {
         'canonical' => 'test_entity_type.view',
       )));
 
+    $entity_type->expects($this->any())
+      ->method('getKey')
+      ->with('id')
+      ->will($this->returnValue('id'));
+
     $this->entityManager
-      ->expects($this->exactly(3))
+      ->expects($this->exactly(5))
       ->method('getDefinition')
       ->with('test_entity_type')
       ->will($this->returnValue($entity_type));
