3 namespace Drupal\Tests\blazy\Unit\Form;
5 use Drupal\Core\DependencyInjection\ContainerBuilder;
6 use Drupal\blazy\Form\BlazyAdminFormatter;
7 use Drupal\blazy\Dejavu\BlazyDefault;
8 use Drupal\Tests\UnitTestCase;
9 use Drupal\Tests\blazy\Traits\BlazyUnitTestTrait;
10 use Drupal\Tests\blazy\Traits\BlazyManagerUnitTestTrait;
13 * Tests the Blazy admin formatter form.
15 * @coversDefaultClass \Drupal\blazy\Form\BlazyAdminFormatter
18 class BlazyAdminFormatterUnitTest extends UnitTestCase {
20 use BlazyUnitTestTrait;
21 use BlazyManagerUnitTestTrait;
24 * The mocked translator.
26 * @var \Drupal\Core\StringTranslation\TranslationInterface|\PHPUnit_Framework_MockObject_MockObject
28 protected $stringTranslation;
33 protected function setUp() {
36 $this->setUpUnitServices();
37 $this->setUpUnitContainer();
39 $this->stringTranslation = $this->getMock('Drupal\Core\StringTranslation\TranslationInterface');
40 $this->entityDisplayRepository = $this->getMock('Drupal\Core\Entity\EntityDisplayRepositoryInterface');
41 $this->typedConfig = $this->getMock('Drupal\Core\Config\TypedConfigManagerInterface');
42 $this->dateFormatter = $this->getMockBuilder('Drupal\Core\Datetime\DateFormatter')
43 ->disableOriginalConstructor()
46 $container = new ContainerBuilder();
47 $container->set('entity_display.repository', $this->entityDisplayRepository);
48 $container->set('config.typed', $this->typedConfig);
49 $container->set('string_translation', $this->getStringTranslationStub());
50 $container->set('date.formatter', $this->dateFormatter);
52 \Drupal::setContainer($container);
54 $this->blazyAdminFormatter = new BlazyAdminFormatter(
55 $this->entityDisplayRepository,
62 * @covers ::buildSettingsForm
63 * @covers ::openingForm
64 * @covers ::imageStyleForm
65 * @covers ::mediaSwitchForm
67 * @covers ::breakpointsForm
68 * @covers ::closingForm
69 * @covers ::finalizeForm
71 public function testBuildSettingsForm() {
73 $definition = $this->getDefaulEntityFormatterDefinition() + $this->getDefaultFormatterDefinition();
75 $definition['settings'] += $this->getDefaultFields(TRUE);
77 $this->blazyAdminFormatter->buildSettingsForm($form, $definition);
78 $this->assertArrayHasKey('closing', $form);
82 * Provider for ::testGetSettingsSummary.
84 public function providerTestGetSettingsSummary() {
86 [FALSE, FALSE, FALSE, '', FALSE],
87 [TRUE, TRUE, TRUE, 'blazy_responsive_test', TRUE],
88 [TRUE, FALSE, FALSE, '', TRUE],
93 * Tests the Blazy admin ::getSettingsSummary().
95 * @dataProvider providerTestGetSettingsSummary
97 public function testGetSettingsSummary($use_settings, $vanilla, $override, $responsive_image_style, $expected) {
98 $definition = $this->getFormatterDefinition();
99 $settings = array_merge(BlazyDefault::gridSettings(), $definition['settings']);
101 $settings['vanilla'] = $vanilla;
102 $settings['image_syle'] = 'large';
103 $settings['box_style'] = 'blazy_crop';
104 $settings['thumbnail_style'] = 'thumbnail';
105 $settings['optionset'] = 'default';
106 $settings['override'] = $override;
107 $settings['overridables'] = ['foo' => 'foo', 'bar' => '0'];
108 $settings['responsive_image_style'] = $responsive_image_style;
109 $settings['caption'] = ['alt' => 'alt', 'title' => 'title'];
110 $settings['breakpoints'] = $this->getDataBreakpoints(TRUE);
112 $definition['settings'] = $use_settings ? $settings : [];
114 $summary = $this->blazyAdminFormatter->getSettingsSummary($definition);
115 $summary = array_filter($summary);
116 $check_summary = !$expected ? empty($summary) : !empty($summary);
118 $this->assertTrue($check_summary);