Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / system / tests / src / Functional / Ajax / OffCanvasDialogTest.php
1 <?php
2
3 namespace Drupal\Tests\system\Functional\Ajax;
4
5 use Drupal\ajax_test\Controller\AjaxTestController;
6 use Drupal\Component\Serialization\Json;
7 use Drupal\Core\EventSubscriber\MainContentViewSubscriber;
8 use Drupal\Tests\BrowserTestBase;
9
10 /**
11  * Performs tests on opening and manipulating dialogs via AJAX commands.
12  *
13  * @group Ajax
14  */
15 class OffCanvasDialogTest extends BrowserTestBase {
16
17   /**
18    * Modules to enable.
19    *
20    * @var array
21    */
22   public static $modules = ['ajax_test'];
23
24   /**
25    * Test sending AJAX requests to open and manipulate off-canvas dialog.
26    */
27   public function testDialog() {
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           'dialogClass' => 'ui-dialog-off-canvas',
50           'width' => 300,
51         ],
52       'effect' => 'fade',
53       'speed' => 1000,
54     ];
55
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.');
60   }
61
62 }