function AjaxCommandsTest::testOpenModalDialogCommand

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Ajax/AjaxCommandsTest.php \Drupal\Tests\Core\Ajax\AjaxCommandsTest::testOpenModalDialogCommand()
  2. 8.9.x core/tests/Drupal/Tests/Core/Ajax/AjaxCommandsTest.php \Drupal\Tests\Core\Ajax\AjaxCommandsTest::testOpenModalDialogCommand()
  3. 10 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 457

Class

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

Namespace

Drupal\Tests\Core\Ajax

Code

public function testOpenModalDialogCommand() : void {
    $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());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.