You are here

public function AjaxCommandsTest::testOpenModalDialogCommand in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 334
Contains \Drupal\Tests\Core\Ajax\AjaxCommandsTest.

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(array(
    'Title',
    '<p>Text!</p>',
    array(
      'url' => 'example',
      'width' => 500,
    ),
  ))
    ->setMethods(array(
    '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 = array(
    'command' => 'openDialog',
    'selector' => '#drupal-modal',
    'settings' => NULL,
    'data' => 'rendered content',
    'dialogOptions' => array(
      'url' => 'example',
      'width' => 500,
      'title' => 'Title',
      'modal' => TRUE,
    ),
  );
  $this
    ->assertEquals($expected, $command
    ->render());
}