Issue #2565031 by penyaskito: Expose $entity in ConfigEntityMapper

8.0.x
Alex Pott 2015-09-26 13:57:45 +02:00
parent 3473bd5d3a
commit 068f6ad739
2 changed files with 18 additions and 2 deletions

View File

@ -117,6 +117,16 @@ class ConfigEntityMapper extends ConfigNamesMapper {
}
/**
* Gets the entity instance for this mapper.
*
* @return \Drupal\Core\Config\Entity\ConfigEntityInterface $entity
* The configuration entity.
*/
public function getEntity() {
return $this->entity;
}
/**
* Sets the entity instance for this mapper.
*
* This method can only be invoked when the concrete entity is known, that is

View File

@ -99,9 +99,9 @@ class ConfigEntityMapperTest extends UnitTestCase {
}
/**
* Tests ConfigEntityMapper::setEntity().
* Tests ConfigEntityMapper::setEntity() and ConfigEntityMapper::getEntity().
*/
public function testSetEntity() {
public function testEntityGetterAndSetter() {
$this->entity
->expects($this->once())
->method('id')
@ -119,9 +119,15 @@ class ConfigEntityMapperTest extends UnitTestCase {
->with('configurable_language')
->will($this->returnValue($entity_type));
// No entity is set.
$this->assertNull($this->configEntityMapper->getEntity());
$result = $this->configEntityMapper->setEntity($this->entity);
$this->assertTrue($result);
// Ensure that the getter provides the entity.
$this->assertEquals($this->entity, $this->configEntityMapper->getEntity());
// Ensure that the configuration name was added to the mapper.
$plugin_definition = $this->configEntityMapper->getPluginDefinition();
$this->assertTrue(in_array('config_prefix.entity_id', $plugin_definition['names']));