class QueryOptionsTest

Same name and namespace in other branches
  1. 11.x core/modules/views/tests/src/Functional/Plugin/QueryOptionsTest.php \Drupal\Tests\views\Functional\Plugin\QueryOptionsTest
  2. 10 core/modules/views/tests/src/Functional/Plugin/QueryOptionsTest.php \Drupal\Tests\views\Functional\Plugin\QueryOptionsTest

Tests setting the query options.

@group views

Hierarchy

Expanded class hierarchy of QueryOptionsTest

File

core/modules/views/tests/src/Functional/Plugin/QueryOptionsTest.php, line 12

Namespace

Drupal\Tests\views\Functional\Plugin
View source
class QueryOptionsTest extends ViewTestBase {
  
  /**
   * Views used by this test.
   *
   * @var array
   */
  public static $testViews = [
    'test_view',
  ];
  
  /**
   * Modules to enable.
   *
   * @var array
   */
  protected static $modules = [
    'node',
    'views_ui',
  ];
  
  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';
  
  /**
   * Test that query overrides are stored.
   */
  public function testStoreQuerySettingsOverride() {
    // Show the default display so the override selection is shown.
    \Drupal::configFactory()->getEditable('views.settings')
      ->set('ui.show.default_display', TRUE)
      ->save();
    $admin_user = $this->drupalCreateUser([
      'administer views',
      'administer site configuration',
    ]);
    $this->drupalLogin($admin_user);
    $edit = [];
    $this->drupalGet('admin/structure/views/view/test_view/edit');
    $this->submitForm($edit, 'Add Page');
    $this->drupalGet('admin/structure/views/nojs/display/test_view/page_1/query');
    $this->assertSession()
      ->checkboxNotChecked('query[options][distinct]');
    $edit = [
      'override[dropdown]' => 'page_1',
      'query[options][distinct]' => 1,
    ];
    $this->submitForm($edit, 'Apply');
    $this->drupalGet('admin/structure/views/nojs/display/test_view/page_1/query');
    $this->assertSession()
      ->checkboxChecked('query[options][distinct]');
    $edit = [
      'query[options][query_comment]' => 'comment',
      'query[options][query_tags]' => 'query_tag, another_tag',
    ];
    $this->submitForm($edit, 'Apply');
    $this->drupalGet('admin/structure/views/nojs/display/test_view/page_1/query');
    $this->assertSession()
      ->checkboxChecked('query[options][distinct]');
    $this->assertSession()
      ->fieldValueEquals('query[options][query_comment]', 'comment');
    $this->assertSession()
      ->fieldValueEquals('query[options][query_tags]', 'query_tag, another_tag');
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.