class FieldStorageConfigEntityUnitTest in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/field/tests/src/Unit/FieldStorageConfigEntityUnitTest.php \Drupal\Tests\field\Unit\FieldStorageConfigEntityUnitTest
@coversDefaultClass \Drupal\field\Entity\FieldStorageConfig
@group field
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\field\Unit\FieldStorageConfigEntityUnitTest
Expanded class hierarchy of FieldStorageConfigEntityUnitTest
File
- core/
modules/ field/ tests/ src/ Unit/ FieldStorageConfigEntityUnitTest.php, line 21 - Contains \Drupal\Tests\field\Unit\FieldStorageConfigEntityUnitTest.
Namespace
Drupal\Tests\field\UnitView source
class FieldStorageConfigEntityUnitTest extends UnitTestCase {
/**
* The entity manager used for testing.
*
* @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $entityManager;
/**
* 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 field type manager.
*
* @var \Drupal\Core\Field\FieldTypePluginManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $fieldTypeManager;
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->entityManager = $this
->getMock('\\Drupal\\Core\\Entity\\EntityManagerInterface');
$this->uuid = $this
->getMock('\\Drupal\\Component\\Uuid\\UuidInterface');
$this->fieldTypeManager = $this
->getMock(FieldTypePluginManagerInterface::class);
$container = new ContainerBuilder();
$container
->set('entity.manager', $this->entityManager);
$container
->set('uuid', $this->uuid);
$container
->set('plugin.manager.field.field_type', $this->fieldTypeManager);
\Drupal::setContainer($container);
}
/**
* @covers ::calculateDependencies
*/
public function testCalculateDependencies() {
// Create a mock entity type for FieldStorageConfig.
$fieldStorageConfigentityType = $this
->getMock('\\Drupal\\Core\\Config\\Entity\\ConfigEntityTypeInterface');
$fieldStorageConfigentityType
->expects($this
->any())
->method('getProvider')
->will($this
->returnValue('field'));
// Create a mock entity type to attach the field to.
$attached_entity_type_id = $this
->randomMachineName();
$attached_entity_type = $this
->getMock('\\Drupal\\Core\\Entity\\EntityTypeInterface');
$attached_entity_type
->expects($this
->any())
->method('getProvider')
->will($this
->returnValue('entity_provider_module'));
// Get definition is called three times. Twice in
// ConfigEntityBase::addDependency() to get the provider of the field config
// entity type and once in FieldStorageConfig::calculateDependencies() to
// get the provider of the entity type that field is attached to.
$this->entityManager
->expects($this
->any())
->method('getDefinition')
->willReturnMap([
[
'field_storage_config',
TRUE,
$fieldStorageConfigentityType,
],
[
$attached_entity_type_id,
TRUE,
$attached_entity_type,
],
]);
$this->fieldTypeManager
->expects($this
->atLeastOnce())
->method('getDefinition')
->with('test_field_type', FALSE)
->willReturn([
'class' => TestFieldType::class,
]);
$field_storage = new FieldStorageConfig([
'entity_type' => $attached_entity_type_id,
'field_name' => 'test_field',
'type' => 'test_field_type',
'module' => 'test_module',
]);
$dependencies = $field_storage
->calculateDependencies()
->getDependencies();
$this
->assertEquals([
'entity_provider_module',
'entity_test',
'test_module',
], $dependencies['module']);
$this
->assertEquals([
'stark',
], $dependencies['theme']);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FieldStorageConfigEntityUnitTest:: |
protected | property | The entity manager used for testing. | |
FieldStorageConfigEntityUnitTest:: |
protected | property | The ID of the type of the entity under test. | |
FieldStorageConfigEntityUnitTest:: |
protected | property | The field type manager. | |
FieldStorageConfigEntityUnitTest:: |
protected | property | The UUID generator used for testing. | |
FieldStorageConfigEntityUnitTest:: |
protected | function |
Overrides UnitTestCase:: |
|
FieldStorageConfigEntityUnitTest:: |
public | function | @covers ::calculateDependencies | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed in array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |