You are here

public function ContentEntityBaseUnitTest::testLabel in Drupal 8

@covers ::label

@group legacy

File

core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php, line 480

Class

ContentEntityBaseUnitTest
@coversDefaultClass \Drupal\Core\Entity\ContentEntityBase @group Entity @group Access

Namespace

Drupal\Tests\Core\Entity

Code

public function testLabel() {
  $this
    ->addExpectedDeprecationMessage('Entity type ' . $this->entityTypeId . ' defines a label callback. Support for that is deprecated in drupal:8.0.0 and will be removed in drupal:9.0.0. Override the EntityInterface::label() method instead. See https://www.drupal.org/node/3050794');

  // Make a mock with one method that we use as the entity's label callback.
  // We check that it is called, and that the entity's label is the callback's
  // return value.
  $callback_label = $this
    ->randomMachineName();
  $callback_container = $this
    ->createMock(get_class());
  $callback_container
    ->expects($this
    ->once())
    ->method(__FUNCTION__)
    ->will($this
    ->returnValue($callback_label));
  $this->entityType
    ->expects($this
    ->once())
    ->method('get')
    ->with('label_callback')
    ->will($this
    ->returnValue([
    $callback_container,
    __FUNCTION__,
  ]));
  $this
    ->assertSame($callback_label, $this->entity
    ->label());
}