3 namespace Drupal\Tests\editor\Unit;
5 use Drupal\Core\DependencyInjection\ContainerBuilder;
6 use Drupal\editor\Entity\Editor;
7 use Drupal\Tests\UnitTestCase;
10 * @coversDefaultClass \Drupal\editor\Entity\Editor
13 class EditorConfigEntityUnitTest extends UnitTestCase {
16 * The entity type used for testing.
18 * @var \Drupal\Core\Entity\EntityTypeInterface|\PHPUnit_Framework_MockObject_MockObject
20 protected $entityType;
23 * The entity manager used for testing.
25 * @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
27 protected $entityManager;
30 * The ID of the type of the entity under test.
34 protected $entityTypeId;
37 * The UUID generator used for testing.
39 * @var \Drupal\Component\Uuid\UuidInterface|\PHPUnit_Framework_MockObject_MockObject
44 * The editor plugin manager used for testing.
46 * @var \Drupal\editor\Plugin\EditorManager|\PHPUnit_Framework_MockObject_MockObject
48 protected $editorPluginManager;
60 protected function setUp() {
61 $this->editorId = $this->randomMachineName();
62 $this->entityTypeId = $this->randomMachineName();
64 $this->entityType = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface');
65 $this->entityType->expects($this->any())
66 ->method('getProvider')
67 ->will($this->returnValue('editor'));
69 $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
70 $this->entityManager->expects($this->any())
71 ->method('getDefinition')
72 ->with($this->entityTypeId)
73 ->will($this->returnValue($this->entityType));
75 $this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface');
77 $this->editorPluginManager = $this->getMockBuilder('Drupal\editor\Plugin\EditorManager')
78 ->disableOriginalConstructor()
81 $container = new ContainerBuilder();
82 $container->set('entity.manager', $this->entityManager);
83 $container->set('uuid', $this->uuid);
84 $container->set('plugin.manager.editor', $this->editorPluginManager);
85 \Drupal::setContainer($container);
89 * @covers ::calculateDependencies
91 public function testCalculateDependencies() {
92 $format_id = 'filter.format.test';
93 $values = ['editor' => $this->editorId, 'format' => $format_id];
95 $plugin = $this->getMockBuilder('Drupal\editor\Plugin\EditorPluginInterface')
96 ->disableOriginalConstructor()
98 $plugin->expects($this->once())
99 ->method('getPluginDefinition')
100 ->will($this->returnValue(['provider' => 'test_module']));
101 $plugin->expects($this->once())
102 ->method('getDefaultSettings')
103 ->will($this->returnValue([]));
105 $this->editorPluginManager->expects($this->any())
106 ->method('createInstance')
107 ->with($this->editorId)
108 ->will($this->returnValue($plugin));
110 $entity = new Editor($values, $this->entityTypeId);
112 $filter_format = $this->getMock('Drupal\Core\Config\Entity\ConfigEntityInterface');
113 $filter_format->expects($this->once())
114 ->method('getConfigDependencyName')
115 ->will($this->returnValue('filter.format.test'));
117 $storage = $this->getMock('Drupal\Core\Entity\EntityStorageInterface');
118 $storage->expects($this->once())
121 ->will($this->returnValue($filter_format));
123 $this->entityManager->expects($this->once())
124 ->method('getStorage')
125 ->with('filter_format')
126 ->will($this->returnValue($storage));
128 $dependencies = $entity->calculateDependencies()->getDependencies();
129 $this->assertContains('test_module', $dependencies['module']);
130 $this->assertContains('filter.format.test', $dependencies['config']);