function EntityUnitTest::testLabel

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php \Drupal\Tests\Core\Entity\EntityUnitTest::testLabel()
  2. 8.9.x core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php \Drupal\Tests\Core\Entity\EntityUnitTest::testLabel()
  3. 11.x core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php \Drupal\Tests\Core\Entity\EntityUnitTest::testLabel()

@covers ::label

File

core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php, line 176

Class

EntityUnitTest
@coversDefaultClass \Drupal\Core\Entity\EntityBase[[api-linebreak]] @group Entity @group Access

Namespace

Drupal\Tests\Core\Entity

Code

public function testLabel() : void {
  $property_label = $this->randomMachineName();
  $this->entityType
    ->expects($this->atLeastOnce())
    ->method('getKey')
    ->with('label')
    ->willReturn('label');
  // 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->entityTypeManager
    ->expects($this->atLeastOnce())
    ->method('getDefinition')
    ->with($this->entityTypeId)
    ->willReturn([
    'entity_keys' => [
      'label' => 'label',
    ],
  ]);
  $this->entity->label = $property_label;
  $this->assertSame($property_label, $this->entity
    ->label());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.