diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php
index cd870f2..7d5b684 100644
--- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php
+++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php
@@ -7,9 +7,10 @@
 
 namespace Drupal\Core\Config\Entity;
 
+use Drupal\Component\Utility\String;
 use Drupal\Core\Entity\Entity;
-use Drupal\Core\Entity\EntityStorageControllerInterface;
 use Drupal\Core\Config\ConfigDuplicateUUIDException;
+use Drupal\Core\Entity\EntityStorageControllerInterface;
 
 /**
  * Defines a base configuration entity class.
@@ -95,6 +96,8 @@ public function get($property_name) {
    */
   public function set($property_name, $value) {
     $this->{$property_name} = $value;
+
+    return $this;
   }
 
   /**
@@ -131,6 +134,8 @@ public function status() {
    */
   public function setSyncing($syncing) {
     $this->isSyncing = $syncing;
+
+    return $this;
   }
 
   /**
@@ -153,7 +158,7 @@ public function createDuplicate() {
   /**
    * Helper callback for uasort() to sort configuration entities by weight and label.
    */
-  public static function sort($a, $b) {
+  public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b) {
     $a_weight = isset($a->weight) ? $a->weight : 0;
     $b_weight = isset($b->weight) ? $b->weight : 0;
     if ($a_weight == $b_weight) {
@@ -192,14 +197,14 @@ public function preSave(EntityStorageControllerInterface $storage_controller) {
       ->execute();
     $matched_entity = reset($matching_entities);
     if (!empty($matched_entity) && ($matched_entity != $this->id())) {
-      throw new ConfigDuplicateUUIDException(format_string('Attempt to save a configuration entity %id with UUID %uuid when this UUID is already used for %matched', array('%id' => $this->id(), '%uuid' => $this->uuid(), '%matched' => $matched_entity)));
+      throw new ConfigDuplicateUUIDException(String::format('Attempt to save a configuration entity %id with UUID %uuid when this UUID is already used for %matched', array('%id' => $this->id(), '%uuid' => $this->uuid(), '%matched' => $matched_entity)));
     }
 
     if (!$this->isNew()) {
       $original = $storage_controller->loadUnchanged($this->id());
       // Ensure that the UUID cannot be changed for an existing entity.
       if ($original && ($original->uuid() != $this->uuid())) {
-        throw new ConfigDuplicateUUIDException(format_string('Attempt to save a configuration entity %id with UUID %uuid when this entity already exists with UUID %original_uuid', array('%id' => $this->id(), '%uuid' => $this->uuid(), '%original_uuid' => $original->uuid())));
+        throw new ConfigDuplicateUUIDException(String::format('Attempt to save a configuration entity %id with UUID %uuid when this entity already exists with UUID %original_uuid', array('%id' => $this->id(), '%uuid' => $this->uuid(), '%original_uuid' => $original->uuid())));
       }
     }
   }
diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php
index 5aa737d..1f1c715 100644
--- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php
+++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php
@@ -28,23 +28,21 @@ public function getOriginalId();
    * @param string $id
    *   The new ID to set as original ID.
    *
-   * @return self
+   * @return $this
    */
   public function setOriginalId($id);
 
   /**
    * Enables the configuration entity.
    *
-   * @return \Drupal\Core\Config\Entity\ConfigEntityInterface
-   *   The configuration entity.
+   * @return $this
    */
   public function enable();
 
   /**
    * Disables the configuration entity.
    *
-   * @return \Drupal\Core\Config\Entity\ConfigEntityInterface
-   *   The configuration entity.
+   * @return $this
    */
   public function disable();
 
@@ -54,8 +52,7 @@ public function disable();
    * @param bool $status
    *   The status of the configuration entity.
    *
-   * @return \Drupal\Core\Config\Entity\ConfigEntityInterface
-   *   The class instance that this method is called on.
+   * @return $this
    */
   public function setStatus($status);
 
@@ -64,6 +61,8 @@ public function setStatus($status);
    *
    * @param bool $status
    *   The status of the sync flag.
+   *
+   * @return $this
    */
   public function setSyncing($status);
 
@@ -109,6 +108,8 @@ public function get($property_name);
    *   The name of the property that should be set.
    * @param mixed $value
    *   The value the property should be set to.
+   *
+   * @return $this
    */
   public function set($property_name, $value);
 
diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php
index 1572129..e11c9f1 100644
--- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php
+++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php
@@ -129,12 +129,19 @@
   protected $isDefaultRevision = TRUE;
 
   /**
+   * The typed data manager.
+   *
+   * @var \Drupal\Core\TypedData\TypedDataManager
+   */
+  protected $typedDataManager;
+
+  /**
    * 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->languages = language_list(Language::STATE_ALL);
+    $this->languages = $this->languageList(Language::STATE_ALL);
 
     foreach ($values as $key => $value) {
       // If the key matches an existing property set the value to the property
@@ -162,6 +169,26 @@ public function __construct(array $values, $entity_type, $bundle = FALSE, $trans
   }
 
   /**
+   * Wraps $this->languageList().
+   */
+  protected function languageList($flags = Language::STATE_CONFIGURABLE) {
+    return language_list($flags);
+  }
+
+  /**
+   * Returns the typed data manager.
+   *
+   * @return \Drupal\Core\TypedData\TypedDataManager
+   */
+  protected function typedDataManager() {
+    if (!$this->typedDataManager) {
+      $this->typedDataManager = \Drupal::typedDataManager();
+    }
+
+    return $this->typedDataManager;
+  }
+
+  /**
    * {@inheritdoc}
    */
   public function setNewRevision($value = TRUE) {
@@ -197,8 +224,7 @@ public function getRevisionId() {
    * {@inheritdoc}
    */
   public function isTranslatable() {
-    // @todo Inject the entity manager and retrieve bundle info from it.
-    $bundles = entity_get_bundles($this->entityTypeId);
+    $bundles = $this->entityManager()->getBundleInfo($this->entityTypeId);
     return !empty($bundles[$this->bundle()]['translatable']);
   }
 
@@ -245,15 +271,14 @@ public function setValue($value, $notify = TRUE) {
    * {@inheritdoc}
    */
   public function getString() {
-    return $this->label();
+    return (string) $this->label();
   }
 
   /**
    * {@inheritdoc}
    */
   public function validate() {
-    // @todo: Add the typed data manager as proper dependency.
-    return \Drupal::typedDataManager()->getValidator()->validate($this);
+    return $this->typedDataManager()->getValidator()->validate($this);
   }
 
   /**
@@ -399,7 +424,7 @@ public function get($property_name) {
   protected function getTranslatedField($name, $langcode) {
     if ($this->translations[$this->activeLangcode]['status'] == static::TRANSLATION_REMOVED) {
       $message = 'The entity object refers to a removed translation (@langcode) and cannot be manipulated.';
-      throw new \InvalidArgumentException(format_string($message, array('@langcode' => $this->activeLangcode)));
+      throw new \InvalidArgumentException(String::format($message, array('@langcode' => $this->activeLangcode)));
     }
     // Populate $this->fields to speed-up further look-ups and to keep track of
     // fields objects, possibly holding changes to field values.
@@ -490,7 +515,7 @@ public function getPropertyDefinition($name) {
   public function getPropertyDefinitions() {
     if (!isset($this->fieldDefinitions)) {
       $bundle = $this->bundle != $this->entityTypeId ? $this->bundle : NULL;
-      $this->fieldDefinitions = \Drupal::entityManager()->getFieldDefinitions($this->entityTypeId, $bundle);
+      $this->fieldDefinitions = $this->entityManager()->getFieldDefinitions($this->entityTypeId, $bundle);
     }
     return $this->fieldDefinitions;
   }
@@ -533,13 +558,13 @@ public function isEmpty() {
   /**
    * {@inheritdoc}
    */
-  public function access($operation = 'view', AccountInterface $account = NULL) {
+  public function access($operation, AccountInterface $account = NULL) {
     if ($operation == 'create') {
-      return \Drupal::entityManager()
+      return $this->entityManager()
         ->getAccessController($this->entityTypeId)
         ->createAccess($this->bundle(), $account);
     }
-    return \Drupal::entityManager()
+    return $this->entityManager()
       ->getAccessController($this->entityTypeId)
       ->access($this, $operation, $this->activeLangcode, $account);
   }
@@ -551,7 +576,7 @@ public function language() {
     $language = NULL;
     if ($this->activeLangcode != Language::LANGCODE_DEFAULT) {
       if (!isset($this->languages[$this->activeLangcode])) {
-        $this->languages += language_list(Language::STATE_ALL);
+        $this->languages += $this->languageList(Language::STATE_ALL);
       }
       $language = $this->languages[$this->activeLangcode];
     }
@@ -601,7 +626,7 @@ public function onChange($name) {
     if ($name == 'langcode') {
       $this->setDefaultLangcode();
       if (isset($this->translations[$this->defaultLangcode])) {
-        $message = format_string('A translation already exists for the specified language (@langcode).', array('@langcode' => $this->defaultLangcode));
+        $message = String::format('A translation already exists for the specified language (@langcode).', array('@langcode' => $this->defaultLangcode));
         throw new \InvalidArgumentException($message);
       }
       $this->updateFieldLangcodes($this->defaultLangcode);
@@ -650,7 +675,7 @@ public function getTranslation($langcode) {
 
     if (empty($translation)) {
       $message = 'Invalid translation language (@langcode) specified.';
-      throw new \InvalidArgumentException(format_string($message, array('@langcode' => $langcode)));
+      throw new \InvalidArgumentException(String::format($message, array('@langcode' => $langcode)));
     }
 
     return $translation;
@@ -715,14 +740,14 @@ public function hasTranslation($langcode) {
   public function addTranslation($langcode, array $values = array()) {
     if (!isset($this->languages[$langcode]) || $this->hasTranslation($langcode)) {
       $message = 'Invalid translation language (@langcode) specified.';
-      throw new \InvalidArgumentException(format_string($message, array('@langcode' => $langcode)));
+      throw new \InvalidArgumentException(String::format($message, array('@langcode' => $langcode)));
     }
 
     // Instantiate a new empty entity so default values will be populated in the
     // specified language.
     $entity_type = $this->getEntityType();
     $default_values = array($entity_type->getKey('bundle') => $this->bundle, 'langcode' => $langcode);
-    $entity = \Drupal::entityManager()
+    $entity = $this->entityManager()
       ->getStorageController($this->getEntityTypeId())
       ->create($default_values);
 
@@ -760,7 +785,7 @@ public function removeTranslation($langcode) {
     }
     else {
       $message = 'The specified translation (@langcode) cannot be removed.';
-      throw new \InvalidArgumentException(format_string($message, array('@langcode' => $langcode)));
+      throw new \InvalidArgumentException(String::format($message, array('@langcode' => $langcode)));
     }
   }
 
@@ -902,7 +927,7 @@ public function __unset($name) {
   public function createDuplicate() {
     if ($this->translations[$this->activeLangcode]['status'] == static::TRANSLATION_REMOVED) {
       $message = 'The entity object refers to a removed translation (@langcode) and cannot be manipulated.';
-      throw new \InvalidArgumentException(format_string($message, array('@langcode' => $this->activeLangcode)));
+      throw new \InvalidArgumentException(String::format($message, array('@langcode' => $this->activeLangcode)));
     }
 
     $duplicate = clone $this;
@@ -911,8 +936,7 @@ public function createDuplicate() {
 
     // Check if the entity type supports UUIDs and generate a new one if so.
     if ($entity_type->hasKey('uuid')) {
-      // @todo Inject the UUID service into the Entity class once possible.
-      $duplicate->{$entity_type->getKey('uuid')}->value = \Drupal::service('uuid')->generate();
+      $duplicate->{$entity_type->getKey('uuid')}->value = $this->uuidGenerator()->generate();
     }
 
     // Check whether the entity type supports revisions and initialize it if so.
@@ -960,9 +984,8 @@ public function __clone() {
   public function label() {
     $label = NULL;
     $entity_type = $this->getEntityType();
-    // @todo Convert to is_callable() and call_user_func().
-    if (($label_callback = $entity_type->getLabelCallback()) && function_exists($label_callback)) {
-      $label = $label_callback($this);
+    if (($label_callback = $entity_type->getLabelCallback()) && is_callable($label_callback)) {
+      $label = call_user_func($label_callback, $this);
     }
     elseif (($label_key = $entity_type->getKey('label')) && isset($this->{$label_key})) {
       $label = $this->{$label_key}->value;
diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php
index 5d70510..8fd3a62 100644
--- a/core/lib/Drupal/Core/Entity/Entity.php
+++ b/core/lib/Drupal/Core/Entity/Entity.php
@@ -7,13 +7,14 @@
 
 namespace Drupal\Core\Entity;
 
+use Drupal\Core\DependencyInjection\DependencySerialization;
 use Drupal\Core\Language\Language;
 use Drupal\Core\Session\AccountInterface;
 
 /**
  * Defines a base entity class.
  */
-abstract class Entity implements EntityInterface {
+abstract class Entity extends DependencySerialization implements EntityInterface {
 
   /**
    * The language code of the entity's default language.
@@ -23,6 +24,20 @@
   public $langcode = Language::LANGCODE_NOT_SPECIFIED;
 
   /**
+   * The entity manager.
+   *
+   * @var \Drupal\Core\Entity\EntityManagerInterface
+   */
+  protected $entityManager;
+
+  /**
+   * The UUID generator.
+   *
+   * @var \Drupal\Component\Uuid\UuidInterface
+   */
+  protected $uuidGenerator;
+
+  /**
    * The entity type.
    *
    * @var string
@@ -61,6 +76,39 @@ public function __construct(array $values, $entity_type) {
   }
 
   /**
+   * Wraps language_load().
+   */
+  protected function languageLoad($langcode) {
+    return language_load($langcode);
+  }
+
+  /**
+   * Returns the entity manager.
+   *
+   * @return \Drupal\Core\Entity\EntityManagerInterface
+   */
+  protected function entityManager() {
+    if (!$this->entityManager) {
+      $this->entityManager = \Drupal::entityManager();
+    }
+
+    return $this->entityManager;
+  }
+
+  /**
+   * Returns the UUID generator.
+   *
+   * @return \Drupal\Component\Uuid\UuidInterface
+   */
+  protected function uuidGenerator() {
+    if (!$this->uuidGenerator) {
+      $this->uuidGenerator = \Drupal::service('uuid');
+    }
+
+    return $this->uuidGenerator;
+  }
+
+  /**
    * {@inheritdoc}
    */
   public function id() {
@@ -86,6 +134,8 @@ public function isNew() {
    */
   public function enforceIsNew($value = TRUE) {
     $this->enforceIsNew = $value;
+
+    return $this;
   }
 
   /**
@@ -108,9 +158,8 @@ public function bundle() {
   public function label() {
     $label = NULL;
     $entity_type = $this->getEntityType();
-    // @todo Convert to is_callable() and call_user_func().
-    if (($label_callback = $entity_type->getLabelCallback()) && function_exists($label_callback)) {
-      $label = $label_callback($this);
+    if (($label_callback = $entity_type->getLabelCallback()) && is_callable($label_callback)) {
+      $label = call_user_func($label_callback, $this);
     }
     elseif (($label_key = $entity_type->getKey('label')) && isset($this->{$label_key})) {
       $label = $this->{$label_key};
@@ -138,7 +187,7 @@ public function urlInfo($rel = 'canonical') {
       $bundle = $this->bundle();
       // A bundle-specific callback takes precedence over the generic one for
       // the entity type.
-      $bundles = \Drupal::entityManager()->getBundleInfo($this->getEntityTypeId());
+      $bundles = $this->entityManager()->getBundleInfo($this->getEntityTypeId());
       if (isset($bundles[$bundle]['uri_callback'])) {
         $uri_callback = $bundles[$bundle]['uri_callback'];
       }
@@ -148,9 +197,8 @@ public function urlInfo($rel = 'canonical') {
 
       // Invoke the callback to get the URI. If there is no callback, use the
       // default URI format.
-      // @todo Convert to is_callable() and call_user_func().
-      if (isset($uri_callback) && function_exists($uri_callback)) {
-        $uri = $uri_callback($this);
+      if (isset($uri_callback) && is_callable($uri_callback)) {
+        $uri = call_user_func($uri_callback, $this);
       }
       else {
         return array();
@@ -247,13 +295,13 @@ public function uriRelationships() {
   /**
    * {@inheritdoc}
    */
-  public function access($operation = 'view', AccountInterface $account = NULL) {
+  public function access($operation, AccountInterface $account = NULL) {
     if ($operation == 'create') {
-      return \Drupal::entityManager()
+      return $this->entityManager()
         ->getAccessController($this->entityTypeId)
         ->createAccess($this->bundle(), $account);
     }
-    return \Drupal::entityManager()
+    return $this->entityManager()
       ->getAccessController($this->entityTypeId)
       ->access($this, $operation, Language::LANGCODE_DEFAULT, $account);
   }
@@ -262,7 +310,7 @@ public function access($operation = 'view', AccountInterface $account = NULL) {
    * {@inheritdoc}
    */
   public function language() {
-    $language = language_load($this->langcode);
+    $language = $this->languageLoad($this->langcode);
     if (!$language) {
       // Make sure we return a proper language object.
       $language = new Language(array('id' => Language::LANGCODE_NOT_SPECIFIED));
@@ -274,7 +322,7 @@ public function language() {
    * {@inheritdoc}
    */
   public function save() {
-    return \Drupal::entityManager()->getStorageController($this->entityTypeId)->save($this);
+    return $this->entityManager()->getStorageController($this->entityTypeId)->save($this);
   }
 
   /**
@@ -282,7 +330,7 @@ public function save() {
    */
   public function delete() {
     if (!$this->isNew()) {
-      \Drupal::entityManager()->getStorageController($this->entityTypeId)->delete(array($this->id() => $this));
+      $this->entityManager()->getStorageController($this->entityTypeId)->delete(array($this->id() => $this));
     }
   }
 
@@ -296,8 +344,7 @@ public function createDuplicate() {
 
     // Check if the entity type supports UUIDs and generate a new one if so.
     if ($entity_type->hasKey('uuid')) {
-      // @todo Inject the UUID service into the Entity class once possible.
-      $duplicate->{$entity_type->getKey('uuid')} = \Drupal::service('uuid')->generate();
+      $duplicate->{$entity_type->getKey('uuid')} = $this->uuidGenerator()->generate();
     }
     return $duplicate;
   }
@@ -306,7 +353,7 @@ public function createDuplicate() {
    * {@inheritdoc}
    */
   public function getEntityType() {
-    return \Drupal::entityManager()->getDefinition($this->getEntityTypeId());
+    return $this->entityManager()->getDefinition($this->getEntityTypeId());
   }
 
   /**
@@ -344,6 +391,7 @@ public static function preDelete(EntityStorageControllerInterface $storage_contr
    * {@inheritdoc}
    */
   public static function postDelete(EntityStorageControllerInterface $storage_controller, array $entities) {
+    /** @var self[] $entities */
     foreach ($entities as $entity) {
       $entity->onSaveOrDelete();
     }
@@ -375,8 +423,8 @@ protected function onSaveOrDelete() {
     }
 
     foreach ($referenced_entities as $entity_type => $entities) {
-      if (\Drupal::entityManager()->hasController($entity_type, 'view_builder')) {
-        \Drupal::entityManager()->getViewBuilder($entity_type)->resetCache($entities);
+      if ($this->entityManager()->hasController($entity_type, 'view_builder')) {
+        $this->entityManager()->getViewBuilder($entity_type)->resetCache($entities);
       }
     }
   }
@@ -394,14 +442,4 @@ protected function urlGenerator() {
     return $this->urlGenerator;
   }
 
-  /**
-   * {@inheritdoc}
-   */
-  public function __sleep() {
-    // Don't serialize the url generator.
-    $this->urlGenerator = NULL;
-
-    return array_keys(get_object_vars($this));
-  }
-
 }
diff --git a/core/lib/Drupal/Core/Entity/EntityInterface.php b/core/lib/Drupal/Core/Entity/EntityInterface.php
index 3e6af82..bb26565 100644
--- a/core/lib/Drupal/Core/Entity/EntityInterface.php
+++ b/core/lib/Drupal/Core/Entity/EntityInterface.php
@@ -65,6 +65,8 @@ public function isNew();
    *   (optional) Whether the entity should be forced to be new. Defaults to
    *   TRUE.
    *
+   * @return self
+   *
    * @see \Drupal\Core\Entity\EntityInterface::isNew()
    */
   public function enforceIsNew($value = TRUE);
diff --git a/core/lib/Drupal/Core/TypedData/ComplexDataInterface.php b/core/lib/Drupal/Core/TypedData/ComplexDataInterface.php
index 438ea6e..d6ea3c9 100644
--- a/core/lib/Drupal/Core/TypedData/ComplexDataInterface.php
+++ b/core/lib/Drupal/Core/TypedData/ComplexDataInterface.php
@@ -61,7 +61,7 @@ public function set($property_name, $value, $notify = TRUE);
    * @param bool $include_computed
    *   If set to TRUE, computed properties are included. Defaults to FALSE.
    *
-   * @return array
+   * @return \Drupal\Core\TypedData\TypedDataInterface[]
    *   An array of property objects implementing the TypedDataInterface, keyed
    *   by property name.
    */
diff --git a/core/modules/block/block.module b/core/modules/block/block.module
index daea82c..dd47d58 100644
--- a/core/modules/block/block.module
+++ b/core/modules/block/block.module
@@ -222,7 +222,7 @@ function _block_get_renderable_region($list = array()) {
     $settings = $block->get('settings');
     if ($not_cacheable || in_array($settings['cache'], array(DRUPAL_NO_CACHE, DRUPAL_CACHE_CUSTOM))) {
       // Non-cached blocks get built immediately.
-      if ($block->access()) {
+      if ($block->access('view')) {
         $build[$key] = entity_view($block, 'block');
       }
     }
@@ -401,7 +401,7 @@ function block_load($entity_id) {
 function _block_get_renderable_block($element) {
   $block = $element['#block'];
   // Don't bother to build blocks that aren't accessible.
-  if ($element['#access'] = $block->access()) {
+  if ($element['#access'] = $block->access('view')) {
     $element += entity_view($block, 'block');
   }
   return $element;
diff --git a/core/modules/block/lib/Drupal/block/Entity/Block.php b/core/modules/block/lib/Drupal/block/Entity/Block.php
index dc20929..0aadc1f 100644
--- a/core/modules/block/lib/Drupal/block/Entity/Block.php
+++ b/core/modules/block/lib/Drupal/block/Entity/Block.php
@@ -10,6 +10,7 @@
 use Drupal\Core\Config\Entity\ConfigEntityBase;
 use Drupal\block\BlockPluginBag;
 use Drupal\block\BlockInterface;
+use Drupal\Core\Config\Entity\ConfigEntityInterface;
 use Drupal\Core\Entity\EntityStorageControllerInterface;
 
 /**
@@ -161,7 +162,7 @@ public function preSave(EntityStorageControllerInterface $storage_controller) {
   /**
    * Sorts active blocks by weight; sorts inactive blocks by name.
    */
-  public static function sort($a, $b) {
+  public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b) {
     // Separate enabled from disabled.
     $status = $b->get('status') - $a->get('status');
     if ($status) {
diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityUnitTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityUnitTest.php
index df6c96d..5e3e5f0 100644
--- a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityUnitTest.php
+++ b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityUnitTest.php
@@ -90,14 +90,4 @@ public function testStorageControllerMethods() {
     }
   }
 
-  /**
-   * Tests getOriginalId() and setOriginalId().
-   */
-  protected function testGetOriginalId() {
-    $entity = $this->storage->create(array());
-    $id = $this->randomName();
-    $this->assertIdentical(spl_object_hash($entity->setOriginalId($id)), spl_object_hash($entity));
-    $this->assertIdentical($entity->getOriginalId(), $id);
-  }
-
 }
diff --git a/core/modules/config/tests/config_test/lib/Drupal/config_test/Entity/ConfigTest.php b/core/modules/config/tests/config_test/lib/Drupal/config_test/Entity/ConfigTest.php
index 623fa14..912ebd4 100644
--- a/core/modules/config/tests/config_test/lib/Drupal/config_test/Entity/ConfigTest.php
+++ b/core/modules/config/tests/config_test/lib/Drupal/config_test/Entity/ConfigTest.php
@@ -9,6 +9,7 @@
 
 use Drupal\Core\Config\Entity\ConfigEntityBase;
 use Drupal\config_test\ConfigTestInterface;
+use Drupal\Core\Config\Entity\ConfigEntityInterface;
 
 /**
  * Defines the ConfigTest configuration entity.
@@ -101,7 +102,7 @@ public function getExportProperties() {
   /**
    * Overrides \Drupal\Core\Config\Entity\ConfigEntityBase::sort().
    */
-  public static function sort($a, $b) {
+  public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b) {
     \Drupal::state()->set('config_entity_sort', TRUE);
     return parent::sort($a, $b);
   }
diff --git a/core/modules/entity/lib/Drupal/entity/EntityDisplayModeBase.php b/core/modules/entity/lib/Drupal/entity/EntityDisplayModeBase.php
index 1541143..aa48720 100644
--- a/core/modules/entity/lib/Drupal/entity/EntityDisplayModeBase.php
+++ b/core/modules/entity/lib/Drupal/entity/EntityDisplayModeBase.php
@@ -8,6 +8,7 @@
 namespace Drupal\entity;
 
 use Drupal\Core\Config\Entity\ConfigEntityBase;
+use Drupal\Core\Config\Entity\ConfigEntityInterface;
 
 /**
  * Base class for config entity types that hold settings for form and view modes.
@@ -67,7 +68,9 @@
   /**
    * {@inheritdoc}
    */
-  public static function sort($a, $b) {
+  public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b) {
+    /** @var \Drupal\entity\EntityDisplayModeInterface $a */
+    /** @var \Drupal\entity\EntityDisplayModeInterface $b */
     // Sort by the type of entity the view mode is used for.
     $a_type = $a->getTargetType();
     $b_type = $b->getTargetType();
diff --git a/core/modules/search/lib/Drupal/search/Entity/SearchPage.php b/core/modules/search/lib/Drupal/search/Entity/SearchPage.php
index bbc4e6f..70d5626 100644
--- a/core/modules/search/lib/Drupal/search/Entity/SearchPage.php
+++ b/core/modules/search/lib/Drupal/search/Entity/SearchPage.php
@@ -8,6 +8,7 @@
 namespace Drupal\search\Entity;
 
 use Drupal\Core\Config\Entity\ConfigEntityBase;
+use Drupal\Core\Config\Entity\ConfigEntityInterface;
 use Drupal\Core\Entity\EntityStorageControllerInterface;
 use Drupal\Component\Plugin\ConfigurablePluginInterface;
 use Drupal\search\Plugin\SearchIndexingInterface;
@@ -227,7 +228,7 @@ public static function postDelete(EntityStorageControllerInterface $storage_cont
   /**
    * {@inheritdoc}
    */
-  public static function sort($a, $b) {
+  public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b) {
     /** @var $a \Drupal\search\SearchPageInterface */
     /** @var $b \Drupal\search\SearchPageInterface */
     $a_status = (int) $a->status();
diff --git a/core/modules/system/lib/Drupal/system/Entity/Action.php b/core/modules/system/lib/Drupal/system/Entity/Action.php
index a313158..d29aaca 100644
--- a/core/modules/system/lib/Drupal/system/Entity/Action.php
+++ b/core/modules/system/lib/Drupal/system/Entity/Action.php
@@ -8,6 +8,7 @@
 namespace Drupal\system\Entity;
 
 use Drupal\Core\Config\Entity\ConfigEntityBase;
+use Drupal\Core\Config\Entity\ConfigEntityInterface;
 use Drupal\Core\Entity\EntityStorageControllerInterface;
 use Drupal\system\ActionConfigEntityInterface;
 use Drupal\Core\Action\ActionBag;
@@ -137,7 +138,9 @@ public function getType() {
   /**
    * {@inheritdoc}
    */
-  public static function sort($a, $b) {
+  public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b) {
+    /** @var \Drupal\system\ActionConfigEntityInterface $a */
+    /** @var \Drupal\system\ActionConfigEntityInterface $b */
     $a_type = $a->getType();
     $b_type = $b->getType();
     if ($a_type != $b_type) {
diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityLabelTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityLabelTest.php
deleted file mode 100644
index 097c7bc..0000000
--- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityLabelTest.php
+++ /dev/null
@@ -1,55 +0,0 @@
-<?php
-
-/**
- * @file
- * Contains \Drupal\system\Tests\Entity\EntityLabelTest.
- */
-
-namespace Drupal\system\Tests\Entity;
-
-/**
- * Tests entity properties.
- */
-class EntityLabelTest extends EntityUnitTestBase {
-
-  public static function getInfo() {
-    return array(
-      'name' => 'Entity label',
-      'description' => 'Tests entity labels.',
-      'group' => 'Entity API',
-    );
-  }
-
-  /**
-   * Tests label key and label callback of an entity.
-   */
-  function testEntityLabel() {
-    $entity_types = array(
-      'entity_test_no_label',
-      'entity_test_label',
-      'entity_test_label_callback',
-    );
-
-    $values = array(
-      'name' => $this->randomName(),
-    );
-    foreach ($entity_types as $entity_type) {
-      $entity = entity_create($entity_type, $values);
-      $label = $entity->label();
-
-      switch ($entity_type) {
-        case 'entity_test_no_label':
-          $this->assertFalse($label, 'Entity with no label property or callback returned FALSE.');
-          break;
-
-        case 'entity_test_label':
-          $this->assertEqual($label, $entity->name->value, 'Entity with label key returned correct label.');
-          break;
-
-        case 'entity_test_label_callback':
-          $this->assertEqual($label, 'label callback ' . $entity->name->value, 'Entity with label callback returned correct label.');
-          break;
-      }
-    }
-  }
-}
diff --git a/core/modules/system/tests/modules/entity_test/entity_test.module b/core/modules/system/tests/modules/entity_test/entity_test.module
index a46a1e7..fc1e722 100644
--- a/core/modules/system/tests/modules/entity_test/entity_test.module
+++ b/core/modules/system/tests/modules/entity_test/entity_test.module
@@ -378,19 +378,6 @@ function entity_test_entity_test_insert($entity) {
 }
 
 /**
- * Entity label callback.
- *
- * @param $entity
- *   The entity object.
- *
- * @return
- *   The label of the entity prefixed with "label callback".
- */
-function entity_test_label_callback($entity) {
-  return 'label callback ' . $entity->name->value;
-}
-
-/**
  * Implements hook_entity_field_access().
  *
  * @see \Drupal\system\Tests\Entity\FieldAccessTest::testFieldAccess()
diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php
new file mode 100644
index 0000000..55dca0b
--- /dev/null
+++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php
@@ -0,0 +1,227 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Tests\Core\Config\Entity\ConfigEntityBaseUnitTest.
+ */
+
+namespace Drupal\Tests\Core\Config\Entity;
+
+use Drupal\Core\DependencyInjection\ContainerBuilder;
+use Drupal\Tests\UnitTestCase;
+
+/**
+ * @coversDefaultClass \Drupal\Core\Config\Entity\ConfigEntityBase
+ *
+ * @group Drupal
+ */
+class ConfigEntityBaseUnitTest extends UnitTestCase {
+
+  /**
+   * The entity under test.
+   *
+   * @var \Drupal\Core\Config\Entity\ConfigEntityBase|\PHPUnit_Framework_MockObject_MockObject
+   */
+  protected $entity;
+
+  /**
+   * The entity info used for testing..
+   *
+   * @var \Drupal\Core\Entity\EntityTypeInterface|\PHPUnit_Framework_MockObject_MockObject
+   */
+  protected $entityInfo;
+
+  /**
+   * The entity manager used for testing.
+   *
+   * @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
+   */
+  protected $entityManager;
+
+  /**
+   * The type of the entity under test.
+   *
+   * @var string
+   */
+  protected $entityType;
+
+  /**
+   * The UUID generator used for testing.
+   *
+   * @var \Drupal\Component\Uuid\UuidInterface|\PHPUnit_Framework_MockObject_MockObject
+   */
+  protected $uuid;
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function getInfo() {
+    return array(
+      'description' => '',
+      'name' => '\Drupal\Core\Config\Entity\ConfigEntityBase unit test',
+      'group' => 'Entity',
+    );
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setUp() {
+    $values = array();
+    $this->entityType = $this->randomName();
+
+    $this->entityInfo = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface');
+
+    $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
+    $this->entityManager->expects($this->any())
+      ->method('getDefinition')
+      ->with($this->entityType)
+      ->will($this->returnValue($this->entityInfo));
+
+    $this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface');
+
+    $container = new ContainerBuilder();
+    $container->set('entity.manager', $this->entityManager);
+    $container->set('uuid', $this->uuid);
+    \Drupal::setContainer($container);
+
+    $this->entity = $this->getMockBuilder('\Drupal\Core\Config\Entity\ConfigEntityBase')
+      ->setConstructorArgs(array($values, $this->entityType))
+      ->setMethods(array('languageLoad'))
+      ->getMock();
+    $this->entity->expects($this->any())
+      ->method('languageLoad')
+      ->will($this->returnValue(NULL));
+  }
+
+  /**
+   * @covers ::setOriginalId
+   * @covers ::getOriginalId
+   */
+  public function testGetOriginalId() {
+    $id = $this->randomName();
+    $this->assertSame(spl_object_hash($this->entity), spl_object_hash($this->entity->setOriginalId($id)));
+    $this->assertSame($id, $this->entity->getOriginalId());
+  }
+
+  /**
+   * @covers ::isNew
+   */
+  public function testIsNew() {
+    $this->assertFalse($this->entity->isNew());
+    $this->assertSame(spl_object_hash($this->entity), spl_object_hash($this->entity->enforceIsNew()));
+    $this->assertTrue($this->entity->isNew());
+    $this->entity->enforceIsNew(FALSE);
+    $this->assertFalse($this->entity->isNew());
+  }
+
+  /**
+   * @covers ::set
+   * @covers ::get
+   */
+  public function testGet() {
+    $name = $this->randomName();
+    $value = $this->randomName();
+    $this->assertNull($this->entity->get($name));
+    $this->assertSame(spl_object_hash($this->entity), spl_object_hash($this->entity->set($name, $value)));
+    $this->assertSame($value, $this->entity->get($name));
+  }
+
+  /**
+   * @covers ::setStatus
+   * @covers ::status
+   */
+  public function testSetStatus() {
+    $this->assertTrue($this->entity->status());
+    $this->assertSame(spl_object_hash($this->entity), spl_object_hash($this->entity->setStatus(FALSE)));
+    $this->assertFalse($this->entity->status());
+    $this->entity->setStatus(TRUE);
+    $this->assertTrue($this->entity->status());
+  }
+
+  /**
+   * @covers ::enable
+   * @depends testSetStatus
+   */
+  public function testEnable() {
+    $this->entity->setStatus(FALSE);
+    $this->assertSame(spl_object_hash($this->entity), spl_object_hash($this->entity->enable()));
+    $this->assertTrue($this->entity->status());
+  }
+
+  /**
+   * @covers ::disable
+   * @depends testSetStatus
+   */
+  public function testDisable() {
+    $this->entity->setStatus(TRUE);
+    $this->assertSame(spl_object_hash($this->entity), spl_object_hash($this->entity->disable()));
+    $this->assertFalse($this->entity->status());
+  }
+
+  /**
+   * @covers ::setSyncing
+   * @covers ::isSyncing
+   */
+  public function testIsSyncing() {
+    $this->assertFalse($this->entity->isSyncing());
+    $this->assertSame(spl_object_hash($this->entity), spl_object_hash($this->entity->setSyncing(TRUE)));
+    $this->assertTrue($this->entity->isSyncing());
+    $this->entity->setSyncing(FALSE);
+    $this->assertFalse($this->entity->isSyncing());
+  }
+
+  /**
+   * @covers ::createDuplicate
+   */
+  public function testCreateDuplicate() {
+    $this->entityInfo->expects($this->once())
+      ->method('getKey')
+      ->with('id')
+      ->will($this->returnValue('id'));
+
+    $this->entity->setOriginalId('foo');
+    /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $duplicate */
+    $duplicate = $this->entity->createDuplicate();
+    $this->assertInstanceOf('\Drupal\Core\Entity\Entity', $duplicate);
+    $this->assertNotSame(spl_object_hash($this->entity), spl_object_hash($duplicate));
+    $this->assertNull($duplicate->id());
+    $this->assertNull($duplicate->getOriginalId());
+    $this->assertNull($duplicate->uuid());
+  }
+
+  /**
+   * @covers ::sort
+   */
+  public function testSort() {
+    $this->entityManager->expects($this->any())
+      ->method('getDefinition')
+      ->with($this->entityType)
+      ->will($this->returnValue(array(
+        'entity_keys' => array(
+          'label' => 'label',
+        ),
+      )));
+    $entity_a = $this->entity;
+    $entity_a->label = 'foo';
+    $entity_b = clone $this->entity;
+    $entity_b->label = 'bar';
+    $list = array($entity_a, $entity_b);
+    // Suppress errors because of https://bugs.php.net/bug.php?id=50688.
+    @usort($list, '\Drupal\Core\Config\Entity\ConfigEntityBase::sort');
+    $this->assertSame(spl_object_hash($entity_b), spl_object_hash($list[0]));
+    $entity_a->weight = 0;
+    $entity_b->weight = 1;
+    // Suppress errors because of https://bugs.php.net/bug.php?id=50688.
+    @usort($list, array($entity_a, 'sort'));
+    $this->assertSame(spl_object_hash($entity_a), spl_object_hash($list[0]));
+  }
+
+  /**
+   * @covers ::getExportProperties
+   */
+  public function testGetExportProperties() {
+    $properties = $this->entity->getExportProperties();
+    $this->assertInternalType('array', $properties);
+  }
+}
diff --git a/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php
new file mode 100644
index 0000000..bf5ce3e
--- /dev/null
+++ b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php
@@ -0,0 +1,333 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Tests\Core\Entity\ContentEntityBaseUnitTest.
+ */
+
+namespace Drupal\Tests\Core\Entity;
+
+use Drupal\Core\DependencyInjection\ContainerBuilder;
+use Drupal\Tests\UnitTestCase;
+
+/**
+ * @coversDefaultClass \Drupal\Core\Entity\ContentEntityBase
+ *
+ * @group Drupal
+ */
+class ContentEntityBaseUnitTest extends UnitTestCase {
+
+  /**
+   * The bundle of the entity under test.
+   *
+   * @var string
+   */
+  protected $bundle;
+
+  /**
+   * The entity under test.
+   *
+   * @var \Drupal\Core\Entity\ContentEntityBase|\PHPUnit_Framework_MockObject_MockObject
+   */
+  protected $entity;
+
+  /**
+   * The entity info used for testing..
+   *
+   * @var \Drupal\Core\Entity\EntityTypeInterface|\PHPUnit_Framework_MockObject_MockObject
+   */
+  protected $entityInfo;
+
+  /**
+   * The entity manager used for testing.
+   *
+   * @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
+   */
+  protected $entityManager;
+
+  /**
+   * The type of the entity under test.
+   *
+   * @var string
+   */
+  protected $entityType;
+
+  /**
+   * The typed data manager used for testing.
+   *
+   * @var \Drupal\Core\TypedData\TypedDataManager|\PHPUnit_Framework_MockObject_MockObject
+   */
+  protected $typedDataManager;
+
+  /**
+   * The UUID generator used for testing.
+   *
+   * @var \Drupal\Component\Uuid\UuidInterface|\PHPUnit_Framework_MockObject_MockObject
+   */
+  protected $uuid;
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function getInfo() {
+    return array(
+      'description' => '',
+      'name' => '\Drupal\Core\Entity\ContentEntityBase unit test',
+      'group' => 'Entity',
+    );
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setUp() {
+    $values = array();
+    $this->entityType = $this->randomName();
+    $this->bundle = $this->randomName();
+
+    $this->entityInfo = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface');
+
+    $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
+    $this->entityManager->expects($this->any())
+      ->method('getDefinition')
+      ->with($this->entityType)
+      ->will($this->returnValue($this->entityInfo));
+    $this->entityManager->expects($this->any())
+      ->method('getFieldDefinitions')
+      ->with($this->entityType, $this->bundle)
+      ->will($this->returnValue(array(
+        'id' => array(
+          'type' => 'integer_field',
+        ),
+      )));
+
+    $this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface');
+
+    $this->typedDataManager = $this->getMockBuilder('\Drupal\Core\TypedData\TypedDataManager')
+      ->disableOriginalConstructor()
+      ->getMock();
+
+    $container = new ContainerBuilder();
+    $container->set('entity.manager', $this->entityManager);
+    $container->set('uuid', $this->uuid);
+    $container->set('typed_data_manager', $this->typedDataManager);
+    \Drupal::setContainer($container);
+
+    $this->entity = $this->getMockBuilder('\Drupal\Core\Entity\ContentEntityBase')
+      ->setConstructorArgs(array($values, $this->entityType, $this->bundle))
+      ->setMethods(array('languageList', 'languageLoad'))
+      ->getMockForAbstractClass();
+    $this->entity->expects($this->any())
+      ->method('languageList')
+      ->will($this->returnValue(array()));
+    $this->entity->expects($this->any())
+      ->method('languageLoad')
+      ->will($this->returnValue(NULL));
+  }
+
+  /**
+   * @covers ::isNewRevision
+   * @covers ::setNewRevision
+   */
+  public function testIsNewRevision() {
+    $this->entityInfo->expects($this->at(0))
+      ->method('hasKey')
+      ->with('revision')
+      ->will($this->returnValue(FALSE));
+    $this->entityInfo->expects($this->at(1))
+      ->method('hasKey')
+      ->with('revision')
+      ->will($this->returnValue(TRUE));
+
+    $this->assertFalse($this->entity->isNewRevision());
+    $this->assertTrue($this->entity->isNewRevision());
+    $this->entity->setNewRevision(TRUE);
+    $this->assertTRUE($this->entity->isNewRevision());
+  }
+
+  /**
+   * @covers ::isDefaultRevision
+   */
+  public function testIsDefaultRevision() {
+    // The default value is TRUE.
+    $this->assertTrue($this->entity->isDefaultRevision());
+    // We override the value, but it does not affect this call.
+    $this->assertTrue($this->entity->isDefaultRevision(FALSE));
+    // The last call changed the return value for this call.
+    $this->assertFalse($this->entity->isDefaultRevision());
+  }
+
+  /**
+   * @covers ::getRevisionId
+   */
+  public function testGetRevisionId() {
+    $this->assertNull($this->entity->getRevisionId());
+  }
+
+  /**
+   * @covers ::isTranslatable
+   */
+  public function testIsTranslatable() {
+    $this->entityManager->expects($this->at(0))
+      ->method('getBundleInfo')
+      ->with($this->entityType)
+      ->will($this->returnValue(array(
+        $this->bundle => array(
+          'translatable' => TRUE,
+        ),
+      )));
+    $this->assertTrue($this->entity->isTranslatable());
+    $this->assertFalse($this->entity->isTranslatable());
+  }
+
+  /**
+   * @covers ::preSaveRevision
+   */
+  public function testPreSaveRevision() {
+    // This method is internal, so check for errors on calling it only.
+    $storage = $this->getMock('\Drupal\Core\Entity\EntityStorageControllerInterface');
+    $record = new \stdClass();
+    $this->entity->preSaveRevision($storage, $record);
+  }
+
+  /**
+   * @covers ::getDefinition
+   */
+  public function testGetDefinition() {
+    $definition = $this->entity->getDefinition();
+    $this->assertInstanceOf('\Drupal\Core\TypedData\DataDefinitionInterface', $definition);
+  }
+
+  /**
+   * @covers ::getString
+   */
+  public function testGetString() {
+    $this->assertInternalType('string', $this->entity->getString());
+  }
+
+  /**
+   * @covers ::validate
+   */
+  public function testValidate() {
+    $validator = $this->getMock('\Symfony\Component\Validator\ValidatorInterface');
+    /** @var \Symfony\Component\Validator\ConstraintViolationList|\PHPUnit_Framework_MockObject_MockObject $empty_violation_list */
+    $empty_violation_list = $this->getMockBuilder('\Symfony\Component\Validator\ConstraintViolationList')
+      ->setMethods(NULL)
+      ->getMock();
+    $non_empty_violation_list = clone $empty_violation_list;
+    $violation = $this->getMock('\Symfony\Component\Validator\ConstraintViolationInterface');
+    $non_empty_violation_list->add($violation);
+    $validator->expects($this->at(0))
+      ->method('validate')
+      ->with($this->entity)
+      ->will($this->returnValue($empty_violation_list));
+    $validator->expects($this->at(1))
+      ->method('validate')
+      ->with($this->entity)
+      ->will($this->returnValue($non_empty_violation_list));
+    $this->typedDataManager->expects($this->exactly(2))
+      ->method('getValidator')
+      ->will($this->returnValue($validator));
+    $this->assertSame(0, count($this->entity->validate()));
+    $this->assertSame(1, count($this->entity->validate()));
+  }
+
+  /**
+   * @covers ::getConstraints
+   */
+  public function testGetConstraints() {
+    $this->assertInternalType('array', $this->entity->getConstraints());
+  }
+
+  /**
+   * @covers ::getName
+   */
+  public function testGetName() {
+    $this->assertNull($this->entity->getName());
+  }
+
+  /**
+   * @covers ::getRoot
+   */
+  public function testGetRoot() {
+    $this->assertSame(spl_object_hash($this->entity), spl_object_hash($this->entity->getRoot()));
+  }
+
+  /**
+   * @covers ::getPropertyPath
+   */
+  public function testGetPropertyPath() {
+    $this->assertSame('', $this->entity->getPropertyPath());
+  }
+
+  /**
+   * @covers ::getParent
+   */
+  public function testGetParent() {
+    $this->assertNull($this->entity->getParent());
+  }
+
+  /**
+   * @covers ::setContext
+   */
+  public function testSetContext() {
+    $name = $this->randomName();
+    $parent = $this->getMock('\Drupal\Core\TypedData\TypedDataInterface');
+    $this->entity->setContext($name, $parent);
+  }
+
+  /**
+   * @covers ::bundle
+   */
+  public function testBundle() {
+    $this->assertSame($this->bundle, $this->entity->bundle());
+  }
+
+  /**
+   * @covers ::getPropertyDefinitions
+   */
+  public function testGetPropertyDefinitions() {
+    $definitions = $this->entity->getPropertyDefinitions();
+    $this->assertInternalType('array', $definitions);
+    $this->arrayHasKey('id', $definitions);
+  }
+
+  /**
+   * @covers ::access
+   */
+  public function testAccess() {
+    $access = $this->getMock('\Drupal\Core\Entity\EntityAccessControllerInterface');
+    $operation = $this->randomName();
+    $access->expects($this->at(0))
+      ->method('access')
+      ->with($this->entity, $operation)
+      ->will($this->returnValue(TRUE));
+    $access->expects($this->at(1))
+      ->method('createAccess')
+      ->will($this->returnValue(TRUE));
+    $this->entityManager->expects($this->exactly(2))
+      ->method('getAccessController')
+      ->will($this->returnValue($access));
+    $this->assertTrue($this->entity->access($operation));
+    $this->assertTrue($this->entity->access('create'));
+  }
+
+  /**
+   * @covers ::label
+   */
+  public function testLabel() {
+    // Make a mock with one method that we use as the entity's uri_callback. We
+    // check that it is called, and that the entity's label is the callback's
+    // return value.
+    $callback_label = $this->randomName();
+    $callback_container = $this->getMock(get_class());
+    $callback_container->expects($this->once())
+      ->method(__FUNCTION__)
+      ->will($this->returnValue($callback_label));
+    $this->entityInfo->expects($this->once())
+      ->method('getLabelCallback')
+      ->will($this->returnValue(array($callback_container, __FUNCTION__)));
+
+    $this->assertSame($callback_label, $this->entity->label());
+  }
+}
diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php
new file mode 100644
index 0000000..74be854
--- /dev/null
+++ b/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php
@@ -0,0 +1,325 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Tests\Core\Entity\EntityUnitTest.
+ */
+
+namespace Drupal\Tests\Core\Entity;
+
+use Drupal\Core\DependencyInjection\ContainerBuilder;
+use Drupal\Tests\UnitTestCase;
+
+/**
+ * @coversDefaultClass \Drupal\Core\Entity\Entity
+ *
+ * @group Drupal
+ */
+class EntityUnitTest extends UnitTestCase {
+
+  /**
+   * The entity under test.
+   *
+   * @var \Drupal\Core\Entity\Entity|\PHPUnit_Framework_MockObject_MockObject
+   */
+  protected $entity;
+
+  /**
+   * The entity info used for testing..
+   *
+   * @var \Drupal\Core\Entity\EntityTypeInterface|\PHPUnit_Framework_MockObject_MockObject
+   */
+  protected $entityInfo;
+
+  /**
+   * The entity manager used for testing.
+   *
+   * @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
+   */
+  protected $entityManager;
+
+  /**
+   * The ID of the type of the entity under test.
+   *
+   * @var string
+   */
+  protected $entityTypeId;
+
+  /**
+   * The route provider used for testing.
+   *
+   * @var \Drupal\Core\Routing\RouteProvider|\PHPUnit_Framework_MockObject_MockObject
+   */
+  protected $routeProvider;
+
+  /**
+   * The UUID generator used for testing.
+   *
+   * @var \Drupal\Component\Uuid\UuidInterface|\PHPUnit_Framework_MockObject_MockObject
+   */
+  protected $uuid;
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function getInfo() {
+    return array(
+      'description' => '',
+      'name' => '\Drupal\Core\Entity\Entity unit test',
+      'group' => 'Entity',
+    );
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setUp() {
+    $values = array();
+    $this->entityTypeId = $this->randomName();
+
+    $this->entityInfo = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface');
+
+    $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
+    $this->entityManager->expects($this->any())
+      ->method('getDefinition')
+      ->with($this->entityTypeId)
+      ->will($this->returnValue($this->entityInfo));
+
+    $this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface');
+
+    $container = new ContainerBuilder();
+    $container->set('entity.manager', $this->entityManager);
+    $container->set('uuid', $this->uuid);
+    \Drupal::setContainer($container);
+
+    $this->entity = $this->getMockBuilder('\Drupal\Core\Entity\Entity')
+      ->setConstructorArgs(array($values, $this->entityTypeId))
+      ->setMethods(array('languageLoad'))
+      ->getMock();
+    $this->entity->expects($this->any())
+      ->method('languageLoad')
+      ->will($this->returnValue(NULL));
+  }
+
+  /**
+   * @covers ::id
+   */
+  public function testId() {
+    // @todo How to test this?
+    $this->assertNull($this->entity->id());
+  }
+
+  /**
+   * @covers ::uuid
+   */
+  public function testUuid() {
+    // @todo How to test this?
+    $this->assertNull($this->entity->uuid());
+  }
+
+  /**
+   * @covers ::isNew
+   */
+  public function testIsNew() {
+    // @todo How to test this?
+    $this->assertInternalType('bool', $this->entity->isNew());
+  }
+
+  /**
+   * @covers ::enforceIsNew
+   */
+  public function testEnforceIsNew() {
+    $this->assertSame(spl_object_hash($this->entity), spl_object_hash($this->entity->enforceIsNew()));
+  }
+
+  /**
+   * @covers ::getEntityType
+   */
+  public function testGetEntityType() {
+    $this->assertInstanceOf('\Drupal\Core\Entity\EntityTypeInterface', $this->entity->getEntityType());
+  }
+
+  /**
+   * @covers ::bundle
+   */
+  public function testBundle() {
+    $this->assertSame($this->entityTypeId, $this->entity->bundle());
+  }
+
+  /**
+   * @covers ::label
+   */
+  public function testLabel() {
+    // Make a mock with one method that we use as the entity's uri_callback. We
+    // check that it is called, and that the entity's label is the callback's
+    // return value.
+    $callback_label = $this->randomName();
+    $property_label = $this->randomName();
+    $callback_container = $this->getMock(get_class());
+    $callback_container->expects($this->once())
+      ->method(__FUNCTION__)
+      ->will($this->returnValue($callback_label));
+    $this->entityInfo->expects($this->at(0))
+      ->method('getLabelCallback')
+      ->will($this->returnValue(array($callback_container, __FUNCTION__)));
+    $this->entityInfo->expects($this->at(1))
+      ->method('getLabelCallback')
+      ->will($this->returnValue(NULL));
+    $this->entityInfo->expects($this->at(2))
+      ->method('getKey')
+      ->with('label')
+      ->will($this->returnValue('label'));
+
+    // Set a dummy property on the entity under test to test that the label can
+    // be returned form a property if there is no callback.
+    $this->entityManager->expects($this->at(1))
+      ->method('getDefinition')
+      ->with($this->entityTypeId)
+      ->will($this->returnValue(array(
+        'entity_keys' => array(
+          'label' => 'label',
+        ),
+      )));
+    $this->entity->label = $property_label;
+
+    $this->assertSame($callback_label, $this->entity->label());
+    $this->assertSame($property_label, $this->entity->label());
+  }
+
+  /**
+   * @covers ::access
+   */
+  public function testAccess() {
+    $access = $this->getMock('\Drupal\Core\Entity\EntityAccessControllerInterface');
+    $operation = $this->randomName();
+    $access->expects($this->at(0))
+      ->method('access')
+      ->with($this->entity, $operation)
+      ->will($this->returnValue(TRUE));
+    $access->expects($this->at(1))
+      ->method('createAccess')
+      ->will($this->returnValue(TRUE));
+    $this->entityManager->expects($this->exactly(2))
+      ->method('getAccessController')
+      ->will($this->returnValue($access));
+    $this->assertTrue($this->entity->access($operation));
+    $this->assertTrue($this->entity->access('create'));
+  }
+
+  /**
+   * @covers ::language
+   */
+  public function testLanguage() {
+    $this->assertInstanceOf('\Drupal\Core\Language\Language', $this->entity->language());
+  }
+
+  /**
+   * @covers ::save
+   */
+  public function testSave() {
+    $storage = $this->getMock('\Drupal\Core\Entity\EntityStorageControllerInterface');
+    $storage->expects($this->once())
+      ->method('save')
+      ->with($this->entity);
+    $this->entityManager->expects($this->once())
+      ->method('getStorageController')
+      ->with($this->entityTypeId)
+      ->will($this->returnValue($storage));
+    $this->entity->save();
+  }
+
+  /**
+   * @covers ::delete
+   */
+  public function testDelete() {
+    $this->entity->id = $this->randomName();
+    $storage = $this->getMock('\Drupal\Core\Entity\EntityStorageControllerInterface');
+    // Testing the argument of the delete() method consumes too much memory.
+    $storage->expects($this->once())
+      ->method('delete');
+    $this->entityManager->expects($this->once())
+      ->method('getStorageController')
+      ->with($this->entityTypeId)
+      ->will($this->returnValue($storage));
+    $this->entity->delete();
+  }
+
+  /**
+   * @covers ::getEntityTypeId
+   */
+  public function testGetEntityTypeId() {
+    $this->assertSame($this->entityTypeId, $this->entity->getEntityTypeId());
+  }
+
+  /**
+   * @covers ::preSave
+   */
+  public function testPreSave() {
+    // This method is internal, so check for errors on calling it only.
+    $storage = $this->getMock('\Drupal\Core\Entity\EntityStorageControllerInterface');
+    $this->entity->preSave($storage);
+  }
+
+  /**
+   * @covers ::postSave
+   */
+  public function testPostSave() {
+    // This method is internal, so check for errors on calling it only.
+    $storage = $this->getMock('\Drupal\Core\Entity\EntityStorageControllerInterface');
+    $this->entity->postSave($storage);
+  }
+
+  /**
+   * @covers ::preCreate
+   */
+  public function testPreCreate() {
+    // This method is internal, so check for errors on calling it only.
+    $storage = $this->getMock('\Drupal\Core\Entity\EntityStorageControllerInterface');
+    $values = array();
+    $this->entity->preCreate($storage, $values);
+  }
+
+  /**
+   * @covers ::postCreate
+   */
+  public function testPostCreate() {
+    // This method is internal, so check for errors on calling it only.
+    $storage = $this->getMock('\Drupal\Core\Entity\EntityStorageControllerInterface');
+    $this->entity->postCreate($storage);
+  }
+
+  /**
+   * @covers ::preDelete
+   */
+  public function testPreDelete() {
+    // This method is internal, so check for errors on calling it only.
+    $storage = $this->getMock('\Drupal\Core\Entity\EntityStorageControllerInterface');
+    $this->entity->preDelete($storage, array($this->entity));
+  }
+
+  /**
+   * @covers ::postDelete
+   */
+  public function testPostDelete() {
+    // This method is internal, so check for errors on calling it only.
+    $storage = $this->getMock('\Drupal\Core\Entity\EntityStorageControllerInterface');
+    $this->entity->postDelete($storage, array($this->entity));
+  }
+
+  /**
+   * @covers ::postLoad
+   */
+  public function testPostLoad() {
+    // This method is internal, so check for errors on calling it only.
+    $storage = $this->getMock('\Drupal\Core\Entity\EntityStorageControllerInterface');
+    $entities = array($this->entity);
+    $this->entity->postLoad($storage, $entities);
+  }
+
+  /**
+   * @covers ::referencedEntities
+   */
+  public function testReferencedEntities() {
+    $this->assertSame(array(), $this->entity->referencedEntities());
+  }
+}
diff --git a/sites/default/default.settings.php b/sites/default/default.settings.php
old mode 100644
new mode 100755
