diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index 725ccbf..7a54289 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -577,7 +577,7 @@ public function getFieldMap() { * {@inheritdoc} */ public function getFieldMapByFieldType($field_type) { - if (!array_key_exists($field_type, $this->fieldMapByFieldType)) { + if (!isset($this->fieldMapByFieldType[$field_type])) { $filtered_map = array(); $map = $this->getFieldMap(); foreach ($map as $entity_type => $fields) { diff --git a/core/modules/comment/tests/src/CommentManagerTest.php b/core/modules/comment/tests/src/CommentManagerTest.php index 77f874b..27c03a1 100644 --- a/core/modules/comment/tests/src/CommentManagerTest.php +++ b/core/modules/comment/tests/src/CommentManagerTest.php @@ -19,15 +19,22 @@ class CommentManagerTest extends UnitTestCase { /** * Tests the getFields method. * - * @see \Drupal\comment\CommentManager::getFields() - * - * @group Drupal - * @group Comment + * @covers ::getFields() */ public function testGetFields() { + // Set up a content entity type. + $entity_type = $this->getMock('Drupal\Core\Entity\ContentEntityTypeInterface'); + $entity_type->expects($this->any()) + ->method('getClass') + ->will($this->returnValue('Node')); + $entity_type->expects($this->any()) + ->method('isSubclassOf') + ->with('\Drupal\Core\Entity\ContentEntityInterface') + ->will($this->returnValue(TRUE)); + $entity_manager = $this->getMockBuilder('Drupal\Core\Entity\EntityManager') ->disableOriginalConstructor() - ->setMethods(array('getFieldMap')) + ->setMethods(array('getFieldMap', 'getDefinition')) ->getMock(); $entity_manager->expects($this->once()) @@ -42,6 +49,11 @@ public function testGetFields() { ), ), ))); + + $entity_manager->expects($this->any()) + ->method('getDefinition') + ->will($this->returnValue($entity_type)); + $comment_manager = new CommentManager( $entity_manager, $this->getMockBuilder('Drupal\Core\Entity\Query\QueryFactory')->disableOriginalConstructor()->getMock(), @@ -56,8 +68,8 @@ public function testGetFields() { // Should not trigger EntityManager::getFieldMap(). $cached_comment_fields = $comment_manager->getFields('node'); $this->assertSame($cached_comment_fields, $comment_fields); - $this->assertArrayHasKey('field_foobar', $comment_fields['node']); - $this->assertArrayNotHasKey('field_fuzzball', $comment_fields['node']); + $this->assertArrayHasKey('field_foobar', $comment_fields); + $this->assertArrayNotHasKey('field_fuzzball', $comment_fields); } }