function FrameworkTest::testAJAXRenderError

Tests behavior of ajax_render_error().

File

drupal/core/modules/system/lib/Drupal/system/Tests/Ajax/FrameworkTest.php, line 50
Definition of Drupal\system\Tests\Ajax\FrameworkTest.

Class

FrameworkTest
Tests primary Ajax framework functions.

Namespace

Drupal\system\Tests\Ajax

Code

function testAJAXRenderError() {

  // Verify default error message.
  $commands = $this
    ->drupalGetAJAX('ajax-test/render-error');
  $expected = array(
    'command' => 'alert',
    'text' => t('An error occurred while handling the request: The server received invalid input.'),
  );
  $this
    ->assertCommand($commands, $expected, 'ajax_render_error() invokes alert command.');

  // Verify custom error message.
  $edit = array(
    'message' => 'Custom error message.',
  );
  $commands = $this
    ->drupalGetAJAX('ajax-test/render-error', array(
    'query' => $edit,
  ));
  $expected = array(
    'command' => 'alert',
    'text' => $edit['message'],
  );
  $this
    ->assertCommand($commands, $expected, 'Custom error message is output.');
}