Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into phpunit10
Browse files Browse the repository at this point in the history
  • Loading branch information
demiankatz committed Jan 26, 2024
2 parents cb54636 + 0272b26 commit 8ee7310
Show file tree
Hide file tree
Showing 27 changed files with 152 additions and 121 deletions.
2 changes: 1 addition & 1 deletion module/VuFind/src/VuFindTest/Feature/AutoRetryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function runBare(): void
if (is_callable($logMethod)) {
$method = get_class($this) . '::' . $this->getName(false);
$msg = "RETRY TEST $method ({$this->retriesLeft} left)"
. ' after exception: ' . $e->getMessage() . '.';
. ' after exception: ' . (string)$e . '.';
call_user_func(
$logMethod,
$msg . ' See PHP error log for details.',
Expand Down
4 changes: 2 additions & 2 deletions module/VuFind/src/VuFindTest/Feature/DemoDriverTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ protected function submitCatalogLoginForm(
string $username,
string $password
): void {
$this->findCss($page, '#profile_cat_username')->setValue($username);
$this->findCss($page, '#profile_cat_password')->setValue($password);
$this->findCssAndSetValue($page, '#profile_cat_username', $username);
$this->findCssAndSetValue($page, '#profile_cat_password', $password);
$this->clickCss($page, 'input.btn.btn-primary');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected function expectConsecutiveCalls(
$matcher = $this->exactly(count($expectedCalls));
$callback = function () use ($matcher, $expectedCalls, $returnValues) {
$index = $matcher->numberOfInvocations() - 1;
$expectedArgs = $expectedCalls[$index];
$expectedArgs = $expectedCalls[$index] ?? [];
$actualArgs = func_get_args();
foreach ($expectedArgs as $i => $expected) {
if ($expected instanceof Constraint) {
Expand Down
72 changes: 43 additions & 29 deletions module/VuFind/src/VuFindTest/Integration/MinkTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -516,11 +516,12 @@ protected function clickCss(
* Set a value within an element selected via CSS; retry if set fails
* due to browser bugs.
*
* @param Element $page Page element
* @param string $selector CSS selector
* @param string $value Value to set
* @param int $timeout Wait timeout for CSS selection (in ms)
* @param int $retries Retry count for set loop
* @param Element $page Page element
* @param string $selector CSS selector
* @param string $value Value to set
* @param int $timeout Wait timeout for CSS selection (in ms)
* @param int $retries Retry count for set loop
* @param bool $verifyValue Whether to verify that the value was written
*
* @return mixed
*/
Expand All @@ -529,33 +530,35 @@ protected function findCssAndSetValue(
$selector,
$value,
$timeout = null,
$retries = 6
$retries = 6,
$verifyValue = true
) {
$timeout ??= $this->getDefaultTimeout();
$field = $this->findCss($page, $selector, $timeout, 0);

$session = $this->getMinkSession();
$session->wait(
$timeout,
"typeof $ !== 'undefined' && $('$selector:focusable').length > 0"
);
$results = $page->findAll('css', $selector);
$this->assertIsArray($results, "Selector not found: $selector");
$field = $results[0];

// Workaround for Chromedriver bug; sometimes setting a value
// doesn't work on the first try.
for ($i = 1; $i <= $retries; $i++) {
$field->setValue($value);
try {
$field = $this->findCss($page, $selector, $timeout, 0);
$field->setValue($value);
if (!$verifyValue) {
return;
}

// Did it work? If so, we're done and can leave....
if ($field->getValue() === $value) {
return;
// Did it work? If so, we're done and can leave....
if ($field->getValue() === $value) {
return;
}
$this->logWarning(
'RETRY setValue after failure in ' . $this->getTestName()
. " (try $i)."
);
} catch (\Exception $e) {
$this->logWarning(
'RETRY setValue after exception in ' . $this->getTestName()
. " (try $i): " . (string)$e
);
}
$this->logWarning(
'RETRY setValue after failure in ' . $this->getTestName()
. " (try $i)."
);

$this->snooze();
}
Expand Down Expand Up @@ -618,13 +621,24 @@ protected function assertWithTimeout(
$timeout ??= $this->getDefaultTimeout();
$result = null;
$startTime = microtime(true);
$exception = null;
while ((microtime(true) - $startTime) * 1000 <= $timeout) {
$result = $callback();
if (call_user_func($compareFunc, $expected, $result)) {
break;
try {
$result = $callback();
if (call_user_func($compareFunc, $expected, $result)) {
// Ignore any previous exception since the callback succeeded eventually:
$exception = null;
break;
}
} catch (\Exception $e) {
// Defer throwing the exception:
$exception = $e;
}
usleep(100000);
}
if ($exception) {
throw $exception;
}
call_user_func($assertion, $expected, $result);
}

Expand Down Expand Up @@ -692,9 +706,9 @@ protected function performSearch($query, $handler = null, $path = '/Search')
$session = $this->getMinkSession();
$session->visit($this->getVuFindUrl() . $path);
$page = $session->getPage();
$this->findCss($page, '#searchForm_lookfor')->setValue($query);
$this->findCssAndSetValue($page, '#searchForm_lookfor', $query);
if ($handler) {
$this->findCss($page, '#searchForm_type')->setValue($handler);
$this->findCssAndSetValue($page, '#searchForm_type', $handler);
}
$this->clickCss($page, '.btn.btn-primary');
$this->waitForPageLoad($page);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ public function testDefaultPickUpLocation(): void
);

// Change the default and verify:
$this->findCss($page, '#home_library')->setValue('B');
$this->findCssAndSetValue($page, '#home_library', 'B');
$this->clickCss($page, '#profile_form .btn');
$this->waitForPageLoad($page);
$this->assertEquals('B', $this->findCss($page, '#home_library')->getValue());
Expand All @@ -365,7 +365,7 @@ public function testDefaultPickUpLocation(): void
);

// Change to "Always ask me":
$this->findCss($page, '#home_library')->setValue(' ** ');
$this->findCssAndSetValue($page, '#home_library', ' ** ');
$this->clickCss($page, '#profile_form .btn');
$this->waitForPageLoad($page);
$this->assertEquals(
Expand All @@ -375,7 +375,7 @@ public function testDefaultPickUpLocation(): void
$this->assertNull($userTable->getByUsername('username2')->home_library);

// Back to default:
$this->findCss($page, '#home_library')->setValue('');
$this->findCssAndSetValue($page, '#home_library', '');
$this->clickCss($page, '#profile_form .btn');
$this->waitForPageLoad($page);
$this->assertEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,13 @@ public function testAdvancedSearchForm()
$this->findCss($page, '#search1_0 .adv-term-remove:not(.hidden)');

// Enter search for bride of the tomb
$this->findCss($page, '#search_lookfor0_0')->setValue('bride');
$this->findCss($page, '#search_lookfor0_1')->setValue('tomb');
$this->findCssAndSetValue($page, '#search_lookfor0_0', 'bride');
$this->findCssAndSetValue($page, '#search_lookfor0_1', 'tomb');
$this->findCss($page, '#search_type0_1')->selectOption('Title');
$this->findCss($page, '#search_lookfor0_2')->setValue('garbage');
$this->findCss($page, '#search_lookfor0_3')->setValue('1883');
$this->findCssAndSetValue($page, '#search_lookfor0_2', 'garbage');
$this->findCssAndSetValue($page, '#search_lookfor0_3', '1883');
$this->findCss($page, '#search_type0_3')->selectOption('year');
$this->findCss($page, '#search_lookfor1_0')->setValue('miller');
$this->findCssAndSetValue($page, '#search_lookfor1_0', 'miller');

// Submit search form
$this->findCss($page, '[type=submit]')->press();
Expand Down Expand Up @@ -217,9 +217,9 @@ public function testAdvancedMultiGroupSearchWithNotOperator()
$this->findCss($page, '#group1');

// Enter search criteria
$this->findCss($page, '#search_lookfor0_0')->setValue('building:"journals.mrc"');
$this->findCssAndSetValue($page, '#search_lookfor0_0', 'building:"journals.mrc"');
$this->findCss($page, '#search_type1_0')->selectOption('Title');
$this->findCss($page, '#search_lookfor1_0')->setValue('rational');
$this->findCssAndSetValue($page, '#search_lookfor1_0', 'rational');
$this->findCss($page, '#search_bool1')->selectOption('NOT');

// Submit search form
Expand Down Expand Up @@ -248,7 +248,7 @@ public function testAdvancedSingleGroupSearchWithNotOperator()

// Enter search criteria
$this->findCss($page, '#search_type0_0')->selectOption('Title');
$this->findCss($page, '#search_lookfor0_0')->setValue('rational');
$this->findCssAndSetValue($page, '#search_lookfor0_0', 'rational');
$this->findCss($page, '#search_bool0')->selectOption('NOT');

// Submit search form
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected function makeRecordApiCall($id = 'testbug2'): Element
$page = $session->getPage();
$this->clickCss($page, '#operations-Record-get_record button');
$this->clickCss($page, '#operations-Record-get_record .try-out button');
$this->findCss($page, '#operations-Record-get_record input[type="text"]')->setValue($id);
$this->findCssAndSetValue($page, '#operations-Record-get_record input[type="text"]', $id);
$this->clickCss($page, '#operations-Record-get_record .execute-wrapper button');
return $page;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected function setupPage($extraConfigs = [])
protected function fillInAndSubmitFeedbackForm($page)
{
$this->clickCss($page, '#feedbackLink');
$this->findCss($page, '#modal .form-control[name="name"]')->setValue('Me');
$this->findCssAndSetValue($page, '#modal .form-control[name="name"]', 'Me');
$this->findCss($page, '#modal .form-control[name="email"]')
->setValue('test@test.com');
$this->findCss($page, '#modal #form_FeedbackSite_message')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ protected function placeHold(
// Add extra form field values:
$this->waitForPageLoad($page);
foreach ($extras as $selector => $value) {
$this->findCss($page, $selector)->setValue($value);
$this->findCssAndSetValue($page, $selector, $value);
}
$this->clickCss($page, '.modal-body .btn.btn-primary');
}
Expand Down Expand Up @@ -597,8 +597,8 @@ public function testFrozenHoldEditing(): void
$this->clickCss($page, '.hold-edit');

// Release the hold and change the pickup location
$this->findCss($page, '#frozen')->setValue('0');
$this->findCss($page, '#pickup_location')->setValue('A');
$this->findCssAndSetValue($page, '#frozen', '0');
$this->findCssAndSetValue($page, '#pickup_location', 'A');
$this->findCss($page, '#modal .btn.btn-primary')->click();

// Confirm that the values have changed
Expand Down Expand Up @@ -652,7 +652,7 @@ public function testEditingDifferentPickupLocations()

// Change the first hold to location C so it matches the second one:
$this->clickCss($page, '.hold-edit');
$this->findCss($page, '#pickup_location')->setValue('C');
$this->findCssAndSetValue($page, '#pickup_location', 'C');
$this->findCss($page, '#modal .btn.btn-primary')->click();

// Locations should now match:
Expand All @@ -669,7 +669,7 @@ public function testEditingDifferentPickupLocations()
$this->clickCss($page, '.checkbox-select-item', 1000, 0);
$this->clickCss($page, '.checkbox-select-item', 1000, 2);
$this->clickCss($page, '#update_selected');
$this->findCss($page, '#pickup_location')->setValue('C');
$this->findCssAndSetValue($page, '#pickup_location', 'C');
$this->findCss($page, '#modal .btn.btn-primary')->click();

// Confirm that it worked:
Expand Down Expand Up @@ -703,8 +703,8 @@ public function testFrozenHoldEditingWithCancellation(): void

// Revise the freeze date:
$futureDate = date('m-d-Y', strtotime('+3 days'));
$this->findCss($page, '#frozen')->setValue('1');
$this->findCss($page, '#frozen_through')->setValue($futureDate);
$this->findCssAndSetValue($page, '#frozen', '1');
$this->findCssAndSetValue($page, '#frozen_through', $futureDate);
$this->findCss($page, '#modal .btn.btn-primary')->click();

// Confirm that the values have changed
Expand Down Expand Up @@ -771,7 +771,7 @@ public function testHoldsAll(): void
// Set pickup location to a non-default value so we can confirm that
// the element is being passed through correctly, then submit form:
$this->waitForPageLoad($page);
$this->findCss($page, '#pickUpLocation')->setValue('B');
$this->findCssAndSetValue($page, '#pickUpLocation', 'B');
$this->clickCss($page, '.modal-body .btn.btn-primary');

// If successful, we should now have a link to review the hold:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ protected function placeIllRequestAndGoToIllScreen(Element $page): void

// Set pickup location to a non-default value so we can confirm that
// the element is being passed through correctly, then submit form:
$this->findCss($page, '#pickupLibrary')->setValue('2');
$this->findCssAndSetValue($page, '#pickupLibrary', '2');
$this->waitForPageLoad($page);
$this->findCss($page, '#pickupLibraryLocation')->setValue('3');
$this->findCssAndSetValue($page, '#pickupLibraryLocation', '3');
$this->clickCss($page, '.modal-body .btn.btn-primary');

// If successful, we should now have a link to review the request:
Expand Down Expand Up @@ -143,7 +143,7 @@ protected function placeStorageRetrievalRequestAndGoToSRRScreen(

// Set pickup location to a non-default value so we can confirm that
// the element is being passed through correctly, then submit form:
$this->findCss($page, '.modal-body select')->setValue('C');
$this->findCssAndSetValue($page, '.modal-body select', 'C');
$this->clickCss($page, '.modal-body .btn.btn-primary');

// If successful, we should now have a link to review the request:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ public function testSwitchingCards(): void
$this->findCss($page, '.catalog-profile tr:nth-child(1) td:nth-child(2)')->getText()
);

// Switch to the second card; we can't currently use findCssAndSetValue() here because
// it conflicts with the behavior of jumpMenu.
$this->findCss($page, '#library_card')->setValue($card2Value);
// Switch to the second card; don't try to verify the set value because it
// conflicts with the behavior of jumpMenu.
$this->findCssAndSetValue($page, '#library_card', $card2Value, null, 6, false);
$this->waitForPageLoad($page);

// Check that the appropriate username is reflected in the output:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ public function testFavoritesInAccordionMode()
$this->submitLoginForm($page);
// Make list
$this->clickCss($page, '#make-list');
$this->findCss($page, '#list_title')->setValue('Test List');
$this->findCss($page, '#list_desc')->setValue('Just. THE BEST.');
$this->findCssAndSetValue($page, '#list_title', 'Test List');
$this->findCssAndSetValue($page, '#list_desc', 'Just. THE BEST.');
$this->clickCss($page, '.modal-body .btn.btn-primary');
// Save to list
$this->clickCss($page, '.modal-body .btn.btn-primary');
Expand Down
Loading

0 comments on commit 8ee7310

Please sign in to comment.