You are here

public function BlazyEntityReferenceFormatterTest::testFormatterSettingsForm in Blazy 8

Tests the Blazy formatter settings form.

File

tests/src/Kernel/BlazyEntityReferenceFormatterTest.php, line 263

Class

BlazyEntityReferenceFormatterTest
Tests the Blazy entity reference file formatter.

Namespace

Drupal\Tests\blazy\Kernel

Code

public function testFormatterSettingsForm() {

  // @todo remove once corrected, likely broken since Drupal 8.4+.
  if (!$this->formatterInstance) {
    $this
      ->assertEquals(NULL, $this->formatterInstance);
    return;
  }
  $formatter = $this->formatterInstance;
  $definition = array_merge($formatter
    ->getScopedFormElements(), $this
    ->getFormatterDefinition());
  $definition['settings'] = array_merge($definition['settings'], $this
    ->getDefaultFields(TRUE));

  // Check for settings form.
  $form = [];
  $form_state = new FormState();

  // Verify global option current_view_mode is available.
  $form['overlay']['#description'] = '';
  $definition['_views'] = TRUE;
  $form['disabled_access'] = [
    '#type' => 'hidden',
    '#access' => FALSE,
  ];

  // Check for formatter buildSettingsForm.
  $this->blazyAdminFormatter
    ->buildSettingsForm($form, $definition);
  $this
    ->assertArrayHasKey('current_view_mode', $form);

  // Check for setttings form.
  $elements = $formatter
    ->settingsForm($form, $form_state);
  $this
    ->assertArrayHasKey('closing', $elements);
  $default_settings = $formatter::defaultSettings();
  $this
    ->assertArrayHasKey('image_style', $default_settings);

  // Tests the Blazy admin formatters.
  $this
    ->assertArrayHasKey('fieldable_form', $definition);

  // Verify summary is working.
  $summary = $formatter
    ->settingsSummary();
  foreach ($summary as $markup) {
    $arguments = $markup
      ->getArguments();
    $this
      ->assertArrayHasKey('@title', $arguments);
  }
  $formatter_settings = $formatter
    ->buildSettings();
  $this
    ->assertArrayHasKey('plugin_id', $formatter_settings);
}