Commit 9a2cb6ad authored by alexpott's avatar alexpott

Issue #2134857 by Xano: PHPUnit test the entity base classes.

parent 1fa8170e
......@@ -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.
......@@ -125,6 +126,8 @@ public function set($property_name, $value) {
}
$this->{$property_name} = $value;
return $this;
}
/**
......@@ -161,6 +164,8 @@ public function status() {
*/
public function setSyncing($syncing) {
$this->isSyncing = $syncing;
return $this;
}
/**
......@@ -184,7 +189,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) {
......@@ -231,14 +236,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())));
}
}
}
......
......@@ -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);
......
......@@ -128,13 +128,20 @@ abstract class ContentEntityBase extends Entity implements \IteratorAggregate, C
*/
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
......@@ -161,6 +168,26 @@ public function __construct(array $values, $entity_type, $bundle = FALSE, $trans
$this->init();
}
/**
* 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}
*/
......@@ -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']);
}
......@@ -239,15 +265,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);
}
/**
......@@ -333,10 +358,7 @@ public function __sleep() {
$this->fieldDefinitions = NULL;
$this->clearTranslationCache();
// Don't serialize the url generator.
$this->urlGenerator = NULL;
return array_keys(get_object_vars($this));
return parent::__sleep();
}
......@@ -344,6 +366,7 @@ public function __sleep() {
* Magic __wakeup() implementation.
*/
public function __wakeup() {
parent::__wakeup();
$this->init();
}
......@@ -393,7 +416,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.
......@@ -526,13 +549,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);
}
......@@ -544,7 +567,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];
}
......@@ -594,7 +617,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);
......@@ -643,7 +666,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;
......@@ -708,14 +731,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);
......@@ -753,7 +776,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)));
}
}
......@@ -895,7 +918,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;
......@@ -904,8 +927,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.
......@@ -953,9 +975,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;
......
......@@ -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.
......@@ -22,6 +23,20 @@ abstract class Entity implements EntityInterface {
*/
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.
*
......@@ -60,6 +75,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}
*/
......@@ -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));
}
}
......@@ -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);
......
......@@ -63,7 +63,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.
*/
......
......@@ -199,7 +199,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');
}
}
......@@ -378,7 +378,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;
......
......@@ -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\Config\Entity\EntityWithPluginBagInterface;
/**
......@@ -148,7 +149,7 @@ public function getExportProperties() {
/**
* 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) {
......
......@@ -97,14 +97,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);
}
}
......@@ -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.
......@@ -93,7 +94,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);
}
......
......@@ -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.
......@@ -60,7 +61,9 @@ abstract class EntityDisplayModeBase extends ConfigEntityBase implements EntityD
/**
* {@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();
......
......@@ -8,6 +8,7 @@
namespace Drupal\search\Entity;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
use Drupal\Core\Config\Entity\EntityWithPluginBagInterface;
use Drupal\Core\Entity\EntityStorageControllerInterface;
use Drupal\Component\Plugin\ConfigurablePluginInterface;
......@@ -213,7 +214,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();
......
......@@ -8,6 +8,7 @@
namespace Drupal\system\Entity;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
use Drupal\Core\Config\Entity\EntityWithPluginBagInterface;
use Drupal\system\ActionConfigEntityInterface;
use Drupal\Core\Action\ActionBag;
......@@ -131,7 +132,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) {
......
<?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;
}
}
}