public function EntityUnitTest::testLabel in Zircon Profile 8
Same name and namespace in other branches
- 8.0 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 173 - Contains \Drupal\Tests\Core\Entity\EntityUnitTest.
Class
- EntityUnitTest
- @coversDefaultClass \Drupal\Core\Entity\Entity @group Entity @group Access
Namespace
Drupal\Tests\Core\EntityCode
public function testLabel() {
// Make a mock with one method that we use as the entity's uri_callback. We
// check that it is called, and that the entity's label is the callback's
// return value.
$callback_label = $this
->randomMachineName();
$property_label = $this
->randomMachineName();
$callback_container = $this
->getMock(get_class());
$callback_container
->expects($this
->once())
->method(__FUNCTION__)
->will($this
->returnValue($callback_label));
$this->entityType
->expects($this
->at(0))
->method('getLabelCallback')
->will($this
->returnValue(array(
$callback_container,
__FUNCTION__,
)));
$this->entityType
->expects($this
->at(1))
->method('getLabelCallback')
->will($this
->returnValue(NULL));
$this->entityType
->expects($this
->at(2))
->method('getKey')
->with('label')
->will($this
->returnValue('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->entityManager
->expects($this
->at(1))
->method('getDefinition')
->with($this->entityTypeId)
->will($this
->returnValue(array(
'entity_keys' => array(
'label' => 'label',
),
)));
$this->entity->label = $property_label;
$this
->assertSame($callback_label, $this->entity
->label());
$this
->assertSame($property_label, $this->entity
->label());
}