public function BlazyMediaUnitTest::testBlazyMediaBuild in Blazy 8
Same name and namespace in other branches
- 8.2 tests/src/Unit/BlazyMediaUnitTest.php \Drupal\Tests\blazy\Unit\BlazyMediaUnitTest::testBlazyMediaBuild()
Tests \Drupal\blazy\BlazyMedia::build().
@covers ::build @covers ::wrap @dataProvider providerTestBlazyMediaBuild
File
- tests/
src/ Unit/ BlazyMediaUnitTest.php, line 35
Class
- BlazyMediaUnitTest
- @coversDefaultClass \Drupal\blazy\BlazyMedia
Namespace
Drupal\Tests\blazy\UnitCode
public function testBlazyMediaBuild($markup) {
$settings = [
'source_field' => $this
->randomMachineName(),
'image_style' => 'blazy_crop',
'ratio' => 'fluid',
'view_mode' => 'default',
'bundle' => 'entity_test',
];
$markup['#settings'] = $settings;
$markup['#attached'] = [];
$markup['#cache'] = [];
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$entity = $this
->createMock('Drupal\\Core\\Entity\\ContentEntityInterface');
$field_definition = $this
->createMock('Drupal\\Core\\Field\\FieldDefinitionInterface');
$items = $this
->createMock('Drupal\\Core\\Field\\FieldItemListInterface');
$items
->expects($this
->any())
->method('getFieldDefinition')
->willReturn($field_definition);
$items
->expects($this
->any())
->method('view')
->with($settings['view_mode'])
->willReturn($markup);
$items
->expects($this
->any())
->method('getEntity')
->willReturn($entity);
$entity
->expects($this
->once())
->method('get')
->with($settings['source_field'])
->will($this
->returnValue($items));
$render = BlazyMedia::build($entity, $settings);
$this
->assertArrayHasKey('#settings', $render);
}