class BlazyAdminFormatterUnitTest in Blazy 8.2
Same name and namespace in other branches
- 8 tests/src/Unit/Form/BlazyAdminFormatterUnitTest.php \Drupal\Tests\blazy\Unit\Form\BlazyAdminFormatterUnitTest
Tests the Blazy admin formatter form.
@coversDefaultClass \Drupal\blazy\Form\BlazyAdminFormatter @group blazy
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\blazy\Unit\Form\BlazyAdminFormatterUnitTest uses BlazyManagerUnitTestTrait, BlazyUnitTestTrait
Expanded class hierarchy of BlazyAdminFormatterUnitTest
File
- tests/
src/ Unit/ Form/ BlazyAdminFormatterUnitTest.php, line 18
Namespace
Drupal\Tests\blazy\Unit\FormView source
class BlazyAdminFormatterUnitTest extends UnitTestCase {
use BlazyUnitTestTrait;
use BlazyManagerUnitTestTrait;
/**
* The mocked translator.
*
* @var \Drupal\Core\StringTranslation\TranslationInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $stringTranslation;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this
->setUpUnitServices();
$this
->setUpUnitContainer();
$this->stringTranslation = $this
->createMock('Drupal\\Core\\StringTranslation\\TranslationInterface');
$this->entityDisplayRepository = $this
->createMock('Drupal\\Core\\Entity\\EntityDisplayRepositoryInterface');
$this->typedConfig = $this
->createMock('Drupal\\Core\\Config\\TypedConfigManagerInterface');
$this->dateFormatter = $this
->getMockBuilder('Drupal\\Core\\Datetime\\DateFormatter')
->disableOriginalConstructor()
->getMock();
$container = new ContainerBuilder();
$container
->set('entity_display.repository', $this->entityDisplayRepository);
$container
->set('config.typed', $this->typedConfig);
$container
->set('string_translation', $this
->getStringTranslationStub());
$container
->set('date.formatter', $this->dateFormatter);
$container
->set('blazy.manager', $this->blazyManager);
\Drupal::setContainer($container);
$this->blazyAdminFormatter = new BlazyAdminFormatter($this->entityDisplayRepository, $this->typedConfig, $this->dateFormatter, $this->blazyManager);
}
/**
* @covers ::buildSettingsForm
* @covers ::openingForm
* @covers ::imageStyleForm
* @covers ::mediaSwitchForm
* @covers ::gridForm
* @covers ::closingForm
* @covers ::finalizeForm
*/
public function testBuildSettingsForm() {
$form = [];
$definition = $this
->getDefaulEntityFormatterDefinition() + $this
->getDefaultFormatterDefinition();
$definition['settings'] += $this
->getDefaultFields(TRUE);
$this->blazyAdminFormatter
->buildSettingsForm($form, $definition);
$this
->assertArrayHasKey('closing', $form);
}
/**
* Provider for ::testGetSettingsSummary.
*/
public function providerTestGetSettingsSummary() {
return [
[
FALSE,
FALSE,
FALSE,
'',
FALSE,
],
[
TRUE,
TRUE,
TRUE,
'blazy_responsive_test',
TRUE,
],
[
TRUE,
FALSE,
FALSE,
'',
TRUE,
],
];
}
/**
* Tests the Blazy admin ::getSettingsSummary().
*
* @dataProvider providerTestGetSettingsSummary
*/
public function testGetSettingsSummary($use_settings, $vanilla, $override, $responsive_image_style, $expected) {
$definition = $this
->getFormatterDefinition();
$settings = array_merge(BlazyDefault::gridSettings(), $definition['settings']);
$settings['vanilla'] = $vanilla;
$settings['image_syle'] = 'large';
$settings['box_style'] = 'blazy_crop';
$settings['thumbnail_style'] = 'thumbnail';
$settings['optionset'] = 'default';
$settings['override'] = $override;
$settings['overridables'] = [
'foo' => 'foo',
'bar' => '0',
];
$settings['responsive_image_style'] = $responsive_image_style;
$settings['caption'] = [
'alt' => 'alt',
'title' => 'title',
];
$definition['settings'] = $use_settings ? $settings : [];
$summary = $this->blazyAdminFormatter
->getSettingsSummary($definition);
$summary = array_filter($summary);
$check_summary = !$expected ? empty($summary) : !empty($summary);
$this
->assertTrue($check_summary);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BlazyAdminFormatterUnitTest:: |
protected | property | The mocked translator. | |
BlazyAdminFormatterUnitTest:: |
public | function | Provider for ::testGetSettingsSummary. | |
BlazyAdminFormatterUnitTest:: |
protected | function |
Overrides UnitTestCase:: |
|
BlazyAdminFormatterUnitTest:: |
public | function | @covers ::buildSettingsForm @covers ::openingForm @covers ::imageStyleForm @covers ::mediaSwitchForm @covers ::gridForm @covers ::closingForm @covers ::finalizeForm | |
BlazyAdminFormatterUnitTest:: |
public | function | Tests the Blazy admin ::getSettingsSummary(). | |
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 entity 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 filter format. | |
BlazyPropertiesTestTrait:: |
protected | property | The filter format. | |
BlazyPropertiesTestTrait:: |
protected | property | The formatter definition. | |
BlazyPropertiesTestTrait:: |
protected | property | The formatter plugin manager. | |
BlazyPropertiesTestTrait:: |
protected | property | The created image item. | |
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 | Returns the default field formatter definition. | |
BlazyUnitTestTrait:: |
protected | function | Returns the default field definition. | |
BlazyUnitTestTrait:: |
protected | function | Returns dummy fields for an entity reference. | |
BlazyUnitTestTrait:: |
protected | function | Returns the default field formatter definition. | |
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. |