diff --git a/core/lib/Drupal/Core/Plugin/Context/Context.php b/core/lib/Drupal/Core/Plugin/Context/Context.php index 599f73e..18204a7 100644 --- a/core/lib/Drupal/Core/Plugin/Context/Context.php +++ b/core/lib/Drupal/Core/Plugin/Context/Context.php @@ -8,9 +8,6 @@ namespace Drupal\Core\Plugin\Context; use Drupal\Component\Plugin\Context\Context as ComponentContext; -use Drupal\Component\Plugin\Context\ContextDefinitionInterface; -use Drupal\Component\Plugin\Exception\ContextException; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\TypedData\TypedDataInterface; diff --git a/core/tests/Drupal/Tests/Component/Plugin/Context/ContextTest.php b/core/tests/Drupal/Tests/Component/Plugin/Context/ContextTest.php index c453b6b..ebfcb81 100644 --- a/core/tests/Drupal/Tests/Component/Plugin/Context/ContextTest.php +++ b/core/tests/Drupal/Tests/Component/Plugin/Context/ContextTest.php @@ -23,7 +23,7 @@ public function providerGetContextValue() { return [ ['context_value', 'context_value', FALSE, 'data_type'], [NULL, NULL, FALSE, 'data_type'], - ['will throw exception', NULL, TRUE, 'data_type'], + [NULL, NULL, TRUE, 'data_type'], ]; } @@ -62,26 +62,11 @@ public function testGetContextValue($expected, $context_value, $is_required, $da ->method('isRequired') ->willReturn($is_required); - // Set expectation for getDataType(). - $mock_definition->expects($this->exactly( - $is_required ? 1 : 0 - )) - ->method('getDataType') - ->willReturn($data_type); - // Set expectation for getContextDefinition(). $mock_context->expects($this->once()) ->method('getContextDefinition') ->willReturn($mock_definition); - // Set expectation for exception. - if ($is_required) { - $this->setExpectedException( - 'Drupal\Component\Plugin\Exception\ContextException', - sprintf("The %s context is required and not present.", $data_type) - ); - } - // Exercise getContextValue(). $this->assertEquals($context_value, $mock_context->getContextValue()); } diff --git a/core/tests/Drupal/Tests/Core/Plugin/Context/ContextTest.php b/core/tests/Drupal/Tests/Core/Plugin/Context/ContextTest.php index 6c00c7f..a7a3f75 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/Context/ContextTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/Context/ContextTest.php @@ -122,9 +122,9 @@ public function testSetContextValueCacheableDependency() { $context->setContextValue($cacheable_dependency); $this->assertSame($cacheable_dependency, $context->getContextData()); - $this->assertEquals(['node:1'], $context->getCacheableMetadata()->getCacheTags()); - $this->assertEquals(['route'], $context->getCacheableMetadata()->getCacheContexts()); - $this->assertEquals(60, $context->getCacheableMetadata()->getCacheMaxAge()); + $this->assertEquals(['node:1'], $context->getCacheTags()); + $this->assertEquals(['route'], $context->getCacheContexts()); + $this->assertEquals(60, $context->getCacheMaxAge()); } /** diff --git a/core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php b/core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php index 5427dd6..abd80f3 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php @@ -242,13 +242,15 @@ public function testApplyContextMapping() { 'miss' => $context_miss, ); + $context_definition = $this->getMock('Drupal\Core\Plugin\Context\ContextDefinitionInterface'); + $plugin = $this->getMock('Drupal\Core\Plugin\ContextAwarePluginInterface'); $plugin->expects($this->once()) ->method('getContextMapping') ->willReturn([]); $plugin->expects($this->once()) ->method('getContextDefinitions') - ->will($this->returnValue(array('hit' => 'hit'))); + ->will($this->returnValue(array('hit' => $context_definition))); $plugin->expects($this->once()) ->method('setContextValue') ->with('hit', array('foo')); @@ -268,13 +270,15 @@ public function testApplyContextMappingConfigurable() { 'name' => $context, ); + $context_definition = $this->getMock('Drupal\Core\Plugin\Context\ContextDefinitionInterface'); + $plugin = $this->getMock('Drupal\Tests\Core\Plugin\TestConfigurableContextAwarePluginInterface'); $plugin->expects($this->once()) ->method('getContextMapping') ->willReturn([]); $plugin->expects($this->once()) ->method('getContextDefinitions') - ->will($this->returnValue(array('hit' => 'hit'))); + ->will($this->returnValue(array('hit' => $context_definition))); $plugin->expects($this->never()) ->method('setContextValue'); @@ -294,13 +298,15 @@ public function testApplyContextMappingConfigurableAssigned() { 'name' => $context, ); + $context_definition = $this->getMock('Drupal\Core\Plugin\Context\ContextDefinitionInterface'); + $plugin = $this->getMock('Drupal\Tests\Core\Plugin\TestConfigurableContextAwarePluginInterface'); $plugin->expects($this->once()) ->method('getContextMapping') ->willReturn([]); $plugin->expects($this->once()) ->method('getContextDefinitions') - ->will($this->returnValue(array('hit' => 'hit'))); + ->will($this->returnValue(array('hit' => $context_definition))); $plugin->expects($this->once()) ->method('setContextValue') ->with('hit', array('foo'));