3 namespace Drupal\outside_in\Tests\Ajax;
5 use Drupal\ajax_test\Controller\AjaxTestController;
6 use Drupal\Core\EventSubscriber\MainContentViewSubscriber;
7 use Drupal\system\Tests\Ajax\AjaxTestBase;
10 * Performs tests on opening and manipulating dialogs via AJAX commands.
14 class OffCanvasDialogTest extends AjaxTestBase {
21 public static $modules = ['outside_in'];
24 * Test sending AJAX requests to open and manipulate off-canvas dialog.
26 public function testDialog() {
27 $this->drupalLogin($this->drupalCreateUser(['administer contact forms']));
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,
55 // Emulate going to the JS version of the page and check the JSON response.
56 $ajax_result = $this->drupalGetAjax('ajax-test/dialog-contents', ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_dialog_off_canvas']]);
57 $this->assertEqual($off_canvas_expected_response, $ajax_result[3], 'off-canvas dialog JSON response matches.');