class BlazyMediaUnitTest in Blazy 8
Same name and namespace in other branches
- 8.2 tests/src/Unit/BlazyMediaUnitTest.php \Drupal\Tests\blazy\Unit\BlazyMediaUnitTest
@coversDefaultClass \Drupal\blazy\BlazyMedia
@group blazy
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\blazy\Unit\BlazyMediaUnitTest uses BlazyUnitTestTrait
Expanded class hierarchy of BlazyMediaUnitTest
File
- tests/
src/ Unit/ BlazyMediaUnitTest.php, line 14
Namespace
Drupal\Tests\blazy\UnitView source
class BlazyMediaUnitTest extends UnitTestCase {
use BlazyUnitTestTrait;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this
->setUpVariables();
$this
->setUpUnitImages();
}
/**
* Tests \Drupal\blazy\BlazyMedia::build().
*
* @covers ::build
* @covers ::wrap
* @dataProvider providerTestBlazyMediaBuild
*/
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);
}
/**
* Provider for ::testBlazyMediaBuild.
*/
public function providerTestBlazyMediaBuild() {
$iframe = [
'#type' => 'html_tag',
'#tag' => 'iframe',
'#attributes' => [
'allowfullscreen' => 'true',
'frameborder' => 0,
'scrolling' => 'no',
'src' => '//www.youtube.com/watch?v=E03HFA923kw',
'width' => 640,
'height' => 360,
],
];
$markup['#markup'] = '<iframe src="//www.youtube.com/watch?v=E03HFA923kw" class="b-lazy"></iframe>';
return [
'With children, has iframe tag' => [
[
$iframe,
],
],
'Without children, has iframe tag' => [
$iframe,
],
'With children, has no iframe tag' => [
[
$markup,
],
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BlazyMediaUnitTest:: |
public | function | Provider for ::testBlazyMediaBuild. | |
BlazyMediaUnitTest:: |
protected | function |
Overrides UnitTestCase:: |
|
BlazyMediaUnitTest:: |
public | function | Tests \Drupal\blazy\BlazyMedia::build(). | |
BlazyPropertiesTestTrait:: |
protected | property | The blazy admin service. | |
BlazyPropertiesTestTrait:: |
protected | property | The blazy admin service. | |
BlazyPropertiesTestTrait:: |
protected | property | The blazy manager service. | |
BlazyPropertiesTestTrait:: |
protected | property | The bundle name. | |
BlazyPropertiesTestTrait:: |
protected | property | The entity display. | |
BlazyPropertiesTestTrait:: |
protected | property | The entity. | |
BlazyPropertiesTestTrait:: |
protected | property | The entity. | |
BlazyPropertiesTestTrait:: |
protected | property | The entity manager. | |
BlazyPropertiesTestTrait:: |
protected | property | The tested entity reference formatter ID. | |
BlazyPropertiesTestTrait:: |
protected | property | The tested entity type. | |
BlazyPropertiesTestTrait:: |
protected | property | The formatter definition. | |
BlazyPropertiesTestTrait:: |
protected | property | The formatter plugin manager. | |
BlazyPropertiesTestTrait:: |
protected | property | The maximum number of created images. | |
BlazyPropertiesTestTrait:: |
protected | property | The maximum number of created paragraphs. | |
BlazyPropertiesTestTrait:: |
protected | property | The node entity. | |
BlazyPropertiesTestTrait:: |
protected | property | The referenced node entity. | |
BlazyPropertiesTestTrait:: |
protected | property | The node entity. | |
BlazyPropertiesTestTrait:: |
protected | property | The tested skins. | |
BlazyPropertiesTestTrait:: |
protected | property | The target bundle names. | |
BlazyPropertiesTestTrait:: |
protected | property | The tested empty field name. | |
BlazyPropertiesTestTrait:: |
protected | property | The tested empty field type. | |
BlazyPropertiesTestTrait:: |
protected | property | The tested field name. | |
BlazyPropertiesTestTrait:: |
protected | property | The tested field type. | |
BlazyPropertiesTestTrait:: |
protected | property | The created item. | |
BlazyPropertiesTestTrait:: |
protected | property | The created items. | |
BlazyPropertiesTestTrait:: |
protected | property | The tested formatter ID. | |
BlazyPropertiesTestTrait:: |
protected | property | The tested type definitions. | |
BlazyUnitTestTrait:: |
protected | property | The formatter settings. | |
BlazyUnitTestTrait:: |
protected | function | Pre render Blazy image. | |
BlazyUnitTestTrait:: |
protected | function | Return dummy cache metadata. | |
BlazyUnitTestTrait:: |
protected | function | Add partially empty data for breakpoints. | |
BlazyUnitTestTrait:: |
protected | function | Returns the default field formatter definition. | |
BlazyUnitTestTrait:: |
protected | function | Returns dummy fields for an entity reference. | |
BlazyUnitTestTrait:: |
protected | function | Returns the default field formatter definition. | |
BlazyUnitTestTrait:: |
protected | function | Add empty data for breakpoints. | |
BlazyUnitTestTrait:: |
protected | function | Returns the field formatter definition along with settings. | |
BlazyUnitTestTrait:: |
protected | function | Returns sensible formatter settings for testing purposes. | |
BlazyUnitTestTrait:: |
protected | function | Sets the field formatter definition. | |
BlazyUnitTestTrait:: |
protected | function | Sets formatter setting. | |
BlazyUnitTestTrait:: |
protected | function | Sets formatter settings. | |
BlazyUnitTestTrait:: |
protected | function | Setup the unit images. | |
BlazyUnitTestTrait:: |
protected | function | Setup the unit images. | |
BlazyUnitTestTrait:: |
protected | function | Set up Blazy variables. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed 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. |