function EntityPropertiesTestCase::testEntityLabel

7.x field.test EntityPropertiesTestCase::testEntityLabel()

Tests label key and label callback of an entity.

File

drupal-7.x/modules/field/tests/field.test, line 3682
Tests for field.module.

Class

EntityPropertiesTestCase
Tests entity properties.

Code

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

  $entity = field_test_create_stub_entity();

  foreach ($entity_types as $entity_type) {
    $label = entity_label($entity_type, $entity);

    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;
    }
  }
}