trait BlazyManagerUnitTestTrait in Blazy 8
Same name and namespace in other branches
- 8.2 tests/src/Traits/BlazyManagerUnitTestTrait.php \Drupal\Tests\blazy\Traits\BlazyManagerUnitTestTrait
A Trait common for Blazy related service managers.
Hierarchy
- trait \Drupal\Tests\blazy\Traits\BlazyManagerUnitTestTrait
5 files declare their use of BlazyManagerUnitTestTrait
- BlazyAdminExtendedUnitTest.php in tests/
src/ Unit/ Form/ BlazyAdminExtendedUnitTest.php - BlazyAdminFormatterUnitTest.php in tests/
src/ Unit/ Form/ BlazyAdminFormatterUnitTest.php - BlazyManagerBaseUnitTest.php in tests/
src/ Unit/ BlazyManagerBaseUnitTest.php - BlazyManagerUnitTest.php in tests/
src/ Unit/ BlazyManagerUnitTest.php - BlazyUnitTest.php in tests/
src/ Unit/ BlazyUnitTest.php
File
- tests/
src/ Traits/ BlazyManagerUnitTestTrait.php, line 12
Namespace
Drupal\Tests\blazy\TraitsView source
trait BlazyManagerUnitTestTrait {
/**
* Setup the unit manager.
*/
protected function setUpUnitServices() {
$this->entityManager = $this
->createMock('Drupal\\Core\\Entity\\EntityManagerInterface');
$this->entityStorage = $this
->createMock('Drupal\\Core\\Entity\\EntityStorageInterface');
$this->entityViewBuilder = $this
->createMock('Drupal\\Core\\Entity\\EntityViewBuilderInterface');
$this->entityTypeMock = $this
->createMock('\\Drupal\\Core\\Entity\\EntityTypeInterface');
$this->entityFieldManager = $this
->createMock('\\Drupal\\Core\\Entity\\EntityFieldManagerInterface');
$this->entityTypeManager = $this
->createMock('\\Drupal\\Core\\Entity\\EntityTypeManagerInterface');
$this->renderer = $this
->createMock('\\Drupal\\Core\\Render\\RendererInterface');
$this->cache = $this
->createMock('\\Drupal\\Core\\Cache\\CacheBackendInterface');
$this->moduleHandler = $this
->getMockBuilder('Drupal\\Core\\Extension\\ModuleHandler')
->disableOriginalConstructor()
->getMock();
$this->token = $this
->getMockBuilder('\\Drupal\\Core\\Utility\\Token')
->disableOriginalConstructor()
->getMock();
$this->token
->expects($this
->any())
->method('replace')
->willReturnArgument(0);
$this->configFactory = $this
->getConfigFactoryStub([
'blazy.settings' => [
'admin_css' => TRUE,
'responsive_image' => TRUE,
'one_pixel' => TRUE,
'blazy' => [
'loadInvisible' => FALSE,
'offset' => 100,
],
],
]);
}
/**
* Setup the unit manager.
*/
protected function setUpUnitContainer() {
$container = new ContainerBuilder();
$container
->set('entity.manager', $this->entityManager);
$container
->set('entity_field.manager', $this->entityFieldManager);
$container
->set('entity_type.manager', $this->entityTypeManager);
$container
->set('module_handler', $this->moduleHandler);
$container
->set('renderer', $this->renderer);
$container
->set('config.factory', $this->configFactory);
$container
->set('cache.default', $this->cache);
$container
->set('token', $this->token);
\Drupal::setContainer($container);
$this->blazyManager = new BlazyManager($this->entityTypeManager, $this->moduleHandler, $this->renderer, $this->configFactory, $this->cache);
}
/**
* Prepare image styles.
*/
protected function setUpImageStyle() {
$styles = [];
$dummies = [
'blazy_crop',
'large',
'medium',
'small',
];
foreach ($dummies as $style) {
$mock = $this
->createMock('Drupal\\Core\\Config\\Entity\\ConfigEntityInterface');
$mock
->expects($this
->any())
->method('getCacheTags')
->willReturn([]);
$styles[$style] = $mock;
}
$ids = array_keys($styles);
$storage = $this
->createMock('\\Drupal\\Core\\Config\\Entity\\ConfigEntityStorageInterface');
$storage
->expects($this
->any())
->method('loadMultiple')
->with($ids)
->willReturn($styles);
$style = 'large';
$storage
->expects($this
->any())
->method('load')
->with($style)
->will($this
->returnValue($styles[$style]));
$this->entityTypeManager
->expects($this
->any())
->method('getStorage')
->with('image_style')
->willReturn($storage);
return $styles;
}
/**
* Prepare Responsive image styles.
*/
protected function setUpResponsiveImageStyle() {
$styles = $image_styles = [];
foreach ([
'fallback',
'small',
'medium',
'large',
] as $style) {
$mock = $this
->createMock('Drupal\\Core\\Config\\Entity\\ConfigEntityInterface');
$mock
->expects($this
->any())
->method('getConfigDependencyName')
->willReturn('image.style.' . $style);
$mock
->expects($this
->any())
->method('getCacheTags')
->willReturn([]);
$image_styles[$style] = $mock;
}
foreach ([
'blazy_picture_test',
'blazy_responsive_test',
] as $style) {
$mock = $this
->createMock('Drupal\\responsive_image\\ResponsiveImageStyleInterface');
$mock
->expects($this
->any())
->method('getImageStyleIds')
->willReturn(array_keys($image_styles));
$mock
->expects($this
->any())
->method('getCacheTags')
->willReturn([]);
$styles[$style] = $mock;
}
$ids = array_keys($styles);
$storage = $this
->createMock('\\Drupal\\Core\\Config\\Entity\\ConfigEntityStorageInterface');
$storage
->expects($this
->any())
->method('loadMultiple')
->with($ids)
->willReturn($styles);
$style = 'blazy_picture_test';
$storage
->expects($this
->any())
->method('load')
->with($style)
->willReturn($styles[$style]);
$this->entityTypeManager
->expects($this
->any())
->method('getStorage')
->with('responsive_image_style')
->willReturn($storage);
$this->entityTypeManager
->expects($this
->any())
->method('getEntityTypeFromClass')
->with('Drupal\\image\\Entity\\ImageStyle')
->willReturn('image_style');
return $styles;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BlazyManagerUnitTestTrait:: |
protected | function | Prepare image styles. | |
BlazyManagerUnitTestTrait:: |
protected | function | Prepare Responsive image styles. | |
BlazyManagerUnitTestTrait:: |
protected | function | Setup the unit manager. | |
BlazyManagerUnitTestTrait:: |
protected | function | Setup the unit manager. |