3 namespace Drupal\Tests\comment\Unit;
5 use Drupal\comment\CommentManager;
6 use Drupal\Core\Entity\FieldableEntityInterface;
7 use Drupal\Tests\UnitTestCase;
10 * @coversDefaultClass \Drupal\comment\CommentManager
13 class CommentManagerTest extends UnitTestCase {
16 * Tests the getFields method.
20 public function testGetFields() {
21 // Set up a content entity type.
22 $entity_type = $this->getMock('Drupal\Core\Entity\ContentEntityTypeInterface');
23 $entity_type->expects($this->any())
25 ->will($this->returnValue('Node'));
26 $entity_type->expects($this->any())
27 ->method('entityClassImplements')
28 ->with(FieldableEntityInterface::class)
29 ->will($this->returnValue(TRUE));
31 $entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
33 $entity_manager->expects($this->once())
34 ->method('getFieldMapByFieldType')
35 ->will($this->returnValue([
43 $entity_manager->expects($this->any())
44 ->method('getDefinition')
45 ->will($this->returnValue($entity_type));
47 $comment_manager = new CommentManager(
49 $this->getMock('Drupal\Core\Config\ConfigFactoryInterface'),
50 $this->getMock('Drupal\Core\StringTranslation\TranslationInterface'),
51 $this->getMock('Drupal\Core\Routing\UrlGeneratorInterface'),
52 $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface'),
53 $this->getMock('Drupal\Core\Session\AccountInterface')
55 $comment_fields = $comment_manager->getFields('node');
56 $this->assertArrayHasKey('field_foobar', $comment_fields);