function EntityPropertiesTest::testEntityLabel

Tests label key and label callback of an entity.

File

drupal/core/modules/field/lib/Drupal/field/Tests/EntityPropertiesTest.php, line 33
Definition of Drupal\field\Tests\EntityPropertiesTest.

Class

EntityPropertiesTest
Tests entity properties.

Namespace

Drupal\field\Tests

Code

function testEntityLabel() {
  $entity_types = array(
    'test_entity_no_label',
    'test_entity_label',
    'test_entity_label_callback',
  );

  // @todo Remove once test_entity entity has been merged with entity_test.
  $values = array(
    'ftlabel' => $this
      ->randomName(),
  );
  foreach ($entity_types as $entity_type) {
    $entity = entity_create($entity_type, $values);
    $label = $entity
      ->label();
    switch ($entity_type) {
      case 'test_entity_no_label':
        $this
          ->assertFalse($label, 'Entity with no label property or callback returned FALSE.');
        break;
      case 'test_entity_label':
        $this
          ->assertEqual($label, $entity->ftlabel, 'Entity with label key returned correct label.');
        break;
      case 'test_entity_label_callback':
        $this
          ->assertEqual($label, 'label callback ' . $entity->ftlabel, 'Entity with label callback returned correct label.');
        break;
    }
  }
}