Commit Graph

8632 Commits

Author SHA1 Message Date
Baptiste Wojtkowski 4fd0ba028c
Bug 41330: Unit tests
Do not apply patches before
1 - Create a new subscription to a serial
2 - Go to 'Serial Collection' panel and click on edit serials button
3 - Try and edit the serial number to "{1}" -> error 500
4 - Apply only unit tests patch and run `prove t/Serials/ModSerialStatus.t` -> Tests will
  not pass
5 - Apply patch and proceed again to 2&3 -> you will get no error
6 - run `prove t/Serials/ModSerialStatus.t` -> tests will pass

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-03-09 17:06:49 -06:00
Martin Renvoize 4ce8081f07
Bug 29923: Prevent overpayment credit when written-off accruing fine is adjusted on check-in
When a staff member writes off an accruing fine and the item is
subsequently checked in (backdated or in fine-free mode), the fine
amount is recalculated downward via adjust(). The previous code
unconditionally created an OVERPAYMENT credit whenever the adjusted
outstanding went negative, regardless of whether the existing credits
were reversible payments or non-reversible writeoffs/discounts.

This caused patrons to receive an erroneous credit equal to the
written-off amount, since writeoffs should simply be absorbed when
the underlying fine shrinks - no refund is due.

The fix calculates the total non-reversible credits (writeoffs,
discounts, cancellations) applied to the debit using the existing
filter_by_non_reversible method, and only generates an OVERPAYMENT
credit for the portion attributable to reversible cash payments that
exceed the recalculated fine amount.

Test plan:
1. Write off an accruing fine in full
2. Check the item in (backdated or fine-free)
3. Confirm no overpayment credit is generated for the patron

Signed-off-by: Benjamin Daeuber <BDaeuber@fargolibrary.org>
Signed-off-by: Andrew Fuerste Henry <andrew@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-03-09 17:06:47 -06:00
Baptiste Wojtkowski 233e02fc1c
Bug 39725: Remove GetSuggestionByStatus from C4/Suggestions.pm
Signed-off-by: Owen Leonard <oleonard@myacpl.org>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-03-05 08:34:05 -07:00
Baptiste Wojtkowski e4f14b3b1d
Bug 39724: Remove GetSuggestionInfo from C4/Suggestions.pm
Signed-off-by: Owen Leonard <oleonard@myacpl.org>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-03-05 08:34:04 -07:00
Baptiste Wojtkowski df21bc24eb
Bug 39723: Remove GetSuggestionInfoFromBiblionumber from C4/Suggestions.pm
To test:
 Create, edit and receive a command from a suggestion (the lonely call
of modReceiveOrder is at the receipt in acqui/finishreceive.pl)
Run `prove prove t/db_dependent/Acquisition.t`
Run `prove prove t/db_dependent/Suggestions.t`

Signed-off-by: Owen Leonard <oleonard@myacpl.org>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-03-05 08:34:03 -07:00
Nick Clemens 39ce85bf84
Bug 23260: Unit tests
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Peter Moore <peter@mrcpl.org>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-03-05 08:33:45 -07:00
Kyle M Hall 3487b56e20
Bug 36542: Update unit test
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-03-05 08:33:41 -07:00
phette23 5940fb39d5
Bug 40105: Patrons cannot add notes when creating an ILL
Testing plan:
- Enable the ILLModule system preference
- Sign into the OPAC and make an ILL request at /cgi-bin/koha/opac-illrequests.pl
- Note there's no option to specify notes
- Apply the patch and restart services
- Make another ILL request
- Use the new notes field
- View the request and note that the notes value was saved

Sponsored-By: California College of the Arts
Signed-off-by: Brendan Lawlor <blawlor@clamsnet.org>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
Signed-off-by: Lisette Scheer <lisette@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-03-05 08:33:32 -07:00
Martin Renvoize 300f121b66
Bug 35612: (QA follow-up) Add test for undefined LostChargesControl preference
Adds test coverage for the case where LostChargesControl system
preference is not set (returns undef). This ensures the code
handles this gracefully and defaults to ItemHomeLibrary behavior.

The test verifies that:
- No warnings are generated when the preference is undefined
- The default behavior (ItemHomeLibrary) is applied correctly
- The correct branch (item homebranch) is recorded in accountlines

This improves test coverage and prevents regression of the fix
for uninitialized value warnings.

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-27 11:38:54 -07:00
Laura_Escamilla 3308b7f61c
Bug 35612: Add tests for chargelostitem branch context
Adds test coverage for C4::Accounts::chargelostitem to verify that
LOST and PROCESSING fee debits correctly record branchcode based on
LostChargesControl and HomeOrHoldingBranch system preferences.

Tests verify all scenarios:

1. LostChargesControl behavior:
   - PatronLibrary: Uses patron's home branch
   - ItemHomeLibrary + homebranch: Uses item's home library
   - ItemHomeLibrary + holdingbranch: Uses item's holding library
2. Explicit library_id override:
   - When library_id is passed in options, it takes precedence
3. Deduplication logic:
   - Prevents duplicate LOST charges for same itemnumber+issue_id
   - Regression test for item_id column name bug
4. Issue_id handling:
   - Correctly looks up issue_id when not provided
   - Handles bundled items (looks up host item's checkout)
5. Processing fees:
   - Honors the same branch logic as LOST fees
   - Correctly applies lost_item_processing_fee circulation rule
     using the appropriate branch context

This test subtest was added to the existing "C4::Accounts::chargelostitem tests"
section and increases the test plan from 4 to 5 subtests.

Signed-off-by: Trevor Diamond <trevor.diamond@mainlib.org>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-27 11:38:52 -07:00
Laura_Escamilla 0832933a96
Bug 35612: Add tests for branch context recording in LOST fees via LostItem
Adds comprehensive test coverage for C4::Circulation::LostItem to verify
that LOST and PROCESSING fee debits correctly record branchcode based on
LostChargesControl and HomeOrHoldingBranch system preferences.

Tests verify:
- LostChargesControl = PatronLibrary uses patron's home branch
- LostChargesControl = PickupLibrary uses checkout/issue branch
- LostChargesControl = ItemHomeLibrary respects HomeOrHoldingBranch:
  * homebranch: uses item's home library
  * holdingbranch: uses item's holding library

Tests cover both LOST and PROCESSING fee types and verify the branch
context is preserved when fees are charged via the LostItem function,
which is called both from the staff interface when manually marking
items lost and from the longoverdue cronjob.

The tests also verify correct behavior when mark_lost_from = 'cronjob'
to ensure the interface context is properly set for batch operations.

Signed-off-by: Trevor Diamond <trevor.diamond@mainlib.org>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-27 11:38:51 -07:00
Laura_Escamilla c7764f1140
Bug 35612: Add tests for branch context recording in OVERDUE fees
Adds comprehensive test coverage for C4::Overdues::UpdateFine to verify
that the branchcode field is correctly populated based on CircControl
and HomeOrHoldingBranch system preferences.

Tests verify:
- CircControl = PatronLibrary uses patron's home branch
- CircControl = PickupLibrary uses checkout/issue branch
- CircControl = ItemHomeLibrary respects HomeOrHoldingBranch:
  * homebranch: uses item's home library
  * holdingbranch: uses item's holding library

The tests create distinct libraries for each context (patron home,
item home, item holding, checkout branch) and verify the correct
branch is recorded in accountlines.branchcode for OVERDUE debits.

Signed-off-by: Trevor Diamond <trevor.diamond@mainlib.org>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-27 11:38:50 -07:00
Laura_Escamilla 60728c63bb
Bug 35612: Add unit test for Koha::Checkout->branch_for_fee_context
Adds test coverage for the new branch_for_fee_context class method.
Tests are minimal at this stage but verify the method exists and
can be called. More comprehensive testing is covered in the
C4::Accounts, C4::Circulation, and C4::Overdues test additions.

Signed-off-by: Trevor Diamond <trevor.diamond@mainlib.org>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-27 11:38:50 -07:00
Martin Renvoize 08409dd450
Bug 36506: (QA follow-up) Add test for missing circulation rule
This adds a test case to verify that when no lost_item_processing_fee
circulation rule exists for a branch/itemtype combination, the system
correctly defaults to 0 (no processing fee charged).

The test confirms:
- No PROCESSING account line is created when the rule is missing
- The LOST fee is still created normally (only processing fee affected)
- The // 0 fallback in C4::Accounts::chargelostitem works correctly

Test plan:
1. prove t/db_dependent/Accounts.t
2. Verify all tests pass, including the new "missing circulation rule"
   test case

Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-27 11:38:48 -07:00
Nick Clemens 88542c7a64
Bug 36506: Unit tests
Sponsored-by: The Main Library Alliance <https://www.mainlib.org/>
Signed-off-by: Trevor Diamond <trevor.diamond@mainlib.org>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-27 11:38:47 -07:00
Nick Clemens cd0462b4c6
Bug 36506: Adjust existing tests and test builder
All the previously written tests should continue to pass.

Sponsored-by: The Main Library Alliance <https://www.mainlib.org/>
Signed-off-by: Trevor Diamond <trevor.diamond@mainlib.org>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-27 11:38:47 -07:00
Owen Leonard 899e4001e8
Bug 24949: Provide password visibility toggle / icon to unmask password on staff login screen
This patch adapts the work on Bug 34778 to the staff client, adding a
"Show password" checkbox to the login form.

To test, apply the batch and go to the staff client login screen.

- You should see a "Show password" checkbox under the password field.
- Type something in the password field. It should be masked (****).
- Click the "Show password" label or check the checkbox.
- The password field should now show the text you entered.
- Confirm that you can log in successfully whether or not the password
  is visible.
- `prove t/db_dependent/selenium/authentication.t` should pass.

Sponsored-by: Athens County Public Libraries
Signed-off-by: Roman Dolny <roman.dolny@jezuici.pl>
Signed-off-by: Mikko <mikko.liimatainen@turku.fi>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-27 11:38:42 -07:00
Tomás Cohen Arazi b16a541537
Bug 41616: Silence warning in authority_hooks.t
This patch silences a useless warning that is printed when in ES context.

To test:
1. Launch a KTD instance with ES enabled:
   $ ktd --proxy --name 41616 --search-engine es8 up -d
   $ ktd --name 41616 --wait-ready 120
2. Run:
   $ ktd --name 41616 --shell
  k$ prove t/db_dependent/Koha/Plugins/authority_hooks.t
=> SUCCESS: Tests pass
=> FAIL: You see:

```shell
prove t/db_dependent/Koha/Plugins/authority_hooks.t
t/db_dependent/Koha/Plugins/authority_hooks.t ................. 1/5 Plugin error (Test Plugin): Exception 'Koha::Exception' thrown 'elasticsearch_to_document ref record: MARC::Record - ref document: HASH'
Plugin error (Test Plugin): Exception 'Koha::Exception' thrown 'elasticsearch_to_document ref record: MARC::Record - ref document: HASH'
t/db_dependent/Koha/Plugins/authority_hooks.t ................. ok
All tests successful.
Files=20, Tests=119, 24 wallclock secs ( 0.04 usr  0.02 sys + 17.89 cusr  2.33 csys = 20.28 CPU)
Result: PASS
```

3. Apply this patch
4. Repeat 2
=> SUCCESS: No tests changes, but no more weird warnings about elasticsearch
5. Sign off :-D
6. Cleanup:
   $ ktd --name 41616 down

Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-26 09:04:24 -07:00
Paul Derscheid ee667d3ddf
Bug 41887: Skip clash detection on terminal status transition
- Booking::store runs item-level and biblio-level clash
  detection unconditionally on every call
- During checkout, C4::Circulation sets the booking status to
  'completed' and calls ->store(), which triggers clash checks
- Combined with false positives from Biblio::check_booking
  (e.g. checkouts on non-bookable sibling items inflating the
  unavailable count), this throws
  Koha::Exceptions::Booking::Clash resulting in a 500 error
- Running clash detection on a terminal transition is
  unnecessary regardless; skip it for cancelled/completed
- Add _is_final_status_transition() helper that inspects the
  dirty columns to detect completed/cancelled transitions
- Guard both clash detection blocks with the new helper

To test:
1. Have a biblio with two items: one bookable, one not
   (bookable = 0).
2. Create a booking on the bookable item.
3. Check out the non-bookable item to a patron.
4. Check out the bookable item to the booking patron (this
   triggers the completed transition via C4::Circulation).
5. Without the patch: 500 error from
   Koha::Exceptions::Booking::Clash.
6. Apply the patch.
7. Repeat steps 2-4.
8. Verify the checkout succeeds and the booking transitions
   to completed.
9. Run: prove t/db_dependent/Koha/Booking.t
   and confirm the new subtest "store() skips clash
   detection on terminal status transition" passes.

Sponsored-by: Büchereizentrale Schleswig-Holstein <https://www.bz-sh.de/>
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-26 09:04:22 -07:00
Paul Derscheid 560520305c
Bug 41886: Filter checkouts to bookable items in check_booking
- Biblio::check_booking counts current checkouts toward the
  unavailable pool to detect booking clashes
- It counts checkouts on ALL items for the biblio, including
  non-bookable ones (e.g. items with an excluded item type)
- When only a subset of items are bookable, checkouts on
  non-bookable siblings incorrectly reduce the available pool,
  producing false clashes
- Restrict the checkout query to only count items whose
  itemnumber is in the bookable items set

To test:
1. Have a biblio with at least two items, where one item is
   bookable and the other is not (bookable = 0).
2. Check out the non-bookable item to a patron.
3. Attempt to create a booking for the bookable item.
4. Without the patch: a clash is detected even though the
   bookable item is available.
5. Apply the patch.
6. Repeat steps 2-3.
7. Verify the booking succeeds without a false clash.
8. Run: prove t/db_dependent/Koha/Biblio.t
   and confirm the new subtest
   "checkouts on non-bookable items do not cause false clashes"
   passes.

Sponsored-by: Büchereizentrale Schleswig-Holstein <https://www.bz-sh.de/>
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-26 09:04:20 -07:00
Jonathan Druart 6b61f010f4
Bug 30803: Raise exception if $error is not passed
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-26 09:04:18 -07:00
Jonathan Druart 06c557cfad
Bug 30803: Add tests
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-26 09:04:17 -07:00
John Doe f9bab53f22
Bug 41036: (QA follow-up) use nowarnings
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-26 09:04:15 -07:00
Lari Taskula f54cce344c
Bug 41036: Log errors in Koha::ImportBatch->new_from_file
To test:
1. prove t/db_dependent/Koha/ImportBatch.t
2. Observe success

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-26 09:04:14 -07:00
Lari Taskula bcf4531288
Bug 41036: Add tests
To test:
1. Apply only this patch, do not yet apply the next one
2. prove t/db_dependent/Koha/ImportBatch.t
3. Observe tests failing

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-26 09:04:14 -07:00
Kyle M Hall 8959185536
Bug 41818: Add unit tests
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-26 09:04:12 -07:00
Pedro Amorim fb921843ab
Bug 41916: Update Cypress tests
Button is now 'Save' not 'Submit' after bug 40191

On ktd:
cypress run --spec t/cypress/integration/SIP2/*

All tests must pass

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-25 08:47:35 -07:00
Nick Clemens fabaa84003
Bug 38384: (follow-up) Improve tests for caching
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-25 07:37:01 -07:00
Martin Renvoize e091b0d4bc
Bug 38384: Refactor plugin loading to use lightweight Koha::Plugins::Loader
This patch addresses the circular dependency issues and code quality
concerns identified in QA by introducing a clean architectural solution.

Changes:

1. Created Koha::Plugins::Loader - A lightweight plugin loader with
   minimal dependencies that can be safely called during early
   initialization. Uses DBIx::Class when available for proper
   transaction support, falls back to raw DBI for early init.

2. Added Koha::Database::table_exists() - Consolidated table checking
   logic into a reusable method that can be called as both class and
   instance method.

3. Simplified C4::Context BEGIN block - Reduced from ~120 lines to
   ~13 lines (91% reduction). Removed XML::Simple dependency and
   manual database connection code.

4. Updated Koha::Plugins::get_enabled_plugins() - Now delegates to
   the Loader module for consistency.

5. Updated C4::Installer::TableExists - Delegates to the new
   Koha::Database::table_exists method.

This addresses all QA concerns:
- Eliminates XML::Simple usage (David Cook)
- Uses Koha::Database instead of manual DBI (David Cook)
- Reuses table checking logic (Nick Clemens)
- Eliminates circular dependencies (Paul Derscheid)
- Much cleaner and maintainable code

Test plan:
1. Run tests:
   prove t/db_dependent/Koha/Database.t
   prove t/db_dependent/Koha/Plugins/Loader.t
   prove t/db_dependent/Koha/Plugins/Plugins.t
2. All tests should pass
3. Install and enable a plugin via the UI
4. Verify plugin hooks are called correctly
5. Verify no regressions in plugin functionality

Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Andrew Fuerste Henry <andrew@bywatersolutions.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-25 07:36:59 -07:00
Jonathan Druart b714b4b8f9
Bug 41831: Mock POST /packages in Dialog_spec.ts
ERM/Titles_spec.ts fails if run after ERM/Dialog_spec.ts because Dialog's "...created!" test create a package and does not delete it.

02:48:52 koha-1      |       <failure message="Timed out retrying after 10000ms: Expected to find content: &apos;There are no packages created yet&apos; within the element: &lt;fieldset#resources_relationship.rows&gt; but never did." type="AssertionError"><![CDATA[AssertionError: Timed out retrying after 10000ms: Expected to find content: 'There are no packages created yet' within the element: <fieldset#resources_relationship.rows> but never did.

Test plan:
0. Do not apply the patch
1. yarn cypress run --spec t/cypress/integration/ERM/Dialog_spec.ts,t/cypress/integration/ERM/Titles_spec.ts
=> FAIL
2. Notice that one entry has been created in the DB table erm_eholdings_packages
3. Delete the DB entry:
  sudo koha-mysql kohadev -e 'DELETE FROM erm_eholdings_packages'
4. Apply this patch
5. Repeat 1
=> SUCCESS
6. Notice that no new entry has been created in erm_eholdings_packages

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-12 07:58:48 -07:00
Jonathan Druart f20fde6565
Bug 38262: Fix VueFramework_spec.ts
Fix the following error:
 Error: The following error originated from your application code, not from Cypress. It was caused by an unhandled promise rejection.

  > JS Warning detected: "[Vue warn]: Unhandled error during execution of watcher callback" "\n" " at <AdditionalFieldsEntry"

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-12 07:58:40 -07:00
Olli Kautonen 9445ffc9aa
Bug 40154: prevent deletion of items with holds
This patch prevents deletion of items that have item level holds on
them.

Test plan:
1. Create an item level hold.
2. Delete the item using alternative A or B:
   A. Open the biblios Detail-view -> From the toolbar, open
      "Edit"-dropdown menu -> Manage items -> Delete the item that has
      an item level hold attached to it from "Actions"-dropdown menu
   B. Open the biblios Detail-view -> Select the item that has an item
      level hold attached to it -> Click "Delete selected items" ->
      Confirm deletion
3. Notice that the item is deleted without any warning and the item
   level hold has disappeared.
4. Apply this patch.
5. Repeat steps 1-3.
6. Notice that the item cannot be deleted and a warning is shown.
7. prove t/db_dependent/Koha/Item.t
8. Run the REST API tests: prove t/db_dependent/api/v1/items.t

Sponsored-by: Koha-Suomi Oy
Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-10 10:52:04 -07:00
Lucas Gass b2e1993597
Bug 28530: Fix tests
Signed-off-by: Kris Becker <kbecker@jcls.org>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-10 10:51:38 -07:00
Lucas Gass e67a210b40
Bug 28530: Adjust tests
Signed-off-by: Kris Becker <kbecker@jcls.org>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-10 10:51:37 -07:00
Lucas Gass c39350dfb2
Bug 28530: Add more tests
Signed-off-by: Kris Becker <kbecker@jcls.org>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-10 10:51:36 -07:00
Kyle M Hall 83e6aecd07
Bug 28530: Add unit tests
Signed-off-by: Andrew Fuerste-Henry <andrewfh@dubcolib.org>
Signed-off-by: Kris Becker <kbecker@jcls.org>
Signed-off-by: Kris Becker <kbecker@jcls.org>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-10 10:51:35 -07:00
Kyle M Hall 556bd55543
Bug 33782: (QA follow-up) Fix qa issues
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-10 10:51:33 -07:00
Tomás Cohen Arazi 4ff2eb3469
Bug 33782: Add unit tests for Koha::Auth::Client::OAuth
This patch adds comprehensive unit tests for the OAuth authentication
client, specifically covering the _get_data_and_patron method which
handles JWT token processing and UserInfo endpoint integration.

Test plan:
1. Apply patch
2. Run:
   $ ktd --shell
  k$ prove t/db_dependent/Koha/Auth/Client/OAuth.t
=> SUCCESS: Tests pass!
3. Tests cover:
   - JWT id_token processing and patron matching
   - UserInfo endpoint calls and data merging
   - Non-existent user scenarios
   - Combined JWT + UserInfo data sources
4. Sign off :-D

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-10 10:51:32 -07:00
Paul Derscheid 9c7b02b365
Bug 37707: (QA follow-up) Fix incorrect bold date expectations in Cypress test
- The test for circulation rules date calculations did not account for
  the start date being bold, only the period endpoint dates
- place_booking.js explicitly adds the selected start date to boldDates
  (boldDates = [new Date(startDate)]), giving it the "title" class
- The verification loop checking for unexpected bold dates then failed
  when it encountered the start date, which was bold but not expected
- Add clearZoneStart to expectedBoldDates to match actual behavior

To test:
- yarn cypress run --spec t/cypress/integration/Circulation/bookingsModalDatePicker_spec.ts
- Verify that the "should handle circulation rules date calculations and visual feedback" test now passes

Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-10 08:51:08 -07:00
Martin Renvoize b591400ac1
Bug 37707: (follow-up) Add comprehensive Cypress tests for bookings modal
Reorganize and expand Cypress tests into three focused spec files:

bookingsModalBasic_spec.ts:
- Modal initialization and field interactions
- Form validation and submission
- Edit booking functionality
- 'Any item' booking with server-side item selection

bookingsModalDatePicker_spec.ts:
- Flatpickr initialization and constraints
- Date range validation
- Circulation rules (issue length, renewals)
- Lead/trail period conflict detection
- 'Any item' mode date availability
- Event dots for existing bookings

bookingsModalTimezone_spec.ts:
- Cross-timezone date display
- Multi-day booking spans
- Conflict detection with timezone awareness
- API round-trip date preservation
- Month boundary handling

Add shared test utilities to e2e.js for date helpers.

Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-10 08:51:07 -07:00
Martin Renvoize 6a17417359
Bug 37707: (follow-up) Support lead/trail periods for 'any item' bookings
When booking "any item of type X", lead/trail period handling must
consider that multiple items may be available:

- Track per-item conflicts instead of global conflicts
- Only disable dates when ALL items of the type have conflicts
- Find closest "all items booked" dates for visual feedback
- Use mathematical search (180 days) to detect conflicts across
  month boundaries

Visual feedback for 'any item' mode:
- Show lead/trail periods around "all items booked" dates
- These represent dates where no item of the type is available

Skip redundant class-based conflict checks since mathematical
detection already handles cross-month boundary cases.

Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-10 08:51:05 -07:00
Lucas Gass 4858768f9a
Bug 40134: (RM follow-up) Tidy commit
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-10 08:51:04 -07:00
Martin Renvoize 9360ed6157
Bug 40134: Add Cypress tests for booking improvements
This patch adds end-to-end Cypress tests for the booking modal improvements,
including smart window maximization and server-side optimal item selection.

New Tests:

1. "should successfully submit an 'Any item' booking with server-side optimal item selection"
   - Tests the complete "any item" booking workflow
   - Selects itemtype and "Any item" option (item_id = 0)
   - Submits booking form
   - Verifies modal closes without errors
   - Validates booking created in database
   - Confirms item was assigned by server
   - Verifies server-side optimal selection completed
   - Test status: PASSING

2. "should maximize booking window by dynamically reducing available items during overlaps"
   - Creates 4 items with strategic booking patterns
   - Tests "never re-add items to pool" algorithm
   - Validates 5 scenarios:
     a) Full window when all items available
     b) Reduced window when Item 1 becomes unavailable
     c) Further reduction when Items 1&2 unavailable
     d) Minimal window with Items 1,2,3 unavailable
     e) No availability when all items booked
   - Demonstrates smart window maximization
   - Test status: PASSING

3. "should handle edit mode date initialization correctly"
   - Tests fix for edit mode race condition
   - Verifies dates populate correctly when editing booking
   - Ensures itemtype is set before date initialization
   - Tests that flatpickr dates are set properly
   - Test status: PASSING

Updated Tests:

- "should successfully submit a booking"
  * Updated to use day+5 start date (accounts for 3-day lead period)
  * Ensures test doesn't fail on past-date constraint

- Updated test comments and log messages to reflect server-side selection
  * Changed from "client-side selectOptimalItem()" references
  * Updated to "server-side optimal item selection"
  * Clarified that server performs the optimal selection

Test Coverage:
- End-to-end "any item" booking submission
- Smart window maximization algorithm
- Edit mode date initialization
- Server-side optimal selection validation
- Database verification of assigned items
- Modal interaction and form submission

Test plan:
1. Start KTD environment
2. Ensure Cypress is installed: yarn install
3. Run: npx cypress run --spec "t/cypress/integration/Circulation/bookingsModalBasic_spec.ts"
4. Verify all 11 tests pass
5. Optionally run in interactive mode: npx cypress open

Signed-off-by: Kristi Krueger <kkrueger@cuyahogalibrary.org>
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-10 08:51:04 -07:00
Martin Renvoize a6766a9e80
Bug 40134: Add unit tests for optimal item selection
This patch adds unit tests for the server-side optimal item selection
functionality.

t/db_dependent/Koha/Booking.t:
- Added subtest for _select_optimal_item() method (7 tests)
  * Tests with no items (returns undef)
  * Tests with single item (returns that item)
  * Tests with multiple items (selects item with longest future availability)
  * Tests optimal selection across items with different booking patterns
  * Tests handling of cancelled bookings (ignored in selection)
  * Tests iterator reset after selection
- Added subtest for _assign_item_for_booking() with itemtype filtering (6 tests)
  * Tests booking without item_id or itemtype_id (selects any available)
  * Tests booking with itemtype_id (filters by type)
  * Tests optimal selection within filtered itemtype
  * Tests exception when no items of specified type available
- Added integration test for full optimal selection workflow (5 tests)
  * Creates 3 items with different future booking patterns
  * Verifies items selected in optimal order (B→C→A)
  * Demonstrates preservation of constrained resources
  * Validates complete algorithm chain
  * Tests booking failure when all items exhausted

t/db_dependent/api/v1/bookings.t:
- Added subtest for itemtype_id parameter validation (16 tests)
  * Tests successful booking creation with itemtype_id
  * Tests that item is automatically assigned
  * Tests validation: cannot specify both item_id and itemtype_id
  * Tests validation: must specify either item_id or itemtype_id
  * Tests clash detection with itemtype-based bookings
- Fixed duplicate booking_id test to use different dates
  * Prevents clash detection from masking duplicate ID constraint
- Updated test count from 3 to 8 subtests in Booking.t
- Updated test count to match actual assertions (16 not 18)

Test Coverage:
- Internal method testing: _select_optimal_item()
- Integration testing: _assign_item_for_booking()
- API endpoint testing: add() with itemtype_id
- End-to-end workflow validation
- Edge cases: empty sets, single items, ties, cancelled bookings

Test plan:
1. prove t/db_dependent/Koha/Booking.t
2. prove t/db_dependent/api/v1/bookings.t
3. Verify all tests pass

Signed-off-by: Kristi Krueger <kkrueger@cuyahogalibrary.org>
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-10 08:51:03 -07:00
Jonathan Druart 458a163360
Bug 39745: Replace more occurrences in selenium tests
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-09 12:57:59 -07:00
Lucas Gass 23934c8edc
Bug 3492: (RM follow-up) Adjust tests
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-09 12:57:58 -07:00
Martin Renvoize 1c893cc019
Bug 3492: (follow-up) Remove last reservefee references
Sponsored-by: OpenFifth <https://openfifth.co.uk>
Signed-off-by: Jackie Usher <jackie.usher@westsussex.gov.uk>
Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-09 12:57:57 -07:00
Martin Renvoize f1b20b645c
Bug 3492: Modernize hold fee system and migrate to circulation rules
This commit completely modernizes the hold fee system by migrating from
the deprecated categories.reservefee column to the circulation rules framework
and implementing modern Koha::Objects patterns.

WHAT CHANGED:

1. MIGRATION TO CIRCULATION RULES:
   - Moved hold fees from categories.reservefee to circulation_rules table
   - Added database migration script with atomic update
   - Maintains existing fee amounts during migration
   - Provides rule hierarchy: category+itemtype+branch specific rules

2. NEW SYSTEM PREFERENCE: TitleHoldFeeStrategy
   - Options: highest, lowest, most_common
   - Addresses inconsistent title-level hold fees when items have different fees
   - Default: 'highest' (safest approach for library revenue)

3. MODERN Koha::Objects API:
   - Koha::Item->holds_fee($patron): Calculate fee for specific item
   - Koha::Hold->calculate_hold_fee(): Enhanced item/title-level logic
   - Koha::Hold->should_charge($stage): Centralized charging logic
   - Koha::Hold->charge_hold_fee(): Modern fee charging with proper accounting
   - Removed C4::Reserves::GetReserveFee and ChargeReserveFee

4. ENHANCED FUNCTIONALITY:
   - Proper ReservesControlBranch logic (patron home vs item home library)
   - Complete HoldFeeMode implementation (placement/collection/not_always)
   - Clear OPAC messaging with "You will be charged..." commitment
   - Comprehensive test coverage for all fee scenarios

5. TECHNICAL IMPROVEMENTS:
   - Object-oriented design following Koha patterns
   - Proper error handling and edge case management
   - Modern test structure with comprehensive coverage
   - Clean separation between fee calculation and charging

TEST PLAN:

A) MIGRATION AND SETUP:
   1. Apply all patches and run database update
   2. Verify existing hold fees migrated to circulation rules:
      - Administration > Circulation and fine rules
      - Previous categories.reservefee values now in "Hold fee" column
   3. Confirm old categories.reservefee column no longer used

B) BASIC FEE CALCULATION:
   1. Set up patron categories with different hold fees in circulation rules
   2. Create items with different item types, each with different hold fees
   3. Test item-level holds charge correct fees based on specific item
   4. Test title-level holds use TitleHoldFeeStrategy preference

C) TITLE-LEVEL HOLD STRATEGIES:
   1. Set TitleHoldFeeStrategy to "highest":
      - Create title with items having fees $1.00, $2.00, $3.00
      - Verify title-level holds charge $3.00
   2. Set TitleHoldFeeStrategy to "lowest":
      - Verify same title charges $1.00
   3. Set TitleHoldFeeStrategy to "most_common":
      - Add multiple items with $2.00 fee
      - Verify title-level holds charge $2.00 (most common)

D) HOLDFEEMODE PREFERENCES:
   1. Set HoldFeeMode to "any_time_is_placed":
      - Place holds and verify immediate fee charging
      - Check patron account for correct hold fee debits
   2. Set HoldFeeMode to "any_time_is_collected":
      - Place holds, verify no immediate charges
      - Check out items to patron, verify fee charged on collection
   3. Set HoldFeeMode to "not_always":
      - With available items: verify no fee charged
      - With all items checked out but no other holds: verify no fee
      - With all items checked out and other holds exist: verify fee charged

E) RULE HIERARCHY TESTING:
   1. Set different fees for different category/itemtype/branch combinations
   2. Verify most specific rule applies:
      - Branch + Category + ItemType (most specific)
      - Category + ItemType
      - Category only (most general)
   3. Test with different patron categories and item types

F) USER INTERFACE TESTING:
   1. OPAC interface:
      - Verify "You will be charged..." messages display correct amounts
      - Test both item-level and title-level hold fee messages
      - Confirm fees match actual charges in patron account
   2. Staff interface:
      - Place holds for patrons and verify fee calculations
      - Check Administration > Circulation rules interface works correctly

G) EDGE CASES AND ERROR HANDLING:
   1. Test $0.00 fees (no charge scenarios)
   2. Test patrons with no applicable fee rules (should default to $0.00)
   3. Test items with no holdable copies (should return $0.00)
   4. Test invalid/missing itemtypes or categories
   5. Test holds on biblios with no items

H) REGRESSION TESTING:
   1. Verify existing hold placement workflows unchanged
   2. Check patron account charging remains accurate
   3. Confirm OPAC and staff interfaces display correctly
   4. Test that existing holds continue to work properly

I) UNIT TESTS:
   Run the following test suites to verify functionality:
   - prove t/db_dependent/Koha/Hold.t
   - prove t/db_dependent/Koha/Item.t
   - prove t/db_dependent/Reserves.t
   - prove t/db_dependent/Circulation.t

BACKWARDS COMPATIBILITY:
- All existing functionality preserved
- Hold fee amounts maintained during migration
- Existing workflows continue unchanged
- Legacy code updated to use new API seamlessly

Sponsored-by: OpenFifth <https://openfifth.co.uk>
Signed-off-by: Jackie Usher <jackie.usher@westsussex.gov.uk>
Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-09 12:57:56 -07:00
Martin Renvoize aee1c8f7a5
Bug 40095: Add context to intranet_js plugin hook
The get_plugins_intranet_js method now passes the current script name
(controller) to plugins via a 'page' parameter, allowing plugins to
determine which page/controller is being displayed.

This will allow plugin authors to only return JS that's relevant to the
current page when they wish to do so.

Test plan:
1. Create a plugin with an intranet_js method that logs the received parameters
2. Navigate to different pages in the staff interface
3. Verify that the plugin receives the page parameter containing the script name
4. Confirm that the script name reflects the actual controller (e.g.,
   '/cgi-bin/koha/admin/admin-home.pl' when on the admin home page)
5. Run the test: prove t/db_dependent/Koha/Template/Plugin/KohaPlugins.t
6. Verify that the new test passes, confirming plugins receive the page parameter

Signed-off-by: Roman Dolny <roman.dolny@jezuici.pl>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-06 15:17:36 -07:00
Lucas Gass b190813020
Bug 41368: Fix View batch click
To test:
1. APPLY PATCH
2. yarn build
3. cypress run --spec t/cypress/integration/Tools/ManageMarcImport_spec.ts
4. It should now pass

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-06 15:17:32 -07:00