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 * @dataProvider dialogPosition
29 public function testDialog($position) {
30 // Ensure the elements render without notices or exceptions.
31 $this->drupalGet('ajax-test/dialog');
33 // Set up variables for this test.
34 $dialog_renderable = AjaxTestController::dialogContents();
35 $dialog_contents = \Drupal::service('renderer')->renderRoot($dialog_renderable);
37 $off_canvas_expected_response = [
38 'command' => 'openDialog',
39 'selector' => '#drupal-off-canvas',
41 'data' => $dialog_contents,
44 'title' => 'AJAX Dialog & contents',
46 'autoResize' => FALSE,
49 'drupalAutoButtons' => FALSE,
50 'drupalOffCanvasPosition' => $position ?: 'side',
52 'dialogClass' => 'ui-dialog-off-canvas ui-dialog-position-' . ($position ?: 'side'),
59 // Emulate going to the JS version of the page and check the JSON response.
60 $wrapper_format = $position && ($position !== 'side') ? 'drupal_dialog.off_canvas_' . $position : 'drupal_dialog.off_canvas';
61 $ajax_result = $this->drupalGet('ajax-test/dialog-contents', ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => $wrapper_format]]);
62 $ajax_result = Json::decode($ajax_result);
63 $this->assertEquals($off_canvas_expected_response, $ajax_result[3], 'off-canvas dialog JSON response matches.');
67 * The data provider for potential dialog positions.
71 public static function dialogPosition() {