Version 1
[yaffs-website] / web / core / tests / Drupal / Tests / Core / Entity / EntityManagerTest.php
1 <?php
2
3 namespace Drupal\Tests\Core\Entity;
4
5 use Drupal\Core\DependencyInjection\ContainerBuilder;
6 use Drupal\Core\Entity\EntityFieldManagerInterface;
7 use Drupal\Core\Entity\EntityManager;
8 use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
9 use Drupal\Core\Entity\EntityTypeManagerInterface;
10 use Drupal\Core\Entity\EntityTypeRepositoryInterface;
11 use Drupal\Tests\UnitTestCase;
12
13 /**
14  * @coversDefaultClass \Drupal\Core\Entity\EntityManager
15  * @group Entity
16  */
17 class EntityManagerTest extends UnitTestCase {
18
19   /**
20    * The entity manager.
21    *
22    * @var \Drupal\Core\Entity\EntityManager
23    */
24   protected $entityManager;
25
26   /**
27    * The entity type manager.
28    *
29    * @var \Drupal\Core\Entity\EntityTypeManagerInterface|\Prophecy\Prophecy\ProphecyInterface
30    */
31   protected $entityTypeManager;
32
33   /**
34    * The entity type repository.
35    *
36    * @var \Drupal\Core\Entity\EntityTypeRepositoryInterface|\Prophecy\Prophecy\ProphecyInterface
37    */
38   protected $entityTypeRepository;
39
40   /**
41    * The entity type bundle info.
42    *
43    * @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface|\Prophecy\Prophecy\ProphecyInterface
44    */
45   protected $entityTypeBundleInfo;
46
47   /**
48    * The entity field manager.
49    *
50    * @var \Drupal\Core\Entity\EntityFieldManagerInterface|\Prophecy\Prophecy\ProphecyInterface
51    */
52   protected $entityFieldManager;
53
54   /**
55    * {@inheritdoc}
56    */
57   protected function setUp() {
58     parent::setUp();
59
60     $this->entityTypeManager = $this->prophesize(EntityTypeManagerInterface::class);
61     $this->entityTypeRepository = $this->prophesize(EntityTypeRepositoryInterface::class);
62     $this->entityTypeBundleInfo = $this->prophesize(EntityTypeBundleInfoInterface::class);
63     $this->entityFieldManager = $this->prophesize(EntityFieldManagerInterface::class);
64
65     $container = new ContainerBuilder();
66     $container->set('entity_type.manager', $this->entityTypeManager->reveal());
67     $container->set('entity_type.repository', $this->entityTypeRepository->reveal());
68     $container->set('entity_type.bundle.info', $this->entityTypeBundleInfo->reveal());
69     $container->set('entity_field.manager', $this->entityFieldManager->reveal());
70
71     $this->entityManager = new EntityManager();
72     $this->entityManager->setContainer($container);
73   }
74
75   /**
76    * Tests the clearCachedDefinitions() method.
77    *
78    * @covers ::clearCachedDefinitions
79    */
80   public function testClearCachedDefinitions() {
81     $this->entityTypeManager->clearCachedDefinitions()->shouldBeCalled();
82     $this->entityTypeRepository->clearCachedDefinitions()->shouldBeCalled();
83     $this->entityTypeBundleInfo->clearCachedBundles()->shouldBeCalled();
84     $this->entityFieldManager->clearCachedFieldDefinitions()->shouldBeCalled();
85
86     $this->entityManager->clearCachedDefinitions();
87   }
88
89 }