Verified Commit 9041793c authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2865401 by Berdir, yassin.barrani, ankithashetty, dxvargas,...

Issue #2865401 by Berdir, yassin.barrani, ankithashetty, dxvargas, Hardik_Patel_12, ayushmishra206: Views pager is using exposed_raw_input instead of exposed_input

(cherry picked from commit a487817d)
parent dce8ca65
Loading
Loading
Loading
Loading
+51 −0
Original line number Diff line number Diff line
@@ -198,4 +198,55 @@ protected function assertIds(array $expected_ids = []): void {
    $this->assertEquals($expected_ids, $actual_ids);
  }

  /**
   * Tests exposed date filters with a pager.
   */
  public function testExposedFilterWithPager() {
    // Expose the empty and not empty operators in a grouped filter.
    $this->drupalGet('admin/structure/views/nojs/handler/test_filter_datetime/default/filter/' . $this->fieldName . '_value');
    $this->submitForm([], t('Expose filter'));

    $edit = [];
    $edit['options[operator]'] = '>';

    $this->submitForm($edit, 'Apply');

    // Expose the view and set the pager to 2 items.
    $path = 'test_filter_datetime-path';
    $this->drupalGet('admin/structure/views/view/test_filter_datetime/edit');
    $this->submitForm([], 'Add Page');
    $this->drupalGet('admin/structure/views/nojs/display/test_filter_datetime/page_1/path');
    $this->submitForm(['path' => $path], 'Apply');
    $this->drupalGet('admin/structure/views/nojs/display/test_filter_datetime/default/pager_options');
    $this->submitForm(['pager_options[items_per_page]' => 2], 'Apply');
    $this->submitForm([], t('Save'));

    // Assert the page without filters.
    $this->drupalGet($path);
    $results = $this->cssSelect('.views-row');
    $this->assertCount(2, $results);
    $this->assertSession()->pageTextContains('Next');

    // Assert the page with filter in the future, one results without pager.
    $page = $this->getSession()->getPage();
    $now = \Drupal::time()->getRequestTime();
    $page->fillField($this->fieldName . '_value', DrupalDateTime::createFromTimestamp($now + 1)->format('Y-m-d H:i:s'));
    $page->pressButton('Apply');

    $results = $this->cssSelect('.views-row');
    $this->assertCount(1, $results);
    $this->assertSession()->pageTextNotContains('Next');

    // Assert the page with filter in the past, 3 results with pager.
    $page->fillField($this->fieldName . '_value', DrupalDateTime::createFromTimestamp($now - 1000000)->format('Y-m-d H:i:s'));
    $this->getSession()->getPage()->pressButton('Apply');
    $results = $this->cssSelect('.views-row');
    $this->assertCount(2, $results);
    $this->assertSession()->pageTextContains('Next');
    $page->clickLink('2');
    $results = $this->cssSelect('.views-row');
    $this->assertCount(1, $results);

  }

}
+1 −1
Original line number Diff line number Diff line
@@ -2241,7 +2241,7 @@ public function elementPreRender(array $element) {
    $element['#feed_icons'] = !empty($view->feedIcons) ? $view->feedIcons : [];

    if ($view->display_handler->renderPager()) {
      $exposed_input = $view->exposed_raw_input ?? NULL;
      $exposed_input = $view->getExposedInput();
      $element['#pager'] = $view->renderPager($exposed_input);
    }

+1 −1
Original line number Diff line number Diff line
@@ -99,7 +99,7 @@ public function testBasicPagination() {
    $this->assertStringContainsString('Node 6 content', $rows[0]->getHtml());
    $link = $page->findLink('Go to page 3');
    // Test that no unwanted parameters are added to the URL.
    $this->assertEquals('?status=All&type=All&langcode=All&items_per_page=5&order=changed&sort=asc&title=&page=2', $link->getAttribute('href'));
    $this->assertEquals('?status=All&type=All&langcode=All&items_per_page=5&order=changed&sort=asc&page=2', $link->getAttribute('href'));
    $this->assertNoDuplicateAssetsOnPage();

    $this->clickLink('Go to page 3');