You are here

public function AjaxCommandsTest::testOpenModalDialogCommand in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Ajax/AjaxCommandsTest.php \Drupal\Tests\Core\Ajax\AjaxCommandsTest::testOpenModalDialogCommand()
  2. 9 core/tests/Drupal/Tests/Core/Ajax/AjaxCommandsTest.php \Drupal\Tests\Core\Ajax\AjaxCommandsTest::testOpenModalDialogCommand()

@covers \Drupal\Core\Ajax\OpenModalDialogCommand

File

core/tests/Drupal/Tests/Core/Ajax/AjaxCommandsTest.php, line 381

Class

AjaxCommandsTest
Test coverage for various classes in the \Drupal\Core\Ajax namespace.

Namespace

Drupal\Tests\Core\Ajax

Code

public function testOpenModalDialogCommand() {
  $command = $this
    ->getMockBuilder('Drupal\\Core\\Ajax\\OpenModalDialogCommand')
    ->setConstructorArgs([
    'Title',
    '<p>Text!</p>',
    [
      'url' => 'example',
      'width' => 500,
    ],
  ])
    ->onlyMethods([
    'getRenderedContent',
  ])
    ->getMock();

  // This method calls the render service, which isn't available. We want it
  // to do nothing so we mock it to return a known value.
  $command
    ->expects($this
    ->once())
    ->method('getRenderedContent')
    ->willReturn('rendered content');
  $expected = [
    'command' => 'openDialog',
    'selector' => '#drupal-modal',
    'settings' => NULL,
    'data' => 'rendered content',
    'dialogOptions' => [
      'url' => 'example',
      'width' => 500,
      'title' => 'Title',
      'modal' => TRUE,
    ],
  ];
  $this
    ->assertEquals($expected, $command
    ->render());
}