You are here

public function WebformDialogHelperTest::testGetModalDialogAttributes in Webform 8.5

Same name and namespace in other branches
  1. 6.x tests/src/Kernel/Utility/WebformDialogHelperTest.php \Drupal\Tests\webform\Kernel\Utility\WebformDialogHelperTest::testGetModalDialogAttributes()

Test get modal dialog attributes.

See also

\Drupal\webform\Utility\WebformDialogHelper::getModalDialogAttributes

File

tests/src/Kernel/Utility/WebformDialogHelperTest.php, line 27

Class

WebformDialogHelperTest
Tests webform dialog utility.

Namespace

Drupal\Tests\webform\Kernel\Utility

Code

public function testGetModalDialogAttributes() {

  // Enable dialogs.
  $this
    ->config('webform.settings')
    ->set('ui.dialog_disabled', FALSE)
    ->save();

  // Check default attributes.
  $this
    ->assertEquals(WebformDialogHelper::getModalDialogAttributes(), [
    'class' => [
      'webform-ajax-link',
    ],
    'data-dialog-type' => 'modal',
    'data-dialog-options' => '{"width":800,"dialogClass":"webform-ui-dialog"}',
  ]);

  // Check custom width and attributes.
  $this
    ->assertEquals(WebformDialogHelper::getModalDialogAttributes(400, [
    'custom',
  ]), [
    'class' => [
      'custom',
      'webform-ajax-link',
    ],
    'data-dialog-type' => 'modal',
    'data-dialog-options' => '{"width":400,"dialogClass":"webform-ui-dialog"}',
  ]);

  // Disable dialogs.
  $this
    ->config('webform.settings')
    ->set('ui.dialog_disabled', TRUE)
    ->save();

  // Check default attributes.
  $this
    ->assertEquals(WebformDialogHelper::getModalDialogAttributes(), []);

  // Check custom attributes.
  $this
    ->assertEquals(WebformDialogHelper::getModalDialogAttributes(400, [
    'custom',
  ]), [
    'class' => [
      'custom',
    ],
  ]);
}