protected function AssetFileEntityHelperTest::setMockedDrupalServices in Media: Acquia DAM 8
Sets Drupal mocked services into a container.
Parameters
\Drupal\Core\DependencyInjection\ContainerBuilder $container: The container to set mocks into.
1 call to AssetFileEntityHelperTest::setMockedDrupalServices()
- AssetFileEntityHelperTest::setUp in tests/
src/ Unit/ AssetFileEntityHelperTest.php
File
- tests/
src/ Unit/ AssetFileEntityHelperTest.php, line 123
Class
- AssetFileEntityHelperTest
- Tests to validate that our file entity helper works as expected.
Namespace
Drupal\Tests\media_acquiadam\UnitCode
protected function setMockedDrupalServices(ContainerBuilder $container) {
$file_storage = $this
->getMockBuilder(EntityStorageInterface::class)
->disableOriginalConstructor()
->getMock();
$file_storage
->method('load')
->with($this->mockedFileEntity
->id())
->willReturn($this->mockedFileEntity);
$file_storage
->method('loadByProperties')
->willReturnMap([
[
[
'uri' => 'private://assets/replaced/' . $this
->getAssetData()->filename,
],
[
$this->mockedFileEntity,
],
],
[
[
'uri' => 'private://assets/replaced/Micro turbine 60.jpg',
],
[
$this->mockedFileEntity,
],
],
]);
$entity_type_manager = $this
->getMockBuilder(EntityTypeManagerInterface::class)
->disableOriginalConstructor()
->getMock();
$entity_type_manager
->method('getStorage')
->willReturnMap([
[
'file',
$file_storage,
],
]);
$data_definition = $this
->getMockBuilder(DataDefinitionInterface::class)
->disableOriginalConstructor()
->getMock();
$data_definition
->method('getSetting')
->willReturnMap([
[
'uri_scheme',
'private',
],
[
'file_directory',
'assets/[token]',
],
]);
$field_definition = $this
->getMockBuilder(FieldDefinitionInterface::class)
->disableOriginalConstructor()
->getMock();
$field_definition
->method('getItemDefinition')
->willReturn($data_definition);
$entity_field_manager = $this
->getMockBuilder(EntityFieldManagerInterface::class)
->disableOriginalConstructor()
->getMock();
$entity_field_manager
->method('getFieldDefinitions')
->willReturnMap([
[
'media',
'acquiadam',
[
'phpunit_file_field' => $field_definition,
],
],
]);
$token = $this
->getMockBuilder(Token::class)
->disableOriginalConstructor()
->getMock();
$token
->method('replace')
->willReturnCallback(function ($string, $a, $b, $c) {
return 'assets/[token]' == $string ? 'assets/replaced' : $string;
});
$file_system = $this
->getMockBuilder(FileSystem::class)
->disableOriginalConstructor()
->setMethods([
'prepareDirectory',
])
->getMockForAbstractClass();
$file_system
->method('prepareDirectory')
->willReturnMap([
[
'private://assets/replaced',
FileSystemInterface::CREATE_DIRECTORY,
TRUE,
],
]);
$container
->set('entity_type.manager', $entity_type_manager);
$container
->set('entity_field.manager', $entity_field_manager);
$container
->set('config.factory', $this
->getConfigFactoryStub());
$container
->set('file_system', $file_system);
$container
->set('token', $token);
}