3 namespace Drupal\Tests\system\Functional\Ajax;
5 use Drupal\ajax_test\Controller\AjaxTestController;
6 use Drupal\Component\Serialization\Json;
7 use Drupal\Core\EventSubscriber\MainContentViewSubscriber;
8 use Drupal\Tests\BrowserTestBase;
11 * Performs tests on opening and manipulating dialogs via AJAX commands.
15 class OffCanvasDialogTest extends BrowserTestBase {
22 public static $modules = ['ajax_test'];
25 * Test sending AJAX requests to open and manipulate off-canvas dialog.
27 public function testDialog() {
28 // Ensure the elements render without notices or exceptions.
29 $this->drupalGet('ajax-test/dialog');
31 // Set up variables for this test.
32 $dialog_renderable = AjaxTestController::dialogContents();
33 $dialog_contents = \Drupal::service('renderer')->renderRoot($dialog_renderable);
35 $off_canvas_expected_response = [
36 'command' => 'openDialog',
37 'selector' => '#drupal-off-canvas',
39 'data' => $dialog_contents,
42 'title' => 'AJAX Dialog & contents',
44 'autoResize' => FALSE,
47 'drupalAutoButtons' => FALSE,
49 'dialogClass' => 'ui-dialog-off-canvas',
56 // Emulate going to the JS version of the page and check the JSON response.
57 $ajax_result = $this->drupalGet('ajax-test/dialog-contents', ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_dialog.off_canvas']]);
58 $ajax_result = Json::decode($ajax_result);
59 $this->assertEqual($off_canvas_expected_response, $ajax_result[3], 'off-canvas dialog JSON response matches.');