From 55701908fe135247e95b9c010eadc5bd323226fa Mon Sep 17 00:00:00 2001 From: Demian Katz Date: Thu, 30 Jan 2025 13:28:14 -0500 Subject: [PATCH 1/3] Add tests to cover bottom button functionality. --- .../src/VuFindTest/Mink/BulkTest.php | 62 +++++++++++++++---- 1 file changed, 51 insertions(+), 11 deletions(-) diff --git a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/BulkTest.php b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/BulkTest.php index 5201394dbef..2ae568a4a81 100644 --- a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/BulkTest.php +++ b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/BulkTest.php @@ -279,27 +279,54 @@ public function testBulkDeleteFromList(): void $this->unfindCss($page, 'button[name="delete"]'); } + /** + * Data provider to allow testing of top or bottom controls. + * + * @return array[] + */ + public static function topOrBottomProvider(): array + { + return [ + 'top button' => [''], + 'bottom button' => ['bottom_'], + ]; + } + /** * Test that the export control works. * + * @param string $idPrefix Prefix for bulk control IDs. + * * @return void + * + * @dataProvider topOrBottomProvider */ - public function testBulkExport(): void + public function testBulkExport(string $idPrefix): void { + $session = $this->getMinkSession(); $page = $this->setUpGenericBulkTest(); - $button = $this->findCss($page, '#ribbon-export'); + $buttonSelector = '#' . $idPrefix . 'ribbon-export'; // First try clicking without selecting anything: - $button->click(); + $this->clickCss($page, $buttonSelector); $this->checkForNonSelectedMessage($page); $this->closeLightbox($page, true); // Now do it for real -- we should get a lightbox prompt. - $page->find('css', '#addFormCheckboxSelectAll')->check(); - $button->click(); + $page->find('css', '#' . $idPrefix . 'addFormCheckboxSelectAll')->check(); + $this->waitStatement('$("input.checkbox-select-item:checked").length === 2'); + $this->clickCss($page, $buttonSelector); // Select EndNote option - $select = $this->findCss($page, '#format'); + try { + $select = $this->findCss($page, '#format', 100); + } catch (\Exception $e) { + // For some reason, the click action does not always succeed here; fall + // back to brute force Javascript to prevent intermittent test failures. + echo "\n\nMink click failed; retrying with Javascript!\n"; + $session->evaluateScript('$("' . $buttonSelector . '").click()'); + $select = $this->findCss($page, '#format'); + } $select->selectOption('EndNote'); // Do the export: @@ -312,22 +339,35 @@ public function testBulkExport(): void /** * Test that the print control works. * + * @param string $idPrefix Prefix for bulk control IDs. + * * @return void + * + * @dataProvider topOrBottomProvider */ - public function testBulkPrint(): void + public function testBulkPrint(string $idPrefix): void { $session = $this->getMinkSession(); $page = $this->setUpGenericBulkTest(); - $button = $this->findCss($page, '#ribbon-print'); + $buttonSelector = '#' . $idPrefix . 'ribbon-print'; // First try clicking without selecting anything: - $button->click(); + $this->clickCss($page, $buttonSelector); $this->checkForNonSelectedMessage($page); $page->find('css', '.modal-body .btn')->click(); // Now do it for real -- we should get redirected. - $page->find('css', '#addFormCheckboxSelectAll')->check(); - $button->click(); + $page->find('css', '#' . $idPrefix . 'addFormCheckboxSelectAll')->check(); + $this->waitStatement('$("input.checkbox-select-item:checked").length === 2'); + $this->clickCss($page, $buttonSelector); + [, $params] = explode('?', $session->getCurrentUrl()); + // For some reason, the click action does not always succeed here; fall + // back to brute force Javascript to prevent intermittent test failures. + if (str_starts_with($params, 'lookfor')) { + echo "\n\nMink click failed; retrying with Javascript!\n"; + $session->evaluateScript('$("' . $buttonSelector . '").click()'); + [, $params] = explode('?', $session->getCurrentUrl()); + } [, $params] = explode('?', $session->getCurrentUrl()); $this->assertEquals( 'print=true&id[]=Solr|testsample1&id[]=Solr|testsample2', From 1aa0892b5980bf1fcc1ec8a8a92981fff6131d6b Mon Sep 17 00:00:00 2001 From: Demian Katz Date: Fri, 31 Jan 2025 10:31:16 -0500 Subject: [PATCH 2/3] Different hack. --- .../src/VuFindTest/Mink/BulkTest.php | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/BulkTest.php b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/BulkTest.php index 2ae568a4a81..bd4cfe37300 100644 --- a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/BulkTest.php +++ b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/BulkTest.php @@ -321,10 +321,12 @@ public function testBulkExport(string $idPrefix): void try { $select = $this->findCss($page, '#format', 100); } catch (\Exception $e) { - // For some reason, the click action does not always succeed here; fall - // back to brute force Javascript to prevent intermittent test failures. - echo "\n\nMink click failed; retrying with Javascript!\n"; - $session->evaluateScript('$("' . $buttonSelector . '").click()'); + // For some reason, the click action does not always succeed here; resizing + // the window and retrying seems to prevent intermittent test failures. + echo "\n\nMink click failed; retrying with resized window!\n"; + $session->resizeWindow(1280, 200, 'current'); + $this->clickCss($page, $buttonSelector); + $session->resizeWindow(1280, 768, 'current'); $select = $this->findCss($page, '#format'); } $select->selectOption('EndNote'); @@ -361,11 +363,13 @@ public function testBulkPrint(string $idPrefix): void $this->waitStatement('$("input.checkbox-select-item:checked").length === 2'); $this->clickCss($page, $buttonSelector); [, $params] = explode('?', $session->getCurrentUrl()); - // For some reason, the click action does not always succeed here; fall - // back to brute force Javascript to prevent intermittent test failures. + // For some reason, the click action does not always succeed here; resizing + // the window and retrying seems to prevent intermittent test failures. if (str_starts_with($params, 'lookfor')) { - echo "\n\nMink click failed; retrying with Javascript!\n"; - $session->evaluateScript('$("' . $buttonSelector . '").click()'); + echo "\n\nMink click failed; retrying with resized window!\n"; + $session->resizeWindow(1280, 200, 'current'); + $this->clickCss($page, $buttonSelector); + $session->resizeWindow(1280, 768, 'current'); [, $params] = explode('?', $session->getCurrentUrl()); } [, $params] = explode('?', $session->getCurrentUrl()); From 275856fc17348ba6507b6b76d5dfdc33fbce34a9 Mon Sep 17 00:00:00 2001 From: Demian Katz Date: Thu, 13 Feb 2025 12:58:17 -0500 Subject: [PATCH 3/3] Review feedback. --- .../src/VuFindTest/Mink/BulkTest.php | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/BulkTest.php b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/BulkTest.php index bd4cfe37300..0ff3f15b726 100644 --- a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/BulkTest.php +++ b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/BulkTest.php @@ -30,6 +30,7 @@ namespace VuFindTest\Mink; use Behat\Mink\Element\Element; +use Behat\Mink\Session; /** * Mink bulk action test class. @@ -292,6 +293,25 @@ public static function topOrBottomProvider(): array ]; } + /** + * After a failed button click has been detected, resize the window and try again. + * + * @param Session $session Mink session + * @param Element $page Current page element + * @param string $selector Selector to click + * + * @return void + */ + protected function retryClickWithResizedWindow(Session $session, Element $page, string $selector): void + { + // For some reason, the click action does not always succeed here; resizing + // the window and retrying seems to prevent intermittent test failures. + echo "\n\nMink click failed; retrying with resized window!\n"; + $session->resizeWindow(1280, 200, 'current'); + $this->clickCss($page, $selector); + $session->resizeWindow(1280, 768, 'current'); + } + /** * Test that the export control works. * @@ -321,12 +341,7 @@ public function testBulkExport(string $idPrefix): void try { $select = $this->findCss($page, '#format', 100); } catch (\Exception $e) { - // For some reason, the click action does not always succeed here; resizing - // the window and retrying seems to prevent intermittent test failures. - echo "\n\nMink click failed; retrying with resized window!\n"; - $session->resizeWindow(1280, 200, 'current'); - $this->clickCss($page, $buttonSelector); - $session->resizeWindow(1280, 768, 'current'); + $this->retryClickWithResizedWindow($session, $page, $buttonSelector); $select = $this->findCss($page, '#format'); } $select->selectOption('EndNote'); @@ -363,16 +378,10 @@ public function testBulkPrint(string $idPrefix): void $this->waitStatement('$("input.checkbox-select-item:checked").length === 2'); $this->clickCss($page, $buttonSelector); [, $params] = explode('?', $session->getCurrentUrl()); - // For some reason, the click action does not always succeed here; resizing - // the window and retrying seems to prevent intermittent test failures. if (str_starts_with($params, 'lookfor')) { - echo "\n\nMink click failed; retrying with resized window!\n"; - $session->resizeWindow(1280, 200, 'current'); - $this->clickCss($page, $buttonSelector); - $session->resizeWindow(1280, 768, 'current'); + $this->retryClickWithResizedWindow($session, $page, $buttonSelector); [, $params] = explode('?', $session->getCurrentUrl()); } - [, $params] = explode('?', $session->getCurrentUrl()); $this->assertEquals( 'print=true&id[]=Solr|testsample1&id[]=Solr|testsample2', str_replace(['%5B', '%5D', '%7C'], ['[', ']', '|'], $params)