Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / outside_in / src / Tests / Ajax / OffCanvasDialogTest.php
1 <?php
2
3 namespace Drupal\outside_in\Tests\Ajax;
4
5 use Drupal\ajax_test\Controller\AjaxTestController;
6 use Drupal\Core\EventSubscriber\MainContentViewSubscriber;
7 use Drupal\system\Tests\Ajax\AjaxTestBase;
8
9 /**
10  * Performs tests on opening and manipulating dialogs via AJAX commands.
11  *
12  * @group outside_in
13  */
14 class OffCanvasDialogTest extends AjaxTestBase {
15
16   /**
17    * Modules to enable.
18    *
19    * @var array
20    */
21   public static $modules = ['outside_in'];
22
23   /**
24    * Test sending AJAX requests to open and manipulate off-canvas dialog.
25    */
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');
30
31     // Set up variables for this test.
32     $dialog_renderable = AjaxTestController::dialogContents();
33     $dialog_contents = \Drupal::service('renderer')->renderRoot($dialog_renderable);
34
35     $off_canvas_expected_response = [
36       'command' => 'openDialog',
37       'selector' => '#drupal-off-canvas',
38       'settings' => NULL,
39       'data' => $dialog_contents,
40       'dialogOptions' =>
41         [
42           'title' => 'AJAX Dialog & contents',
43           'modal' => FALSE,
44           'autoResize' => FALSE,
45           'resizable' => 'w',
46           'draggable' => FALSE,
47           'drupalAutoButtons' => FALSE,
48           'buttons' => [],
49           'width' => 300,
50         ],
51       'effect' => 'fade',
52       'speed' => 1000,
53     ];
54
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.');
58   }
59
60 }