class BlazyManagerUnitTest in Blazy 8
Same name and namespace in other branches
- 8.2 tests/src/Unit/BlazyManagerUnitTest.php \Drupal\Tests\blazy\Unit\BlazyManagerUnitTest
@coversDefaultClass \Drupal\blazy\BlazyManager
@group blazy
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\blazy\Unit\BlazyManagerUnitTest uses BlazyManagerUnitTestTrait, BlazyUnitTestTrait
Expanded class hierarchy of BlazyManagerUnitTest
File
- tests/
src/ Unit/ BlazyManagerUnitTest.php, line 15
Namespace
Drupal\Tests\blazy\UnitView source
class BlazyManagerUnitTest extends UnitTestCase {
use BlazyUnitTestTrait;
use BlazyManagerUnitTestTrait;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this
->setUpUnitServices();
$this
->setUpUnitContainer();
$this
->setUpUnitImages();
}
/**
* Tests cases for various methods.
*
* @covers ::getEntityTypeManager
* @covers ::getModuleHandler
* @covers ::getRenderer
* @covers ::getCache
* @covers ::getConfigFactory
*/
public function testBlazyManagerServiceInstances() {
$this
->assertInstanceOf('\\Drupal\\Core\\Entity\\EntityTypeManagerInterface', $this->blazyManager
->getEntityTypeManager());
$this
->assertInstanceOf('\\Drupal\\Core\\Extension\\ModuleHandlerInterface', $this->blazyManager
->getModuleHandler());
$this
->assertInstanceOf('\\Drupal\\Core\\Render\\RendererInterface', $this->blazyManager
->getRenderer());
$this
->assertInstanceOf('\\Drupal\\Core\\Config\\ConfigFactoryInterface', $this->blazyManager
->getConfigFactory());
$this
->assertInstanceOf('\\Drupal\\Core\\Cache\\CacheBackendInterface', $this->blazyManager
->getCache());
}
/**
* Tests cases for config.
*
* @covers ::configLoad
*/
public function testConfigLoad() {
$blazy = $this->blazyManager
->configLoad('blazy');
$this
->assertArrayHasKey('loadInvisible', $blazy);
$admin_css = $this->blazyManager
->configLoad('admin_css', 'blazy.settings');
$this
->assertTrue($admin_css, 'Blazy admin CSS is enabled by default.');
$responsive_image = $this->blazyManager
->configLoad('responsive_image');
$this
->assertTrue($responsive_image, 'Responsive image was disabled by default, yet enabled now.');
}
/**
* Tests cases for config.
*
* @covers ::entityLoad
* @covers ::entityLoadMultiple
*/
public function testEntityLoadImageStyle() {
$styles = $this
->setUpImageStyle();
$ids = array_keys($styles);
$multiple = $this->blazyManager
->entityLoadMultiple('image_style', $ids);
$this
->assertArrayHasKey('large', $multiple);
$expected = $this->blazyManager
->entityLoad('large', 'image_style');
$this
->assertEquals($expected, $multiple['large']);
}
/**
* Test \Drupal\blazy\BlazyManager::cleanUpBreakpoints().
*
* @covers ::cleanUpBreakpoints
* @dataProvider providerTestCleanUpBreakpoints
*/
public function testCleanUpBreakpoints($breakpoints, $expected_breakpoints, $blazy, $expected_blazy) {
$settings['blazy'] = $blazy;
$settings['breakpoints'] = $breakpoints;
$this->blazyManager
->cleanUpBreakpoints($settings);
$this
->assertEquals($expected_breakpoints, $settings['breakpoints']);
}
/**
* Provider for ::testCleanUpBreakpoints().
*/
public function providerTestCleanUpBreakpoints() {
return [
'empty' => [
[],
[],
FALSE,
FALSE,
],
'not so empty' => [
$this
->getEmptyBreakpoints(),
[],
FALSE,
FALSE,
],
'mixed empty' => [
$this
->getDataBreakpoints(),
$this
->getDataBreakpoints(TRUE),
FALSE,
TRUE,
],
'mixed empty blazy enabled first' => [
$this
->getDataBreakpoints(),
$this
->getDataBreakpoints(TRUE),
FALSE,
TRUE,
],
];
}
/**
* Tests for \Drupal\blazy\BlazyManager::preRenderImage().
*
* @covers ::getImage
* @covers ::preRenderImage
* @dataProvider providerTestPreRenderImage
*/
public function testPreRenderImage($item, $uri, $content, $expected_image, $expected_render) {
$build = [];
$build['item'] = $item ? $this->testItem : [];
$build['content'] = $content;
$build['settings'] = BlazyDefault::itemSettings();
$build['settings']['uri'] = $uri;
if ($item) {
$build['item']->_attributes['data-blazy-test'] = TRUE;
}
$image = $this->blazyManager
->getImage($build);
$build_image['#build']['settings'] = array_merge($this
->getCacheMetaData(), $build['settings']);
$build_image['#build']['item'] = $build['item'];
$pre_render = $this->blazyManager
->preRenderImage($build_image);
$check_image = !$expected_image ? empty($image) : !empty($image);
$this
->assertTrue($check_image);
$check_pre_render = !$expected_render ? TRUE : !empty($pre_render);
$this
->assertTrue($check_pre_render);
}
/**
* Provide test cases for ::testPreRenderImage().
*
* @return array
* An array of tested data.
*/
public function providerTestPreRenderImage() {
$data[] = [
FALSE,
'',
'',
TRUE,
TRUE,
];
$data[] = [
TRUE,
'',
'',
TRUE,
TRUE,
];
$data[] = [
TRUE,
'core/misc/druplicon.png',
'',
TRUE,
TRUE,
];
$data[] = [
TRUE,
'core/misc/druplicon.png',
'<iframe src="//www.youtube.com/watch?v=E03HFA923kw" class="b-lazy"></iframe>',
TRUE,
FALSE,
];
return $data;
}
/**
* Tests cases for attachments.
*
* @covers ::attach
* @depends testConfigLoad
*/
public function testAttach() {
$attach = [
'blazy' => TRUE,
'grid' => 0,
'media' => TRUE,
'media_switch' => 'media',
'ratio' => 'fluid',
'style' => 'column',
];
$attachments = $this->blazyManager
->attach($attach);
$this
->assertArrayHasKey('library', $attachments);
$this
->assertArrayHasKey('blazy', $attachments['drupalSettings']);
$this
->assertContains('blazy/media', $attachments['library']);
$this
->assertContains('blazy/ratio', $attachments['library']);
}
/**
* Tests cases for lightboxes.
*
* @covers ::getLightboxes
*/
public function testGetLightboxes() {
$lightboxes = $this->blazyManager
->getLightboxes();
$this
->assertNotContains('nixbox', $lightboxes);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BlazyManagerUnitTest:: |
public | function | Provider for ::testCleanUpBreakpoints(). | |
BlazyManagerUnitTest:: |
public | function | Provide test cases for ::testPreRenderImage(). | |
BlazyManagerUnitTest:: |
protected | function |
Overrides UnitTestCase:: |
|
BlazyManagerUnitTest:: |
public | function | Tests cases for attachments. | |
BlazyManagerUnitTest:: |
public | function | Tests cases for various methods. | |
BlazyManagerUnitTest:: |
public | function | Test \Drupal\blazy\BlazyManager::cleanUpBreakpoints(). | |
BlazyManagerUnitTest:: |
public | function | Tests cases for config. | |
BlazyManagerUnitTest:: |
public | function | Tests cases for config. | |
BlazyManagerUnitTest:: |
public | function | Tests cases for lightboxes. | |
BlazyManagerUnitTest:: |
public | function | Tests for \Drupal\blazy\BlazyManager::preRenderImage(). | |
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. | |
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. |