UnsavedPreviewTest.php 2.02 KB
Newer Older
1 2
<?php

3
namespace Drupal\Tests\views_ui\Functional;
4 5 6 7 8 9

/**
 * Tests covering Preview of unsaved Views.
 *
 * @group views_ui
 */
10
class UnsavedPreviewTest extends UITestBase {
11 12

  /**
13 14 15 16
   * Views used by this test.
   *
   * @var array
   */
17 18
  public static $testViews = ['content'];

19 20 21 22 23
  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';

24 25 26 27 28 29 30 31 32 33
  /**
   * An admin user with the 'administer views' permission.
   *
   * @var \Drupal\user\UserInterface
   */
  protected $adminUser;

  /**
   * {@inheritdoc}
   */
34
  protected static $modules = ['node', 'views_ui'];
35 36 37 38

  /**
   * Sets up a Drupal site for running functional and integration tests.
   */
39
  protected function setUp($import_test_views = TRUE): void {
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
    parent::setUp(FALSE);

    $this->adminUser = $this->drupalCreateUser(['administer views']);
    $this->drupalLogin($this->adminUser);
  }

  /**
   * Tests previews of unsaved new page displays.
   */
  public function testUnsavedPageDisplayPreview() {
    $this->drupalCreateContentType(['type' => 'page']);
    for ($i = 0; $i < 5; $i++) {
      $this->drupalCreateNode();
    }

    $this->drupalGet('admin/structure/views/view/content');
56
    $this->assertSession()->statusCodeEquals(200);
57

58
    $this->submitForm([], 'Add Page');
59
    $this->assertSession()->statusCodeEquals(200);
60 61

    $this->drupalGet('admin/structure/views/nojs/display/content/page_2/path');
62
    $this->assertSession()->statusCodeEquals(200);
63

64
    $this->submitForm(['path' => 'foobarbaz'], 'Apply');
65
    $this->assertSession()->statusCodeEquals(200);
66

67
    $this->submitForm([], 'Update preview');
68
    $this->assertSession()->statusCodeEquals(200);
69
    $this->assertText('This display has no path');
70 71

    $this->drupalGet('admin/structure/views/view/content/edit/page_2');
72
    $this->assertSession()->statusCodeEquals(200);
73

74
    $this->submitForm([], 'Save');
75
    $this->assertSession()->statusCodeEquals(200);
76

77
    $this->submitForm([], 'Update preview');
78
    $this->assertSession()->statusCodeEquals(200);
79
    $this->assertSession()->linkByHrefExists('foobarbaz');
80 81 82
  }

}