Issue #2583135 by Torenware, klausi: Context::getContextData() sometimes returns NULL which violates ContextInterface
parent
5d450cb8c4
commit
3a8cb0d5f6
|
@ -121,11 +121,9 @@ class Context extends ComponentContext implements ContextInterface {
|
|||
if (!isset($this->contextData)) {
|
||||
$definition = $this->getContextDefinition();
|
||||
$default_value = $definition->getDefaultValue();
|
||||
if (isset($default_value)) {
|
||||
// Store the default value so that subsequent calls don't have to look
|
||||
// it up again.
|
||||
$this->contextData = $this->getTypedDataManager()->create($definition->getDataDefinition(), $default_value);
|
||||
}
|
||||
// Store the default value so that subsequent calls don't have to look
|
||||
// it up again.
|
||||
$this->contextData = $this->getTypedDataManager()->create($definition->getDataDefinition(), $default_value);
|
||||
}
|
||||
return $this->contextData;
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ class ContextTest extends UnitTestCase {
|
|||
* @covers ::getContextValue
|
||||
*/
|
||||
public function testDefaultValue() {
|
||||
$this->setUpDefaultValue();
|
||||
$this->setUpDefaultValue('test');
|
||||
|
||||
$context = new Context($this->contextDefinition);
|
||||
$context->setTypedDataManager($this->typedDataManager);
|
||||
|
@ -67,7 +67,18 @@ class ContextTest extends UnitTestCase {
|
|||
* @covers ::getContextData
|
||||
*/
|
||||
public function testDefaultDataValue() {
|
||||
$this->setUpDefaultValue();
|
||||
$this->setUpDefaultValue('test');
|
||||
|
||||
$context = new Context($this->contextDefinition);
|
||||
$context->setTypedDataManager($this->typedDataManager);
|
||||
$this->assertEquals($this->typedData, $context->getContextData());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getContextData
|
||||
*/
|
||||
public function testNullDataValue() {
|
||||
$this->setUpDefaultValue(NULL);
|
||||
|
||||
$context = new Context($this->contextDefinition);
|
||||
$context->setTypedDataManager($this->typedDataManager);
|
||||
|
@ -127,8 +138,11 @@ class ContextTest extends UnitTestCase {
|
|||
|
||||
/**
|
||||
* Set up mocks for the getDefaultValue() method call.
|
||||
*
|
||||
* @param mixed $default_value
|
||||
* The default value to assign to the mock context definition.
|
||||
*/
|
||||
protected function setUpDefaultValue() {
|
||||
protected function setUpDefaultValue($default_value = NULL) {
|
||||
$mock_data_definition = $this->getMock('Drupal\Core\TypedData\DataDefinitionInterface');
|
||||
|
||||
$this->contextDefinition = $this->getMockBuilder('Drupal\Core\Plugin\Context\ContextDefinitionInterface')
|
||||
|
@ -137,7 +151,7 @@ class ContextTest extends UnitTestCase {
|
|||
|
||||
$this->contextDefinition->expects($this->once())
|
||||
->method('getDefaultValue')
|
||||
->willReturn('test');
|
||||
->willReturn($default_value);
|
||||
|
||||
$this->contextDefinition->expects($this->once())
|
||||
->method('getDataDefinition')
|
||||
|
@ -147,7 +161,7 @@ class ContextTest extends UnitTestCase {
|
|||
|
||||
$this->typedDataManager->expects($this->once())
|
||||
->method('create')
|
||||
->with($mock_data_definition, 'test')
|
||||
->with($mock_data_definition, $default_value)
|
||||
->willReturn($this->typedData);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue