3 namespace Drupal\Tests\blazy\Unit;
5 use Drupal\Tests\UnitTestCase;
6 use Drupal\blazy\BlazyMedia;
7 use Drupal\Tests\blazy\Traits\BlazyUnitTestTrait;
10 * @coversDefaultClass \Drupal\blazy\BlazyMedia
14 class BlazyMediaUnitTest extends UnitTestCase {
16 use BlazyUnitTestTrait;
21 protected function setUp() {
24 $this->setUpVariables();
25 $this->setUpUnitImages();
29 * Tests \Drupal\blazy\BlazyMedia::build().
33 * @dataProvider providerTestBlazyMediaBuild
35 public function testBlazyMediaBuild($markup) {
37 'source_field' => $this->randomMachineName(),
38 'image_style' => 'blazy_crop',
40 'view_mode' => 'default',
41 'bundle' => 'entity_test',
44 $markup['#settings'] = $settings;
45 $markup['#attached'] = [];
46 $markup['#cache'] = [];
48 /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
49 $entity = $this->getMock('Drupal\Core\Entity\ContentEntityInterface');
50 $field_definition = $this->getMock('Drupal\Core\Field\FieldDefinitionInterface');
52 $items = $this->getMock('Drupal\Core\Field\FieldItemListInterface');
53 $items->expects($this->any())
54 ->method('getFieldDefinition')
55 ->willReturn($field_definition);
56 $items->expects($this->any())
58 ->with($settings['view_mode'])
59 ->willReturn($markup);
60 $items->expects($this->any())
62 ->willReturn($entity);
64 $entity->expects($this->once())
66 ->with($settings['source_field'])
67 ->will($this->returnValue($items));
69 $render = BlazyMedia::build($entity, $settings);
70 $this->assertArrayHasKey('#settings', $render);
74 * Provider for ::testBlazyMediaBuild.
76 public function providerTestBlazyMediaBuild() {
78 '#type' => 'html_tag',
81 'allowfullscreen' => 'true',
84 'src' => '//www.youtube.com/watch?v=E03HFA923kw',
90 $markup['#markup'] = '<iframe src="//www.youtube.com/watch?v=E03HFA923kw" class="b-lazy"></iframe>';
93 'With children, has iframe tag' => [
96 'Without children, has iframe tag' => [
99 'With children, has no iframe tag' => [