Skip to content
Snippets Groups Projects
Verified Commit 9c045ead authored by Lauri Timmanee's avatar Lauri Timmanee
Browse files

Issue #3100826 by ilya.no, mwilbur, nikita_tt, smustgrave, quietone: AJAX...

Issue #3100826 by ilya.no, mwilbur, nikita_tt, smustgrave, quietone: AJAX pager doesn't work with exposed filter which has a default value

(cherry picked from commit d251a98e)
parent 80b264b1
No related branches found
No related tags found
19 merge requests!11628Update file MediaLibraryWidget.php,!7564Revert "Issue #3364773 by roshnichordiya, Chris Matthews, thakurnishant_06,...,!5752Issue #3275828 by joachim, quietone, bradjones1, Berdir: document the reason...,!5627Issue #3261805: Field not saved when change of 0 on string start,!5427Issue #3338518: send credentials in ajax if configured in CORS settings.,!5395Issue #3387916 by fjgarlin, Spokje: Each GitLab job exposes user email,!5217Issue #3386607 by alexpott: Improve spell checking in commit-code-check.sh,!5064Issue #3379522 by finnsky, Gauravvvv, kostyashupenko, smustgrave, Chi: Revert...,!5040SDC ComponentElement: Transform slots scalar values to #plain_text instead of throwing an exception,!4958Issue #3392147: Whitelist IP for a Ban module.,!4894Issue #3280279: Add API to allow sites to opt in to upload SVG images in CKEditor 5,!4857Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!4856Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!4788Issue #3272985: RSS Feed header reverts to text/html when cached,!4716Issue #3362929: Improve 400 responses for broken/invalid image style routes,!3679Issue #115801: Allow password on registration without disabling e-mail verification,!3106Issue #3017548: "Filtered HTML" text format does not support manual teaser break (<!--break-->),!925Issue #2339235: Remove taxonomy hard dependency on node module,!872Draft: Issue #3221319: Race condition when creating menu links and editing content deletes menu links
......@@ -29,9 +29,13 @@
for (let i = 0; i < pairs.length; i++) {
pair = pairs[i].split('=');
// Ignore the 'q' path argument, if present.
if (pair[0] !== 'q' && pair[1]) {
args[decodeURIComponent(pair[0].replace(/\+/g, ' '))] =
decodeURIComponent(pair[1].replace(/\+/g, ' '));
if (pair[0] !== 'q') {
if (pair[1]) {
args[decodeURIComponent(pair[0].replace(/\+/g, ' '))] =
decodeURIComponent(pair[1].replace(/\+/g, ' '));
} else {
args[decodeURIComponent(pair[0].replace(/\+/g, ' '))] = '';
}
}
}
return args;
......
......@@ -46,7 +46,11 @@ protected function setUp(): void {
// Create a Content type and eleven test nodes.
$this->createContentType(['type' => 'page']);
for ($i = 1; $i <= 11; $i++) {
$this->createNode(['title' => 'Node ' . $i . ' content', 'changed' => $i * 1000]);
$fields = [
'title' => $i > 6 ? 'Node ' . $i . ' content' : 'Node ' . $i . ' content default_value',
'changed' => $i * 1000,
];
$this->createNode($fields);
}
// Create a user privileged enough to view content.
......@@ -90,18 +94,18 @@ public function testBasicPagination() {
/** @var \Behat\Mink\Element\NodeElement[] $rows */
$rows = $page->findAll('css', 'tbody tr');
$this->assertCount(5, $rows);
$this->assertStringContainsString('Node 1 content', $rows[0]->getHtml());
$this->assertStringContainsString('Node 1 content default_value', $rows[0]->getHtml());
$this->clickLink('Go to page 2');
$session_assert->assertWaitOnAjaxRequest();
$rows = $page->findAll('css', 'tbody tr');
$this->assertCount(5, $rows);
$this->assertStringContainsString('Node 6 content', $rows[0]->getHtml());
$this->assertStringContainsString('Node 6 content default_value', $rows[0]->getHtml());
$link = $page->findLink('Go to page 3');
$this->assertNoDuplicateAssetsOnPage();
// 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&page=2', $link->getAttribute('href'));
$this->assertEquals('?status=All&type=All&title=&langcode=All&items_per_page=5&order=changed&sort=asc&page=2', $link->getAttribute('href'));
$this->clickLink('Go to page 3');
$session_assert->assertWaitOnAjaxRequest();
......@@ -114,14 +118,14 @@ public function testBasicPagination() {
$session_assert->assertWaitOnAjaxRequest();
$rows = $page->findAll('css', 'tbody tr');
$this->assertCount(5, $rows);
$this->assertStringContainsString('Node 1 content', $rows[0]->getHtml());
$this->assertStringContainsString('Node 1 content default_value', $rows[0]->getHtml());
// Navigate using the 'next' link.
$this->clickLink('Go to next page');
$session_assert->assertWaitOnAjaxRequest();
$rows = $page->findAll('css', 'tbody tr');
$this->assertCount(5, $rows);
$this->assertStringContainsString('Node 6 content', $rows[0]->getHtml());
$this->assertStringContainsString('Node 6 content default_value', $rows[0]->getHtml());
// Navigate using the 'last' link.
$this->clickLink('Go to last page');
......@@ -135,6 +139,104 @@ public function testBasicPagination() {
$this->assertEquals($expected_view_path, current($settings['views']['ajaxViews'])['view_path']);
}
/**
* Tests if pagination via AJAX works for the filter with default value.
*/
public function testDefaultFilterPagination() {
// Add default value to the title filter.
$view = \Drupal::configFactory()->getEditable('views.view.test_content_ajax');
$display = $view->get('display');
$display['default']['display_options']['filters']['title']['value'] = 'default_value';
$view->set('display', $display);
$view->save();
// Visit the content page.
$this->drupalGet('test-content-ajax');
$session_assert = $this->assertSession();
$page = $this->getSession()->getPage();
$settings = $this->getDrupalSettings();
// Make sure that the view_path is set correctly.
$expected_view_path = '/test-content-ajax';
$this->assertEquals($expected_view_path, current($settings['views']['ajaxViews'])['view_path']);
// Set the number of items displayed per page to 5 using the exposed pager.
$page->selectFieldOption('edit-items-per-page', 5);
$page->pressButton('Filter');
$session_assert->assertWaitOnAjaxRequest();
// Change 'Updated' sorting from descending to ascending.
$page->clickLink('Updated');
$session_assert->assertWaitOnAjaxRequest();
// Use the pager by clicking on the links and test if we see the expected
// number of rows on each page. For easy targeting the titles of the pager
// links are used.
/** @var \Behat\Mink\Element\NodeElement[] $rows */
$rows = $page->findAll('css', 'tbody tr');
$this->assertCount(5, $rows);
$this->assertStringContainsString('Node 1 content default_value', $rows[0]->getHtml());
$this->clickLink('Go to page 2');
$session_assert->assertWaitOnAjaxRequest();
$rows = $page->findAll('css', 'tbody tr');
$this->assertCount(1, $rows);
$this->assertStringContainsString('Node 6 content default_value', $rows[0]->getHtml());
$link = $page->findLink('Go to page 1');
$this->assertNoDuplicateAssetsOnPage();
// Test that no unwanted parameters are added to the URL.
$this->assertEquals('?status=All&type=All&title=default_value&langcode=All&items_per_page=5&order=changed&sort=asc&page=0', $link->getAttribute('href'));
// Set the title filter to empty string using the exposed pager.
$page->fillField('title', '');
$page->pressButton('Filter');
$session_assert->assertWaitOnAjaxRequest();
$rows = $page->findAll('css', 'tbody tr');
$this->assertCount(5, $rows);
$this->assertStringContainsString('Node 11 content', $rows[0]->getHtml());
// Navigate to the second page.
$this->clickLink('Go to page 2');
$session_assert->assertWaitOnAjaxRequest();
$rows = $page->findAll('css', 'tbody tr');
$this->assertCount(5, $rows);
$this->assertStringContainsString('Node 6 content default_value', $rows[0]->getHtml());
$link = $page->findLink('Go to page 1');
$this->assertNoDuplicateAssetsOnPage();
// Test that no unwanted parameters are added to the URL.
$this->assertEquals('?status=All&type=All&title=&langcode=All&items_per_page=5&page=0', $link->getAttribute('href'));
// Navigate back to the first page.
$this->clickLink('Go to first page');
$session_assert->assertWaitOnAjaxRequest();
$rows = $page->findAll('css', 'tbody tr');
$this->assertCount(5, $rows);
$this->assertStringContainsString('Node 11 content', $rows[0]->getHtml());
// Navigate using the 'next' link.
$this->clickLink('Go to next page');
$session_assert->assertWaitOnAjaxRequest();
$rows = $page->findAll('css', 'tbody tr');
$this->assertCount(5, $rows);
$this->assertStringContainsString('Node 6 content default_value', $rows[0]->getHtml());
// Navigate using the 'last' link.
$this->clickLink('Go to last page');
$session_assert->assertWaitOnAjaxRequest();
$rows = $page->findAll('css', 'tbody tr');
$this->assertCount(1, $rows);
$this->assertStringContainsString('Node 1 content default_value', $rows[0]->getHtml());
// Make sure the AJAX calls don't change the view_path.
$settings = $this->getDrupalSettings();
$this->assertEquals($expected_view_path, current($settings['views']['ajaxViews'])['view_path']);
}
/**
* Assert that assets are not loaded twice on a page.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment