commit 2014e433ea02d39cbe15ce1b2804e4127c359938
Author: Bart Feenstra <bart@mynameisbart.com>
Date:   Fri Nov 15 21:53:00 2013 +0100

    Strength through unit testing

diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php
index a988135..20b1ecc 100644
--- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php
+++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php
@@ -57,6 +57,13 @@ public function __construct(array $values, $entity_type) {
   }
 
   /**
+   * Wraps format_string().
+   */
+  protected function formatString($string, array $args = array()) {
+    return format_string($string, $args);
+  }
+
+  /**
    * {@inheritdoc}
    */
   public function getOriginalId() {
@@ -95,6 +102,8 @@ public function get($property_name) {
    */
   public function set($property_name, $value) {
     $this->{$property_name} = $value;
+
+    return $this;
   }
 
   /**
@@ -131,6 +140,8 @@ public function status() {
    */
   public function setSyncing($syncing) {
     $this->isSyncing = $syncing;
+
+    return $this;
   }
 
   /**
@@ -153,7 +164,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) {
@@ -185,21 +196,24 @@ public function getExportProperties() {
   public function preSave(EntityStorageControllerInterface $storage_controller) {
     parent::preSave($storage_controller);
 
-    // Ensure this entity's UUID does not exist with a different ID, regardless
-    // of whether it's new or updated.
-    $matching_entities = $storage_controller->getQuery()
-      ->condition('uuid', $this->uuid())
-      ->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)));
-    }
+    // The getQuery() method only exists on ConfigStorageController.
+    if ($storage_controller instanceof ConfigStorageController) {
+      // Ensure this entity's UUID does not exist with a different ID, regardless
+      // of whether it's new or updated.
+      $matching_entities = $storage_controller->getQuery()
+        ->condition('uuid', $this->uuid())
+        ->execute();
+      $matched_entity = reset($matching_entities);
+      if (!empty($matched_entity) && ($matched_entity != $this->id())) {
+        throw new ConfigDuplicateUUIDException($this->formatString('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())));
+      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($this->formatString('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..b49a73b 100644
--- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php
+++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php
@@ -64,6 +64,8 @@ public function setStatus($status);
    *
    * @param bool $status
    *   The status of the sync flag.
+   *
+   * @return self
    */
   public function setSyncing($status);
 
@@ -109,6 +111,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 self
    */
   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 5447e90..afe5f35 100644
--- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php
+++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php
@@ -139,7 +139,7 @@
   public function __construct(array $values, $entity_type, $bundle = FALSE, $translations = array()) {
     $this->entityType = $entity_type;
     $this->bundle = $bundle ? $bundle : $this->entityType;
-    $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
@@ -167,6 +167,36 @@ public function __construct(array $values, $entity_type, $bundle = FALSE, $trans
   }
 
   /**
+   * Wraps language_list().
+   */
+  protected function languageList($flags = Language::STATE_CONFIGURABLE) {
+    return language_list($flags);
+  }
+
+  /**
+   * Wraps check_plain().
+   */
+  protected function checkPlain($text) {
+    return check_plain($text);
+  }
+
+  /**
+   * Wraps format_string().
+   */
+  protected function formatString($string, array $args = array()) {
+    return format_string($string, $args);
+  }
+
+  /**
+   * Returns the typed data manager.
+   *
+   * @return \Drupal\Core\TypedData\TypedDataManager
+   */
+  protected function typedDataManager() {
+    return \Drupal::typedData();
+  }
+
+  /**
    * {@inheritdoc}
    */
   public function setNewRevision($value = TRUE) {
@@ -203,8 +233,7 @@ public function getRevisionId() {
    * {@inheritdoc}
    */
   public function isTranslatable() {
-    // @todo Inject the entity manager and retrieve bundle info from it.
-    $bundles = entity_get_bundles($this->entityType);
+    $bundles = $this->entityManager()->getBundleInfo($this->entityType);
     return !empty($bundles[$this->bundle()]['translatable']);
   }
 
@@ -258,8 +287,7 @@ public function getString() {
    * {@inheritdoc}
    */
   public function validate() {
-    // @todo: Add the typed data manager as proper dependency.
-    return \Drupal::typedData()->getValidator()->validate($this);
+    return $this->typedDataManager()->getValidator()->validate($this);
   }
 
   /**
@@ -395,7 +423,7 @@ protected function getTranslatedField($property_name, $langcode) {
     if (!isset($this->fields[$property_name][$langcode])) {
       $definition = $this->getPropertyDefinition($property_name);
       if (!$definition) {
-        throw new \InvalidArgumentException('Field ' . check_plain($property_name) . ' is unknown.');
+        throw new \InvalidArgumentException('Field ' . $this->checkPlain($property_name) . ' is unknown.');
       }
       // Non-translatable fields are always stored with
       // Language::LANGCODE_DEFAULT as key.
@@ -410,7 +438,7 @@ protected function getTranslatedField($property_name, $langcode) {
         if (isset($this->values[$property_name][$langcode])) {
           $value = $this->values[$property_name][$langcode];
         }
-        $field = \Drupal::typedData()->getPropertyInstance($this, $property_name, $value);
+        $field = $this->typedDataManager()->getPropertyInstance($this, $property_name, $value);
         $field->setLangcode($langcode);
         $this->fields[$property_name][$langcode] = $field;
       }
@@ -472,7 +500,7 @@ public function getPropertyDefinition($name) {
   public function getPropertyDefinitions() {
     if (!isset($this->fieldDefinitions)) {
       $bundle = $this->bundle != $this->entityType ? $this->bundle : NULL;
-      $this->fieldDefinitions = \Drupal::entityManager()->getFieldDefinitions($this->entityType, $bundle);
+      $this->fieldDefinitions = $this->entityManager()->getFieldDefinitions($this->entityType, $bundle);
     }
     return $this->fieldDefinitions;
   }
@@ -515,13 +543,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->entityType)
         ->createAccess($this->bundle(), $account);
     }
-    return \Drupal::entityManager()
+    return $this->entityManager()
       ->getAccessController($this->entityType)
       ->access($this, $operation, $this->activeLangcode, $account);
   }
@@ -532,7 +560,7 @@ public function access($operation = 'view', AccountInterface $account = NULL) {
   public function language() {
     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);
       }
       return $this->languages[$this->activeLangcode];
     }
@@ -608,7 +636,7 @@ public function getTranslation($langcode) {
       else {
         // If we were given a valid language and there is no translation for it,
         // we return a new one.
-        $languages = language_list(Language::STATE_ALL);
+        $languages = $this->languageList(Language::STATE_ALL);
         if (isset($languages[$langcode])) {
           // If the entity or the requested language  is not a configured
           // language, we fall back to the entity itself, since in this case it
@@ -685,17 +713,17 @@ public function hasTranslation($langcode) {
    * {@inheritdoc}
    */
   public function addTranslation($langcode, array $values = array()) {
-    $languages = language_list(Language::STATE_ALL);
+    $languages = $this->languageList(Language::STATE_ALL);
     if (!isset($languages[$langcode]) || $this->hasTranslation($langcode)) {
       $message = 'Invalid translation language (@langcode) specified.';
-      throw new \InvalidArgumentException(format_string($message, array('@langcode' => $langcode)));
+      throw new \InvalidArgumentException($this->formatString($message, array('@langcode' => $langcode)));
     }
 
     // Instantiate a new empty entity so default values will be populated in the
     // specified language.
     $info = $this->entityInfo();
     $default_values = array($info['entity_keys']['bundle'] => $this->bundle, 'langcode' => $langcode);
-    $entity = \Drupal::entityManager()
+    $entity = $this->entityManager()
       ->getStorageController($this->entityType())
       ->create($default_values);
 
@@ -733,7 +761,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($this->formatString($message, array('@langcode' => $langcode)));
     }
   }
 
@@ -759,7 +787,7 @@ public function getTranslationLanguages($include_default = TRUE) {
     }
 
     // Now load language objects based upon translation langcodes.
-    return array_intersect_key(language_list(Language::STATE_ALL), $translations);
+    return array_intersect_key($this->languageList(Language::STATE_ALL), $translations);
   }
 
   /**
@@ -876,7 +904,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($this->formatString($message, array('@langcode' => $this->activeLangcode)));
     }
 
     $duplicate = clone $this;
@@ -885,8 +913,7 @@ public function createDuplicate() {
 
     // Check if the entity type supports UUIDs and generate a new one if so.
     if (!empty($entity_info['entity_keys']['uuid'])) {
-      // @todo Inject the UUID service into the Entity class once possible.
-      $duplicate->{$entity_info['entity_keys']['uuid']}->value = \Drupal::service('uuid')->generate();
+      $duplicate->{$entity_info['entity_keys']['uuid']}->value = $this->uuidGenerator()->generate();
     }
 
     // Check whether the entity type supports revisions and initialize it if so.
diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php
index 745ef83..fce463b 100644
--- a/core/lib/Drupal/Core/Entity/Entity.php
+++ b/core/lib/Drupal/Core/Entity/Entity.php
@@ -62,6 +62,31 @@ 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() {
+    return \Drupal::entityManager();
+  }
+
+  /**
+   * Returns the UUID generator.
+   *
+   * @return \Drupal\Component\Uuid\UuidInterface
+   */
+  protected function uuidGenerator() {
+    return \Drupal::service('uuid');
+  }
+
+  /**
    * {@inheritdoc}
    */
   public function id() {
@@ -87,6 +112,8 @@ public function isNew() {
    */
   public function enforceIsNew($value = TRUE) {
     $this->enforceIsNew = $value;
+
+    return $this;
   }
 
   /**
@@ -109,8 +136,8 @@ public function bundle() {
   public function label($langcode = NULL) {
     $label = NULL;
     $entity_info = $this->entityInfo();
-    if (isset($entity_info['label_callback']) && function_exists($entity_info['label_callback'])) {
-      $label = $entity_info['label_callback']($this->entityType, $this, $langcode);
+    if (isset($entity_info['label_callback']) && is_callable($entity_info['label_callback'])) {
+      $label = call_user_func($entity_info['label_callback'], $this->entityType, $this, $langcode);
     }
     elseif (!empty($entity_info['entity_keys']['label']) && isset($this->{$entity_info['entity_keys']['label']})) {
       $label = $this->{$entity_info['entity_keys']['label']};
@@ -181,7 +208,7 @@ public function uri($rel = 'canonical') {
     $bundle = $this->bundle();
     // A bundle-specific callback takes precedence over the generic one for
     // the entity type.
-    $bundles = entity_get_bundles($this->entityType);
+    $bundles = $this->entityManager()->getBundleInfo($this->entityType);
     if (isset($bundles[$bundle]['uri_callback'])) {
       $uri_callback = $bundles[$bundle]['uri_callback'];
     }
@@ -191,8 +218,8 @@ public function uri($rel = 'canonical') {
 
     // Invoke the callback to get the URI. If there is no callback, use the
     // default URI format.
-    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);
     }
     // Only use these defaults for a canonical link (that is, a link to self).
     // Other relationship types are not supported by this logic.
@@ -251,13 +278,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->entityType)
         ->createAccess($this->bundle(), $account);
     }
-    return \Drupal::entityManager()
+    return $this->entityManager()
       ->getAccessController($this->entityType)
       ->access($this, $operation, Language::LANGCODE_DEFAULT, $account);
   }
@@ -266,7 +293,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));
@@ -278,7 +305,7 @@ public function language() {
    * {@inheritdoc}
    */
   public function save() {
-    return \Drupal::entityManager()->getStorageController($this->entityType)->save($this);
+    return $this->entityManager()->getStorageController($this->entityType)->save($this);
   }
 
   /**
@@ -286,7 +313,7 @@ public function save() {
    */
   public function delete() {
     if (!$this->isNew()) {
-      \Drupal::entityManager()->getStorageController($this->entityType)->delete(array($this->id() => $this));
+      $this->entityManager()->getStorageController($this->entityType)->delete(array($this->id() => $this));
     }
   }
 
@@ -300,8 +327,7 @@ public function createDuplicate() {
 
     // Check if the entity type supports UUIDs and generate a new one if so.
     if (!empty($entity_info['entity_keys']['uuid'])) {
-      // @todo Inject the UUID service into the Entity class once possible.
-      $duplicate->{$entity_info['entity_keys']['uuid']} = \Drupal::service('uuid')->generate();
+      $duplicate->{$entity_info['entity_keys']['uuid']} = $this->uuidGenerator()->generate();
     }
     return $duplicate;
   }
@@ -310,7 +336,7 @@ public function createDuplicate() {
    * {@inheritdoc}
    */
   public function entityInfo() {
-    return \Drupal::entityManager()->getDefinition($this->entityType());
+    return $this->entityManager()->getDefinition($this->entityType());
   }
 
   /**
@@ -379,8 +405,8 @@ public function changed() {
     }
 
     foreach ($referenced_entity_ids as $entity_type => $entity_ids) {
-      if (\Drupal::entityManager()->hasController($entity_type, 'view_builder')) {
-        \Drupal::entityManager()->getViewBuilder($entity_type)->resetCache(array_keys($entity_ids));
+      if ($this->entityManager()->hasController($entity_type, 'view_builder')) {
+        $this->entityManager()->getViewBuilder($entity_type)->resetCache(array_keys($entity_ids));
       }
     }
   }
diff --git a/core/lib/Drupal/Core/Entity/EntityInterface.php b/core/lib/Drupal/Core/Entity/EntityInterface.php
index f02bb1e..b2bb238 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/modules/block/block.module b/core/modules/block/block.module
index e1bc631..aaf3937 100644
--- a/core/modules/block/block.module
+++ b/core/modules/block/block.module
@@ -239,7 +239,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');
       }
     }
@@ -435,7 +435,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/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/lib/Drupal/system/Tests/Entity/EntityUriTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUriTest.php
deleted file mode 100644
index 381d8b0..0000000
--- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUriTest.php
+++ /dev/null
@@ -1,40 +0,0 @@
-<?php
-
-/**
- * @file
- * Contains \Drupal\system\Tests\Entity\EntityUriTest.
- */
-
-namespace Drupal\system\Tests\Entity;
-
-/**
- * Tests the basic Entity API.
- */
-class EntityUriTest extends EntityUnitTestBase {
-
-  public static function getInfo() {
-    return array(
-      'name' => 'Entity URI',
-      'description' => 'Tests default URI functionality.',
-      'group' => 'Entity API',
-    );
-  }
-
-  public function setUp() {
-    parent::setUp();
-    $this->installSchema('system', array('variable', 'url_alias'));
-  }
-
-  /**
-   * Tests that an entity without a URI callback uses the default URI.
-   */
-  function testDefaultUri() {
-    // Create a test entity.
-    $entity = entity_create('entity_test_no_label', array('name' => 'test', 'user_id' => 1));
-    $entity->save();
-    $uri = $entity->uri();
-    $expected_path = 'entity/entity_test_no_label/' . $entity->id();
-    $this->assertEqual(url($uri['path'], $uri['options']), url($expected_path), 'Entity without URI callback returns expected URI.');
-  }
-
-}
diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/FieldSqlStorageTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/FieldSqlStorageTest.php
index 45d997f..5127a68 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Entity/FieldSqlStorageTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Entity/FieldSqlStorageTest.php
@@ -258,7 +258,7 @@ function testFieldWrite() {
    */
   function testLongNames() {
     // Use one of the longest entity_type names in core.
-    $entity_type = $bundle = 'entity_test_label_callback';
+    $entity_type = $bundle = 'entity_test_label';
     $storage_controller = $this->container->get('entity.manager')->getStorageController($entity_type);
 
     // Create two fields with instances, and generate randome values.
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 2348856..94c454c 100644
--- a/core/modules/system/tests/modules/entity_test/entity_test.module
+++ b/core/modules/system/tests/modules/entity_test/entity_test.module
@@ -375,23 +375,6 @@ function entity_test_entity_test_insert($entity) {
 }
 
 /**
- * Entity label callback.
- *
- * @param $entity_type
- *   The entity type.
- * @param $entity
- *   The entity object.
- * @param $langcocde
- *   (optional) The langcode.
- *
- * @return
- *   The label of the entity prefixed with "label callback".
- */
-function entity_test_label_callback($entity_type, $entity, $langcode = NULL) {
-  return 'label callback ' . $entity->name->value;
-}
-
-/**
  * Implements hook_entity_field_access().
  *
  * @see \Drupal\system\Tests\Entity\FieldAccessTest::testFieldAccess()
diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestLabelCallback.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestLabelCallback.php
deleted file mode 100644
index 92012a3..0000000
--- a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestLabelCallback.php
+++ /dev/null
@@ -1,35 +0,0 @@
-<?php
-
-/**
- * @file
- * Contains \Drupal\entity_test\Entity\EntityTestLabelCallback.
- */
-
-namespace Drupal\entity_test\Entity;
-
-use Drupal\Core\Entity\Annotation\EntityType;
-use Drupal\Core\Annotation\Translation;
-
-/**
- * Test entity class.
- *
- * @EntityType(
- *   id = "entity_test_label_callback",
- *   label = @Translation("Entity test label callback"),
- *   controllers = {
- *     "storage" = "Drupal\entity_test\EntityTestStorageController"
- *   },
- *   field_cache = FALSE,
- *   base_table = "entity_test",
- *   revision_table = "entity_test_revision",
- *   label_callback = "entity_test_label_callback",
- *   fieldable = TRUE,
- *   entity_keys = {
- *     "id" = "id",
- *     "bundle" = "type"
- *   }
- * )
- */
-class EntityTestLabelCallback extends EntityTest {
-
-}
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..ddfcb47
--- /dev/null
+++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php
@@ -0,0 +1,272 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Tests\Core\Config\Entity\ConfigEntityBaseUnitTest.
+ */
+
+namespace Drupal\Tests\Core\Config\Entity;
+
+use Drupal\Tests\UnitTestCase;
+
+/**
+ * Tests \Drupal\Core\Config\Entity\ConfigEntityBase;
+ */
+class ConfigEntityBaseUnitTest extends UnitTestCase {
+
+  /**
+   * The entity under test.
+   *
+   * @var \Drupal\Core\Config\Entity\ConfigEntityBase
+   */
+  protected $entity;
+
+  /**
+   * The entity manager used for testing.
+   *
+   * @var \Drupal\Core\Entity\EntityManagerInterface
+   */
+  protected $entityManager;
+
+  /**
+   * The type of the entity under test.
+   *
+   * @var string
+   */
+  protected $entityType;
+
+  /**
+   * The route provider used for testing.
+   *
+   * @var \Drupal\Core\Routing\RouteProvider
+   */
+  protected $routeProvider;
+
+  /**
+   * The UUID generator used for testing.
+   *
+   * @var \Drupal\Component\Uuid\UuidInterface
+   */
+  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->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
+
+    $this->routeProvider = $this->getMockBuilder('\Drupal\Core\Routing\RouteProvider')
+      ->disableOriginalConstructor()
+      ->getMock();
+
+    $this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface');
+
+    $this->entity = $this->getMockBuilder('\Drupal\Core\Config\Entity\ConfigEntityBase')
+      ->setConstructorArgs(array($values, $this->entityType))
+      ->setMethods(array('entityManager', 'formatString', 'languageLoad', 'routeProvider', 'uuidGenerator'))
+      ->getMock();
+    $this->entity->expects($this->any())
+      ->method('formatString')
+      ->will($this->returnArgument(0));
+    $this->entity->expects($this->any())
+      ->method('entityManager')
+      ->will($this->returnValue($this->entityManager));
+    $this->entity->expects($this->any())
+      ->method('routeProvider')
+      ->will($this->returnValue($this->routeProvider));
+    $this->entity->expects($this->any())
+      ->method('uuidGenerator')
+      ->will($this->returnValue($this->uuid));
+    $this->entity->expects($this->any())
+      ->method('languageLoad')
+      ->will($this->returnValue(NULL));
+  }
+
+  /**
+   * Tests setOriginalId() and 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());
+  }
+
+  /**
+   * Tests 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());
+  }
+
+  /**
+   * Tests set() and 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));
+  }
+
+  /**
+   * Tests setStatus() and 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());
+  }
+
+  /**
+   * Tests 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());
+  }
+
+  /**
+   * Tests 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());
+  }
+
+  /**
+   * Tests setSyncing() and 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());
+  }
+
+  /**
+   * Tests createDuplicate().
+   */
+  public function testCreateDuplicate() {
+    $this->entityManager->expects($this->at(0))
+      ->method('getDefinition')
+      ->with($this->entityType)
+      ->will($this->returnValue(array(
+        'entity_keys' => array(
+          'id' => 'id',
+          'uuid' => 'uuid',
+        ),
+      )));
+    $this->entity->setOriginalId('foo');
+    $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());
+  }
+
+  /**
+   * Tests 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, array('\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]));
+  }
+
+  /**
+   * Tests getExportProperties().
+   */
+  public function testGetExportProperties() {
+    $properties = $this->entity->getExportProperties();
+    $this->assertInternalType('array', $properties);
+  }
+
+  /**
+   * Tests 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);
+  }
+
+  /**
+   * Tests uri().
+   */
+  public function testUri() {
+    // The only difference between ConfigEntityBase::uri() and Entity::uri() is
+    // how link templates are processed, so only test those.
+    $this->entity->id = $this->randomName();
+    $expected_template_path = 'foo/' . $this->entity->id();
+    $route_name = 'foo.bar';
+    $route_path = 'foo/{id}';
+    $this->entityManager->expects($this->once())
+      ->method('getDefinition')
+      ->with($this->entityType)
+      ->will($this->returnValue(array(
+        'links' => array(
+          'edit-form' => $route_name,
+        ),
+      )));
+    $route = $this->getMockBuilder('\Symfony\Component\Routing\Route')
+      ->disableOriginalConstructor()
+      ->getMock();
+    $route->expects($this->once())
+      ->method('getPath')
+      ->will($this->returnValue($route_path));
+    $this->routeProvider->expects($this->once())
+      ->method('getRouteByName')
+      ->with($route_name)
+      ->will($this->returnValue($route));
+
+    $actual_template_uri = $this->entity->uri();
+    $this->assertSame($expected_template_path, $actual_template_uri['path']);
+  }
+}
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..3421d65
--- /dev/null
+++ b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php
@@ -0,0 +1,582 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Tests\Core\Entity\ContentEntityBaseUnitTest.
+ */
+
+namespace Drupal\Tests\Core\Entity;
+
+use Drupal\Tests\UnitTestCase;
+
+/**
+ * Tests \Drupal\Core\Entity\ContentEntityBase;
+ */
+class ContentEntityBaseUnitTest extends UnitTestCase {
+
+  /**
+   * The bundle of the entity under test.
+   *
+   * @var string
+   */
+  protected $bundle;
+
+  /**
+   * The entity under test.
+   *
+   * @var \Drupal\Core\Entity\ContentEntityBase
+   */
+  protected $entity;
+
+  /**
+   * The entity manager used for testing.
+   *
+   * @var \Drupal\Core\Entity\EntityManagerInterface
+   */
+  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
+   */
+  protected $typedDataManager;
+
+  /**
+   * The UUID generator used for testing.
+   *
+   * @var \Drupal\Component\Uuid\UuidInterface
+   */
+  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->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
+    $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();
+
+    $this->entity = $this->getMockBuilder('\Drupal\Core\Entity\ContentEntityBase')
+      ->setConstructorArgs(array($values, $this->entityType, $this->bundle))
+      ->setMethods(array('checkPlain', 'entityManager', 'formatString', 'languageList', 'languageLoad', 'typedDataManager', 'uuidGenerator'))
+      ->getMockForAbstractClass();
+    $this->entity->expects($this->any())
+      ->method('checkPlain')
+      ->will($this->returnArgument(0));
+    $this->entity->expects($this->any())
+      ->method('entityManager')
+      ->will($this->returnValue($this->entityManager));
+    $this->entity->expects($this->any())
+      ->method('formatString')
+      ->will($this->returnArgument(0));
+    $this->entity->expects($this->any())
+      ->method('languageList')
+      ->will($this->returnValue(array()));
+    $this->entity->expects($this->any())
+      ->method('languageLoad')
+      ->will($this->returnValue(NULL));
+    $this->entity->expects($this->any())
+      ->method('typedDataManager')
+      ->will($this->returnValue($this->typedDataManager));
+    $this->entity->expects($this->any())
+      ->method('uuidGenerator')
+      ->will($this->returnValue($this->uuid));
+  }
+
+  /**
+   * Tests isNewRevision() and setNewRevision().
+   */
+  public function testIsNewRevision() {
+    $this->entityManager->expects($this->at(3))
+      ->method('getDefinition')
+      ->with($this->entityType)
+      ->will($this->returnValue(array(
+        'entity_keys' => array(
+          'revision' => $this->randomName(),
+        ),
+      )));
+    // The value defaults to FALSE.
+    $this->assertFalse($this->entity->isNewRevision());
+    // Set the value explicitly and test it is returned.
+    $this->entity->setNewRevision(TRUE);
+    $this->assertTrue($this->entity->isNewRevision());
+    // Reset the value and test it is returned.
+    $this->entity->setNewRevision(FALSE);
+    $this->assertFalse($this->entity->isNewRevision());
+    // Because isNewRevision() can now find an entity key, it returns TRUE.
+    $this->assertTrue($this->entity->isNewRevision());
+  }
+
+  /**
+   * Tests 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());
+  }
+
+  /**
+   * Tests getRevisionId().
+   */
+  public function testGetRevisionId() {
+    $this->assertNull($this->entity->getRevisionId());
+  }
+
+  /**
+   * Tests 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());
+  }
+
+  /**
+   * Tests 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);
+  }
+
+  /**
+   * Tests getDefinition().
+   */
+  public function testGetDefinition() {
+    $definition = $this->entity->getDefinition();
+    $this->assertInternalType('array', $definition);
+    $this->arrayHasKey('type', $definition);
+    $this->assertInternalType('string', $definition['type']);
+  }
+
+  /**
+   * Tests getValue().
+   */
+  public function testGetValue() {
+    // @todo Finish this test method.
+    $this->fail();
+  }
+
+  /**
+   * Tests setValue().
+   */
+  public function testSetValue() {
+    // @todo Finish this test method.
+    $this->fail();
+  }
+
+  /**
+   * Tests getString().
+   */
+  public function testGetString() {
+    $this->assertInternalType('string', $this->entity->getString());
+  }
+
+  /**
+   * Tests validate().
+   */
+  public function testValidate() {
+    $validator = $this->getMock('\Symfony\Component\Validator\ValidatorInterface');
+    $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()));
+  }
+
+  /**
+   * Tests applyDefaultValue().
+   */
+  public function testApplyDefaultValue() {
+    // @todo Finish this test method.
+    $this->fail();
+  }
+
+  /**
+   * Tests getConstraints().
+   */
+  public function testGetConstraints() {
+    $this->assertInternalType('array', $this->entity->getConstraints());
+  }
+
+  /**
+   * Tests getName().
+   */
+  public function testGetName() {
+    $this->assertNull($this->entity->getConstraints());
+  }
+
+  /**
+   * Tests getRoot().
+   */
+  public function testGetRoot() {
+    $this->assertSame(spl_object_hash($this->entity), spl_object_hash($this->entity->getRoot()));
+  }
+
+  /**
+   * Tests getPropertyPath().
+   */
+  public function testGetPropertyPath() {
+    $this->assertSame('', $this->entity->getPropertyPath());
+  }
+
+  /**
+   * Tests getParent().
+   */
+  public function testGetParent() {
+    $this->assertNull($this->entity->getParent());
+  }
+
+  /**
+   * Tests setContext().
+   */
+  public function testSetContext() {
+    $name = $this->randomName();
+    $parent = $this->getMock('\Drupal\Core\TypedData\TypedDataInterface');
+    $this->entity->setContext($name, $parent);
+  }
+
+  /**
+   * Tests id().
+   */
+  public function testId() {
+    // @todo Finish this test method.
+    $this->fail();
+  }
+
+  /**
+   * Tests bundle().
+   */
+  public function testBundle() {
+    $this->assertSame($this->bundle, $this->entity->bundle());
+  }
+
+  /**
+   * Tests uuid().
+   */
+  public function testUuid() {
+    // @todo Finish this test method.
+    $this->fail();
+  }
+
+  /**
+   * Tests hasField().
+   */
+  public function testHasField() {
+    // @todo Finish this test method.
+    $this->fail();
+  }
+
+  /**
+   * Tests get().
+   */
+  public function testGet() {
+    // @todo Finish this test method.
+    $this->fail();
+  }
+
+  /**
+   * Tests set().
+   */
+  public function testSet() {
+    // @todo Finish this test method.
+    $this->fail();
+  }
+
+  /**
+   * Tests getProperties().
+   */
+  public function testGetProperties() {
+    // @todo Finish this test method.
+    $this->fail();
+    $properties = $this->entity->getProperties();
+    $this->assertInternalType('array', $properties);
+    $this->assertArrayHasKey('id', $properties);
+  }
+
+  /**
+   * Tests getIterator().
+   */
+  public function testGetIterator() {
+    $this->assertInstanceOf('\Traversable', $this->entity->getIterator());
+  }
+
+  /**
+   * Tests getPropertyDefinition().
+   */
+  public function testGetPropertyDefinition() {
+    $this->entityManager->expects($this->once())
+      ->method('getFieldDefinitions')
+      ->with($this->entityType, $this->bundle)
+      ->will($this->returnValue($this->entity->baseFieldDefinitions($this->entityType)));
+    $definition = $this->entity->getPropertyDefinition('id');
+    $this->assertInternalType('array', $definition);
+    $this->arrayHasKey('type', $definition);
+  }
+
+  /**
+   * Tests getPropertyDefinitions().
+   */
+  public function testGetPropertyDefinitions() {
+    $definitions = $this->entity->getPropertyDefinitions();
+    $this->assertInternalType('array', $definitions);
+    $this->arrayHasKey('id', $definitions);
+  }
+
+  /**
+   * Tests getPropertyValues().
+   */
+  public function testGetPropertyValues() {
+    // @todo Finish this test method.
+    $this->fail();
+  }
+
+  /**
+   * Tests setPropertyValues().
+   */
+  public function testSetPropertyValues() {
+    // @todo Finish this test method.
+    $this->fail();
+  }
+
+  /**
+   * Tests isEmpty().
+   */
+  public function testIsEmpty() {
+    // @todo Finish this test method.
+    $this->fail();
+  }
+
+  /**
+   * Tests 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'));
+  }
+
+  /**
+   * Tests language().
+   */
+  public function testLanguage() {
+    // @todo Finish this test method.
+    $this->fail();
+  }
+
+  /**
+   * Tests onChange().
+   */
+  public function testOnChange() {
+    // @todo Finish this test method.
+    $this->fail();
+  }
+
+  /**
+   * Tests getTranslation().
+   */
+  public function testGetTranslation() {
+    // @todo Finish this test method.
+    $this->fail();
+  }
+
+  /**
+   * Tests getUntranslated().
+   */
+  public function testGetUntranslated() {
+    // @todo Finish this test method.
+    $this->fail();
+  }
+
+  /**
+   * Tests hasTranslation().
+   */
+  public function testHasTranslation() {
+    // @todo Finish this test method.
+    $this->fail();
+  }
+
+  /**
+   * Tests addTranslation().
+   */
+  public function testAddTranslation() {
+    // @todo Finish this test method.
+    $this->fail();
+  }
+
+  /**
+   * Tests removeTranslation().
+   */
+  public function testRemoveTranslation() {
+    // @todo Finish this test method.
+    $this->fail();
+  }
+
+  /**
+   * Tests initTranslation().
+   */
+  public function testInitTranslation() {
+    // @todo Finish this test method.
+    $this->fail();
+  }
+
+  /**
+   * Tests getTranslationLanguages().
+   */
+  public function testGetTranslationLanguages() {
+    // @todo Finish this test method.
+    $this->fail();
+  }
+
+  /**
+   * Tests translations().
+   */
+  public function testTranslations() {
+    // @todo Finish this test method.
+    $this->fail();
+  }
+
+  /**
+   * Tests updateOriginalValues().
+   */
+  public function testUpdateOriginalValues() {
+    // @todo Finish this test method.
+    $this->fail();
+  }
+
+  /**
+   * Tests createDuplicate().
+   */
+  public function testCreateDuplicate() {
+    $this->entityManager->expects($this->at(0))
+      ->method('getDefinition')
+      ->with($this->entityType)
+      ->will($this->returnValue(array(
+        'entity_keys' => array(
+          'id' => 'id',
+          'revision' => 'revision',
+          'uuid' => 'uuid',
+        ),
+      )));
+    $duplicate = $this->entity->createDuplicate();
+    $this->assertInstanceOf('\Drupal\Core\Entity\Entity', $duplicate);
+    $this->assertNotSame(spl_object_hash($this->entity), spl_object_hash($duplicate));
+  }
+
+  /**
+   * Tests 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->entityManager->expects($this->at(0))
+      ->method('getDefinition')
+      ->with($this->entityType)
+      ->will($this->returnValue(array(
+        'label_callback' => array($callback_container, __FUNCTION__),
+      )));
+
+    // 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->entityType)
+      ->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());
+  }
+
+  /**
+   * Tests referencedEntities().
+   */
+  public function testReferencedEntities() {
+    // @todo Finish this test method.
+    $this->fail();
+  }
+}
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..2076611
--- /dev/null
+++ b/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php
@@ -0,0 +1,402 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Tests\Core\Entity\EntityUnitTest.
+ */
+
+namespace Drupal\Tests\Core\Entity;
+
+use Drupal\Tests\UnitTestCase;
+
+/**
+ * Tests \Drupal\Core\Entity\Entity;
+ */
+class EntityUnitTest extends UnitTestCase {
+
+  /**
+   * The entity under test.
+   *
+   * @var \Drupal\Core\Entity\Entity
+   */
+  protected $entity;
+
+  /**
+   * The entity manager used for testing.
+   *
+   * @var \Drupal\Core\Entity\EntityManagerInterface
+   */
+  protected $entityManager;
+
+  /**
+   * The type of the entity under test.
+   *
+   * @var string
+   */
+  protected $entityType;
+
+  /**
+   * The route provider used for testing.
+   *
+   * @var \Drupal\Core\Routing\RouteProvider
+   */
+  protected $routeProvider;
+
+  /**
+   * The UUID generator used for testing.
+   *
+   * @var \Drupal\Component\Uuid\UuidInterface
+   */
+  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->entityType = $this->randomName();
+
+    $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
+
+    $this->routeProvider = $this->getMockBuilder('\Drupal\Core\Routing\RouteProvider')
+      ->disableOriginalConstructor()
+      ->getMock();
+
+    $this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface');
+
+    $this->entity = $this->getMockBuilder('\Drupal\Core\Entity\Entity')
+      ->setConstructorArgs(array($values, $this->entityType))
+      ->setMethods(array('entityManager', 'uuidGenerator', 'languageLoad', 'routeProvider'))
+      ->getMock();
+    $this->entity->expects($this->any())
+      ->method('entityManager')
+      ->will($this->returnValue($this->entityManager));
+    $this->entity->expects($this->any())
+      ->method('languageLoad')
+      ->will($this->returnValue(NULL));
+    $this->entity->expects($this->any())
+      ->method('routeProvider')
+      ->will($this->returnValue($this->routeProvider));
+    $this->entity->expects($this->any())
+      ->method('uuidGenerator')
+      ->will($this->returnValue($this->uuid));
+  }
+
+  /**
+   * Tests id().
+   */
+  public function testId() {
+    // @todo How to test this?
+    $this->assertNull($this->entity->id());
+  }
+
+  /**
+   * Tests uuid().
+   */
+  public function testUuid() {
+    // @todo How to test this?
+    $this->assertNull($this->entity->uuid());
+  }
+
+  /**
+   * Tests isNew().
+   */
+  public function testIsNew() {
+    // @todo How to test this?
+    $this->assertInternalType('bool', $this->entity->isNew());
+  }
+
+  /**
+   * Tests enforceIsNew().
+   */
+  public function testEnforceIsNew() {
+    $this->assertSame(spl_object_hash($this->entity), spl_object_hash($this->entity->enforceIsNew()));
+  }
+
+  /**
+   * Tests entityType().
+   */
+  public function testEntityType() {
+    $this->assertSame($this->entityType, $this->entity->entityType());
+  }
+
+  /**
+   * Tests bundle().
+   */
+  public function testBundle() {
+    $this->assertSame($this->entityType, $this->entity->bundle());
+  }
+
+  /**
+   * Tests 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->entityManager->expects($this->at(0))
+      ->method('getDefinition')
+      ->with($this->entityType)
+      ->will($this->returnValue(array(
+        'label_callback' => array($callback_container, __FUNCTION__),
+      )));
+
+    // 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->entityType)
+      ->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());
+  }
+
+  /**
+   * Tests uri().
+   */
+  public function testUri() {
+    // Test link templates.
+    $this->entity->id = $this->randomName();
+    $expected_template_path = 'foo/' . $this->entity->id();
+    $route_name = 'foo.bar';
+    $route_path = 'foo/{id}';
+    $this->entityManager->expects($this->at(0))
+      ->method('getDefinition')
+      ->with($this->entityType)
+      ->will($this->returnValue(array(
+        'links' => array(
+          'canonical' => $route_name,
+        ),
+      )));
+    $route = $this->getMockBuilder('\Symfony\Component\Routing\Route')
+      ->disableOriginalConstructor()
+      ->getMock();
+    $route->expects($this->once())
+      ->method('getPath')
+      ->will($this->returnValue($route_path));
+    $this->routeProvider->expects($this->once())
+      ->method('getRouteByName')
+      ->with($route_name)
+      ->will($this->returnValue($route));
+
+    // 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 uri is the callback's
+    // return value.
+    $expected_callback_path = $this->randomName();
+    $uri = array(
+      'path' => $expected_callback_path,
+    );
+    $callback_container = $this->getMock(get_class());
+    $callback_container->expects($this->once())
+      ->method(__FUNCTION__)
+      ->will($this->returnValue($uri));
+    $this->entityManager->expects($this->at(2))
+      ->method('getBundleInfo')
+      ->with($this->entityType)
+      ->will($this->returnValue(array(
+        $this->entityType => array(
+          'uri_callback' => array($callback_container, __FUNCTION__),
+        ),
+      )));
+
+    $actual_template_uri = $this->entity->uri();
+    $this->assertSame($expected_template_path, $actual_template_uri['path']);
+
+    $actual_callback_uri = $this->entity->uri();
+    $this->assertSame($expected_callback_path, $actual_callback_uri['path']);
+
+    $expected_fallback_path = 'entity/' . $this->entityType . '/' . $this->entity->id();
+    $actual_fallback_uri = $this->entity->uri();
+    $this->assertSame($expected_fallback_path, $actual_fallback_uri['path']);
+  }
+
+  /**
+   * Tests 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'));
+  }
+
+  /**
+   * Tests language().
+   */
+  public function testLanguage() {
+    $this->assertInstanceOf('\Drupal\Core\Language\Language', $this->entity->language());
+  }
+
+  /**
+   * Tests 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->entityType)
+      ->will($this->returnValue($storage));
+    $this->entity->save();
+  }
+
+  /**
+   * Tests 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->entityType)
+      ->will($this->returnValue($storage));
+    $this->entity->delete();
+  }
+
+  /**
+   * Tests createDuplicate().
+   */
+  public function testCreateDuplicate() {
+    $this->entityManager->expects($this->at(0))
+      ->method('getDefinition')
+      ->with($this->entityType)
+      ->will($this->returnValue(array(
+        'entity_keys' => array(
+          'id' => 'id',
+          'uuid' => 'uuid',
+        ),
+      )));
+    $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->uuid());
+  }
+
+  /**
+   * Tests entityInfo().
+   */
+  public function testEntityInfo() {
+    $this->entityManager->expects($this->once())
+      ->method('getDefinition')
+      ->with($this->entityType);
+    $this->entity->entityInfo();
+  }
+
+  /**
+   * Tests 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);
+  }
+
+  /**
+   * Tests 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);
+  }
+
+  /**
+   * Tests 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);
+  }
+
+  /**
+   * Tests 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);
+  }
+
+  /**
+   * Tests 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));
+  }
+
+  /**
+   * Tests 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));
+  }
+
+  /**
+   * Tests postLoad().
+   */
+  public function testPostLoad() {
+    // This method is internal, so check for errors on calling it only.
+    $storage = $this->getMock('\Drupal\Core\Entity\EntityStorageControllerInterface');
+    $this->entity->postLoad($storage, array($this->entity));
+  }
+
+  /**
+   * Tests referencedEntities().
+   */
+  public function testReferencedEntities() {
+    $this->assertSame(array(), $this->entity->referencedEntities());
+  }
+
+  /**
+   * Tests changed().
+   */
+  public function testChanged() {
+    // This method is internal, so check for errors on calling it only.
+    $this->entity->changed();
+  }
+}
