class QueryOptionsTest in Drupal 10
Tests setting the query options.
@group views
Hierarchy
- class \Drupal\Tests\views\Functional\Plugin\QueryOptionsTest extends \Drupal\Tests\views\Functional\ViewTestBase
 
Expanded class hierarchy of QueryOptionsTest
File
- core/
modules/ views/ tests/ src/ Functional/ Plugin/ QueryOptionsTest.php, line 12  
Namespace
Drupal\Tests\views\Functional\PluginView 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');
  }
}