Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Tests\comment\Unit;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\comment\CommentManager;
|
Chris@18
|
6 use Drupal\Core\Entity\EntityFieldManagerInterface;
|
Chris@18
|
7 use Drupal\Core\Entity\EntityTypeManagerInterface;
|
Chris@0
|
8 use Drupal\Core\Entity\FieldableEntityInterface;
|
Chris@18
|
9 use Drupal\Core\Session\AccountInterface;
|
Chris@0
|
10 use Drupal\Tests\UnitTestCase;
|
Chris@0
|
11
|
Chris@0
|
12 /**
|
Chris@0
|
13 * @coversDefaultClass \Drupal\comment\CommentManager
|
Chris@0
|
14 * @group comment
|
Chris@0
|
15 */
|
Chris@0
|
16 class CommentManagerTest extends UnitTestCase {
|
Chris@0
|
17
|
Chris@0
|
18 /**
|
Chris@0
|
19 * Tests the getFields method.
|
Chris@0
|
20 *
|
Chris@0
|
21 * @covers ::getFields
|
Chris@0
|
22 */
|
Chris@0
|
23 public function testGetFields() {
|
Chris@0
|
24 // Set up a content entity type.
|
Chris@0
|
25 $entity_type = $this->getMock('Drupal\Core\Entity\ContentEntityTypeInterface');
|
Chris@0
|
26 $entity_type->expects($this->any())
|
Chris@0
|
27 ->method('getClass')
|
Chris@0
|
28 ->will($this->returnValue('Node'));
|
Chris@0
|
29 $entity_type->expects($this->any())
|
Chris@0
|
30 ->method('entityClassImplements')
|
Chris@0
|
31 ->with(FieldableEntityInterface::class)
|
Chris@0
|
32 ->will($this->returnValue(TRUE));
|
Chris@0
|
33
|
Chris@18
|
34 $entity_field_manager = $this->createMock(EntityFieldManagerInterface::class);
|
Chris@18
|
35 $entity_type_manager = $this->createMock(EntityTypeManagerInterface::class);
|
Chris@0
|
36
|
Chris@18
|
37 $entity_field_manager->expects($this->once())
|
Chris@0
|
38 ->method('getFieldMapByFieldType')
|
Chris@0
|
39 ->will($this->returnValue([
|
Chris@0
|
40 'node' => [
|
Chris@0
|
41 'field_foobar' => [
|
Chris@0
|
42 'type' => 'comment',
|
Chris@0
|
43 ],
|
Chris@0
|
44 ],
|
Chris@0
|
45 ]));
|
Chris@0
|
46
|
Chris@18
|
47 $entity_type_manager->expects($this->any())
|
Chris@0
|
48 ->method('getDefinition')
|
Chris@0
|
49 ->will($this->returnValue($entity_type));
|
Chris@0
|
50
|
Chris@0
|
51 $comment_manager = new CommentManager(
|
Chris@18
|
52 $entity_type_manager,
|
Chris@0
|
53 $this->getMock('Drupal\Core\Config\ConfigFactoryInterface'),
|
Chris@0
|
54 $this->getMock('Drupal\Core\StringTranslation\TranslationInterface'),
|
Chris@0
|
55 $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface'),
|
Chris@18
|
56 $this->createMock(AccountInterface::class),
|
Chris@18
|
57 $entity_field_manager
|
Chris@0
|
58 );
|
Chris@0
|
59 $comment_fields = $comment_manager->getFields('node');
|
Chris@0
|
60 $this->assertArrayHasKey('field_foobar', $comment_fields);
|
Chris@0
|
61 }
|
Chris@0
|
62
|
Chris@0
|
63 }
|