diff --git a/core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php b/core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php index 5100074..43f5ebf 100644 --- a/core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php +++ b/core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php @@ -191,7 +191,8 @@ protected function getDerivativeFetcher($base_plugin_id, $base_definition) { */ protected function getDerivativeClass($base_definition) { $class = NULL; - // @todo: Support derivatives for plugin definitions as classes? + // @todo: Support derivatives for plugin definitions as classes in + // https://drupal.org/node/2168159. if (is_array($base_definition) && isset($base_definition['derivative'])) { $class = $base_definition['derivative']; if (!is_subclass_of($class, '\Drupal\Component\Plugin\Derivative\DerivativeInterface')) { diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index 01b080e..da1dc51 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -17,6 +17,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Language\LanguageManager; use Drupal\Core\Language\Language; +use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\Plugin\DefaultPluginManager; use Drupal\Core\Plugin\Discovery\InfoHookDecorator; use Drupal\Core\StringTranslation\TranslationInterface; @@ -95,12 +96,12 @@ class EntityManager extends DefaultPluginManager implements EntityManagerInterfa * The module handler. * @param \Drupal\Core\Cache\CacheBackendInterface $cache * The cache backend to use. - * @param \Drupal\Core\Language\LanguageManager $language_manager + * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The language manager. * @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager * The string translationManager. */ - public function __construct(\Traversable $namespaces, ContainerInterface $container, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache, LanguageManager $language_manager, TranslationInterface $translation_manager) { + public function __construct(\Traversable $namespaces, ContainerInterface $container, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache, LanguageManagerInterface $language_manager, TranslationInterface $translation_manager) { parent::__construct('Entity', $namespaces, 'Drupal\Core\Entity\Annotation\EntityType'); $this->setCacheBackend($cache, $language_manager, 'entity_type:', array('entity_types' => TRUE)); diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php index 60622f0..5dc1e07 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php @@ -111,12 +111,13 @@ protected function setUp() { $this->cache = $this->getMock('Drupal\Core\Cache\CacheBackendInterface'); - $this->languageManager = $this->getMockBuilder('Drupal\Core\Language\LanguageManager') - ->disableOriginalConstructor() - ->getMock(); + $this->languageManager = $this->getMock('Drupal\Core\Language\LanguageManagerInterface'); $this->languageManager->expects($this->any()) ->method('getCurrentLanguage') ->will($this->returnValue((object) array('id' => 'en'))); + $this->languageManager->expects($this->any()) + ->method('getLanguages') + ->will($this->returnValue(array('en' => (object) array('id' => 'en')))); $this->translationManager = $this->getStringTranslationStub(); @@ -124,7 +125,7 @@ protected function setUp() { $this->container = $this->getContainerWithCacheBins($this->cache); - $this->discovery = $this->getMock('Drupal\Component\Plugin\Discovery\CachedDiscoveryInterface'); + $this->discovery = $this->getMock('Drupal\Component\Plugin\Discovery\DiscoveryInterface'); } /** @@ -161,8 +162,9 @@ protected function setUpEntityManager($definitions = array()) { */ public function testClearCachedDefinitions() { $this->setUpEntityManager(); - $this->discovery->expects($this->once()) - ->method('clearCachedDefinitions'); + $this->cache->expects($this->once()) + ->method('deleteTags') + ->with(array('entity_types' => TRUE)); $this->entityManager->clearCachedDefinitions(); } @@ -474,21 +476,19 @@ public function testGetFieldDefinitionsWithCaching() { $expected = array('id' => $field_definition); - // @todo Investigate why this is 0 and 2, not 0/1 or 1/2. - $this->cache->expects($this->at(0)) + $get_method = $this->cache->expects($this->any()) ->method('get') - ->with('entity_field_definitions:test_entity_type:en', FALSE) ->will($this->returnValue(FALSE)); - $this->cache->expects($this->at(2)) - ->method('get') - ->with('entity_field_definitions:test_entity_type:en', FALSE) - ->will($this->returnValue((object) array('data' => array('definitions' => $expected)))); - $this->cache->expects($this->once()) + $this->cache->expects($this->exactly(2)) ->method('set'); $this->assertSame($expected, $this->entityManager->getFieldDefinitions('test_entity_type')); $this->entityManager->testClearEntityFieldInfo(); + + $get_method + ->will($this->returnValue((object) array('data' => array('definitions' => $expected)))); + $this->assertSame($expected, $this->entityManager->getFieldDefinitions('test_entity_type')); } @@ -500,12 +500,11 @@ public function testGetFieldDefinitionsWithCaching() { public function testGetFieldDefinitionsWithBundleMap() { $field_definition = $this->setUpEntityWithFieldDefinition(TRUE); - $this->moduleHandler->expects($this->at(0)) + $this->moduleHandler->expects($this->exactly(2)) ->method('invokeAll') - ->will($this->returnValue(array())); - $this->moduleHandler->expects($this->at(1)) - ->method('invokeAll') - ->will($this->returnValue(array( + ->will($this->returnValueMap(array( + array('test_entity_type_field_info', array(), array()), + array('entity_field_info', array('test_entity_type'), array( 'bundle map' => array( 'test_entity_bundle' => array( 'custom_field', @@ -514,7 +513,7 @@ public function testGetFieldDefinitionsWithBundleMap() { 'optional' => array( 'custom_field' => $field_definition, ), - ))); + ))))); $expected = array('id' => $field_definition); $this->assertSame($expected, $this->entityManager->getFieldDefinitions('test_entity_type')); @@ -589,7 +588,7 @@ protected function setUpEntityWithFieldDefinition($custom_invoke_all = FALSE, $f $field_definition_id => $field_definition, ))); - $this->moduleHandler->expects($this->once()) + $this->moduleHandler->expects($this->exactly(2)) ->method('alter'); if (!$custom_invoke_all) { $this->moduleHandler->expects($this->exactly(2)) @@ -681,13 +680,11 @@ public function testGetAllBundleInfo() { 'apple' => $apple, 'banana' => $banana, )); - $this->cache->expects($this->at(1)) + $get_method = $this->cache->expects($this->any()) ->method('get') ->will($this->returnValue(FALSE)); - $this->cache->expects($this->at(2)) - ->method('get') - ->will($this->returnValue((object) array('data' => 'cached data'))); - $this->cache->expects($this->once()) + + $this->cache->expects($this->exactly(2)) ->method('set'); $expected = array( @@ -710,6 +707,12 @@ public function testGetAllBundleInfo() { $this->entityManager->clearCachedDefinitions(); + $get_method + ->will($this->returnValueMap(array( + array('entity_types:en', FALSE, FALSE), + array('entity_bundle_info:en', FALSE, (object) array('data' => 'cached data')), + ))); + $bundle_info = $this->entityManager->getAllBundleInfo(); $this->assertSame('cached data', $bundle_info); }