Commit 3a8cb0d5 authored by alexpott's avatar alexpott

Issue #2583135 by Torenware, klausi: Context::getContextData() sometimes...

Issue #2583135 by Torenware, klausi: Context::getContextData() sometimes returns NULL which violates ContextInterface
parent 5d450cb8
......@@ -121,11 +121,9 @@ public function getContextData() {
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 @@ public function setUp() {
* @covers ::getContextValue
*/
public function testDefaultValue() {
$this->setUpDefaultValue();
$this->setUpDefaultValue('test');
$context = new Context($this->contextDefinition);
$context->setTypedDataManager($this->typedDataManager);
......@@ -67,7 +67,18 @@ public function testDefaultValue() {
* @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 @@ public function testSetContextValueCacheableDependency() {
/**
* 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 @@ protected function setUpDefaultValue() {
$this->contextDefinition->expects($this->once())
->method('getDefaultValue')
->willReturn('test');
->willReturn($default_value);
$this->contextDefinition->expects($this->once())
->method('getDataDefinition')
......@@ -147,7 +161,7 @@ protected function setUpDefaultValue() {
$this->typedDataManager->expects($this->once())
->method('create')
->with($mock_data_definition, 'test')
->with($mock_data_definition, $default_value)
->willReturn($this->typedData);
}
}
......
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