class EditorConfigEntityUnitTest
Same name in other branches
- 9 core/modules/editor/tests/src/Unit/EditorConfigEntityUnitTest.php \Drupal\Tests\editor\Unit\EditorConfigEntityUnitTest
- 8.9.x core/modules/editor/tests/src/Unit/EditorConfigEntityUnitTest.php \Drupal\Tests\editor\Unit\EditorConfigEntityUnitTest
- 10 core/modules/editor/tests/src/Unit/EditorConfigEntityUnitTest.php \Drupal\Tests\editor\Unit\EditorConfigEntityUnitTest
@coversDefaultClass \Drupal\editor\Entity\Editor @group editor
Hierarchy
- class \Drupal\Tests\editor\Unit\EditorConfigEntityUnitTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of EditorConfigEntityUnitTest
File
-
core/
modules/ editor/ tests/ src/ Unit/ EditorConfigEntityUnitTest.php, line 16
Namespace
Drupal\Tests\editor\UnitView source
class EditorConfigEntityUnitTest extends UnitTestCase {
/**
* The entity type used for testing.
*
* @var \Drupal\Core\Entity\EntityTypeInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $entityType;
/**
* The entity type manager used for testing.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $entityTypeManager;
/**
* The ID of the type of the entity under test.
*
* @var string
*/
protected $entityTypeId;
/**
* The UUID generator used for testing.
*
* @var \Drupal\Component\Uuid\UuidInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $uuid;
/**
* The editor plugin manager used for testing.
*
* @var \Drupal\editor\Plugin\EditorManager|\PHPUnit\Framework\MockObject\MockObject
*/
protected $editorPluginManager;
/**
* Editor plugin ID.
*
* @var string
*/
protected $editorId;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->editorId = $this->randomMachineName();
$this->entityTypeId = $this->randomMachineName();
$this->entityType = $this->createMock('\\Drupal\\Core\\Entity\\EntityTypeInterface');
$this->entityType
->expects($this->any())
->method('getProvider')
->willReturn('editor');
$this->entityTypeManager = $this->createMock(EntityTypeManagerInterface::class);
$this->entityTypeManager
->expects($this->any())
->method('getDefinition')
->with($this->entityTypeId)
->willReturn($this->entityType);
$this->uuid = $this->createMock('\\Drupal\\Component\\Uuid\\UuidInterface');
$this->editorPluginManager = $this->getMockBuilder('Drupal\\editor\\Plugin\\EditorManager')
->disableOriginalConstructor()
->getMock();
$container = new ContainerBuilder();
$container->set('entity_type.manager', $this->entityTypeManager);
$container->set('uuid', $this->uuid);
$container->set('plugin.manager.editor', $this->editorPluginManager);
\Drupal::setContainer($container);
}
/**
* @covers ::calculateDependencies
*/
public function testCalculateDependencies() : void {
$format_id = 'filter.format.test';
$values = [
'editor' => $this->editorId,
'format' => $format_id,
];
$plugin = $this->getMockBuilder('Drupal\\editor\\Plugin\\EditorPluginInterface')
->disableOriginalConstructor()
->getMock();
$plugin->expects($this->once())
->method('getPluginDefinition')
->willReturn([
'provider' => 'test_module',
]);
$plugin->expects($this->once())
->method('getDefaultSettings')
->willReturn([]);
$this->editorPluginManager
->expects($this->any())
->method('createInstance')
->with($this->editorId)
->willReturn($plugin);
$entity = new Editor($values, $this->entityTypeId);
$filter_format = $this->createMock('Drupal\\Core\\Config\\Entity\\ConfigEntityInterface');
$filter_format->expects($this->once())
->method('getConfigDependencyName')
->willReturn('filter.format.test');
$storage = $this->createMock('Drupal\\Core\\Entity\\EntityStorageInterface');
$storage->expects($this->once())
->method('load')
->with($format_id)
->willReturn($filter_format);
$this->entityTypeManager
->expects($this->once())
->method('getStorage')
->with('filter_format')
->willReturn($storage);
$dependencies = $entity->calculateDependencies()
->getDependencies();
$this->assertContains('test_module', $dependencies['module']);
$this->assertContains('filter.format.test', $dependencies['config']);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
EditorConfigEntityUnitTest::$editorId | protected | property | Editor plugin ID. | |
EditorConfigEntityUnitTest::$editorPluginManager | protected | property | The editor plugin manager used for testing. | |
EditorConfigEntityUnitTest::$entityType | protected | property | The entity type used for testing. | |
EditorConfigEntityUnitTest::$entityTypeId | protected | property | The ID of the type of the entity under test. | |
EditorConfigEntityUnitTest::$entityTypeManager | protected | property | The entity type manager used for testing. | |
EditorConfigEntityUnitTest::$uuid | protected | property | The UUID generator used for testing. | |
EditorConfigEntityUnitTest::setUp | protected | function | Overrides UnitTestCase::setUp | |
EditorConfigEntityUnitTest::testCalculateDependencies | public | function | @covers ::calculateDependencies | |
ExpectDeprecationTrait::expectDeprecation | public | function | Adds an expected deprecation. | |
ExpectDeprecationTrait::getCallableName | private static | function | Returns a callable as a string suitable for inclusion in a message. | |
ExpectDeprecationTrait::setUpErrorHandler | public | function | Sets up the test error handler. | |
ExpectDeprecationTrait::tearDownErrorHandler | public | function | Tears down the test error handler. | |
RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |
RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | |
RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | |
RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |
UnitTestCase::$root | protected | property | The app root. | |
UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | |
UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase::getConfigStorageStub | public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase::setUpBeforeClass | public static | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.