1<?php
2
3namespace Drupal\Tests\Core\Ajax;
4
5use Drupal\Core\Ajax\OpenOffCanvasDialogCommand;
6use Drupal\Tests\UnitTestCase;
7
8/**
9 * @coversDefaultClass \Drupal\Core\Ajax\OpenOffCanvasDialogCommand
10 * @group Ajax
11 */
12class OpenOffCanvasDialogCommandTest extends UnitTestCase {
13
14  /**
15   * @covers ::render
16   *
17   * @dataProvider dialogPosition
18   */
19  public function testRender($position) {
20    $command = new OpenOffCanvasDialogCommand('Title', '<p>Text!</p>', ['url' => 'example'], NULL, $position);
21
22    $expected = [
23      'command' => 'openDialog',
24      'selector' => '#drupal-off-canvas',
25      'settings' => NULL,
26      'data' => '<p>Text!</p>',
27      'dialogOptions' => [
28        'url' => 'example',
29        'title' => 'Title',
30        'modal' => FALSE,
31        'autoResize' => FALSE,
32        'resizable' => 'w',
33        'draggable' => FALSE,
34        'drupalAutoButtons' => FALSE,
35        'buttons' => [],
36        'dialogClass' => 'ui-dialog-off-canvas ui-dialog-position-' . $position,
37        'width' => 300,
38        'drupalOffCanvasPosition' => $position,
39      ],
40      'effect' => 'fade',
41      'speed' => 1000,
42    ];
43    $this->assertEquals($expected, $command->render());
44  }
45
46  /**
47   * The data provider for potential dialog positions.
48   *
49   * @return array
50   */
51  public static function dialogPosition() {
52    return [
53      ['side'],
54      ['top'],
55    ];
56  }
57
58}
59