Commit 3827a481 authored by alexpott's avatar alexpott

Issue #2030613 by balagan, Mile23, scottrigby, alexpott: Expand EntityViewMode...

Issue #2030613 by balagan, Mile23, scottrigby, alexpott: Expand EntityViewMode (really EntityDisplayModeBase) with methods
parent f5d180e1
......@@ -11,7 +11,7 @@
use Drupal\Core\Config\Entity\ConfigEntityInterface;
/**
* Base class for config entity types that hold settings for form and view modes.
* Base class for config entity types with settings for form and view modes.
*/
abstract class EntityDisplayModeBase extends ConfigEntityBase implements EntityDisplayModeInterface {
......@@ -20,14 +20,14 @@ abstract class EntityDisplayModeBase extends ConfigEntityBase implements EntityD
*
* @var string
*/
public $id;
protected $id;
/**
* The human-readable name of the form or view mode.
*
* @var string
*/
public $label;
protected $label;
/**
* The entity type this form or view mode is used for.
......@@ -37,7 +37,7 @@ abstract class EntityDisplayModeBase extends ConfigEntityBase implements EntityD
*
* @var string
*/
public $targetEntityType;
protected $targetEntityType;
/**
* Whether or not this form or view mode has custom settings by default.
......@@ -56,7 +56,7 @@ abstract class EntityDisplayModeBase extends ConfigEntityBase implements EntityD
*
* @var bool
*/
public $cache = TRUE;
protected $cache = TRUE;
/**
* {@inheritdoc}
......@@ -78,6 +78,14 @@ public function getTargetType() {
return $this->targetEntityType;
}
/**
* {@inheritdoc}
*/
public function setTargetType($target_entity_type) {
$this->targetEntityType = $target_entity_type;
return $this;
}
/**
* {@inheritdoc}
*/
......
......@@ -22,4 +22,14 @@ interface EntityDisplayModeInterface extends ConfigEntityInterface {
*/
public function getTargetType();
/**
* Set the entity type this display mode is used for.
*
* @param string $target_entity_type
* The target entity type for this display mode.
*
* @return Drupal\Core\Entity\EntityDisplayModeInterface
* The display mode object, for fluent interface.
*/
public function setTargetType($target_entity_type);
}
......@@ -53,7 +53,7 @@ protected function prepareEntity() {
throw new NotFoundHttpException();
}
$this->entity->targetEntityType = $this->targetEntityTypeId;
$this->entity->setTargetType($this->targetEntityTypeId);
}
}
......@@ -23,7 +23,7 @@ protected function prepareEntity() {
throw new NotFoundHttpException();
}
$this->entity->targetEntityType = $this->targetEntityTypeId;
$this->entity->setTargetType($this->targetEntityTypeId);
}
}
......@@ -70,7 +70,6 @@ protected function setUp() {
$container->set('entity.manager', $this->entityManager);
$container->set('uuid', $this->uuid);
\Drupal::setContainer($container);
}
/**
......@@ -101,7 +100,62 @@ public function testCalculateDependencies() {
$dependencies = $this->entity->calculateDependencies();
$this->assertContains('test_module', $dependencies['module']);
}
/**
* @covers ::setTargetType
*/
public function testSetTargetType() {
// Generate mock.
$mock = $this->getMock(
'Drupal\Core\Entity\EntityDisplayModeBase',
NULL,
array(array('something' => 'nothing'), 'test_type')
);
// Some test values.
$bad_target = 'uninitialized';
$target = 'test_target_type';
// Gain access to the protected property.
$property = new \ReflectionProperty($mock, 'targetEntityType');
$property->setAccessible(TRUE);
// Set the property to a known state.
$property->setValue($mock, $bad_target);
// Set the target type.
$mock->setTargetType($target);
// Test the outcome.
$this->assertNotEquals($bad_target, $property->getValue($mock));
$this->assertEquals($target, $property->getValue($mock));
}
/**
* @covers ::getTargetType
*/
public function testGetTargetType() {
// Generate mock.
$mock = $this->getMock(
'Drupal\Core\Entity\EntityDisplayModeBase',
NULL,
array(array('something' => 'nothing'), 'test_type')
);
// A test value.
$target = 'test_target_type';
// Gain access to the protected property.
$property = new \ReflectionProperty($mock, 'targetEntityType');
$property->setAccessible(TRUE);
// Set the property to a known state.
$property->setValue($mock, $target);
// Get the target type.
$value = $mock->getTargetType($target);
// Test the outcome.
$this->assertEquals($value, $property->getValue($mock));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment