Bug ID: 18445
Summary: Tests in t stumble over Auth's BEGIN block
Change sponsored?: ---
Priority: P5 - low
Component: Test Suite
Assignee: [hidden email] Reporter: [hidden email] QA Contact: [hidden email]
We should be able to run the tests in t without the database.
But if some module loads Auth.pm via C4/Serials or Koha/Virtualshelf directly
or indirectly, this will trigger execution of Auth's BEGIN block. This block
contains three calls for systempreferences (one from Auth_with_cas). Note that
loading Biblio.pm also starts a chain going to Auth.pm.
This report changes two use C4::Auth statements into requires. This will
prevent or postpone execution of this code. Note also that this will resolve a
few failing tests like (Matcher.t and Prices.t) where the schema mock actually
was too late and the database was accessed instead of defined fixtures.
Along the way we fix a few minor issues in t where database access should be
Both Serials.pm and Virtualshelf.pm only need haspermission in a specific
sub. Since loading the module at compile-time triggers early execution of
the BEGIN block, this results in database access in the tests that are
assumed to be database independent.
At the same time we are resolving test failures in Matcher.t and Prices.t
because the schema mock is too late.
 Do not yet apply this patch. Backup your database.
 Drop the database and create a new empty one.
 Run the tests in t. Look at Matcher.t and Prices.t too.
You will see quite some occurrences of:
DBD::mysql::st execute failed: Table 'koha_master.systempreferences'
doesn't exist [for Statement "SELECT `me`.`variable`, `me`.`value`,
`me`.`options`, `me`.`explanation`, `me`.`type` FROM `systempreferences` `me`
WHERE ( `me`.`variable` = ? )" with ParamValues: 0='casauthentication'] at
/usr/share/perl5/DBIx/Class/Storage/DBI.pm line 1832.
 Apply this patch.
 Run the tests in t again. Check the results of Matcher.t and Prices.t.
 Restore your database.
 Run t/db_dependent/Serials_2.t to trigger the change in Serials.
 Run t/db_dependent/Virtualshelves.t to test Koha/Virtualshelf.
--- Comment #6 from Marcel de Rooy <[hidden email]> ---
(In reply to Jonathan Druart from comment #5)
> Marcel, did you see bug 18226 and related?
> I don't think we should replace the use with require to make the tests pass.