|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
# This file is part of Koha. |
| 4 |
# |
| 5 |
# Koha is free software; you can redistribute it and/or modify it under the |
| 6 |
# terms of the GNU General Public License as published by the Free Software |
| 7 |
# Foundation; either version 3 of the License, or (at your option) any later |
| 8 |
# version. |
| 9 |
# |
| 10 |
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
| 11 |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
| 12 |
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU General Public License along |
| 15 |
# with Koha; if not, see <https://www.gnu.org/licenses>. |
| 16 |
|
| 17 |
use Modern::Perl; |
| 18 |
|
| 19 |
use Test::More tests => 3; |
| 20 |
use Test::Exception; |
| 21 |
use Test::MockModule; |
| 22 |
use Test::NoWarnings; |
| 23 |
|
| 24 |
use t::lib::TestBuilder; |
| 25 |
use t::lib::Mocks::Logger; |
| 26 |
|
| 27 |
BEGIN { |
| 28 |
use_ok('Koha::Template::Plugin::AuthClient'); |
| 29 |
} |
| 30 |
|
| 31 |
my $schema = Koha::Database->new->schema; |
| 32 |
my $builder = t::lib::TestBuilder->new; |
| 33 |
my $logger = t::lib::Mocks::Logger->new(); |
| 34 |
|
| 35 |
subtest 'get_providers() tests' => sub { |
| 36 |
|
| 37 |
plan tests => 2; |
| 38 |
|
| 39 |
subtest 'Normal operation' => sub { |
| 40 |
|
| 41 |
plan tests => 2; |
| 42 |
|
| 43 |
$schema->storage->txn_begin; |
| 44 |
|
| 45 |
my $plugin = Koha::Template::Plugin::AuthClient->new(); |
| 46 |
my $providers; |
| 47 |
|
| 48 |
lives_ok { |
| 49 |
$providers = $plugin->get_providers('staff'); |
| 50 |
} |
| 51 |
'get_providers executes without error'; |
| 52 |
|
| 53 |
is( ref($providers), 'ARRAY', 'Returns array reference' ); |
| 54 |
|
| 55 |
$schema->storage->txn_rollback; |
| 56 |
}; |
| 57 |
|
| 58 |
subtest 'Database error handling' => sub { |
| 59 |
|
| 60 |
plan tests => 2; |
| 61 |
|
| 62 |
$schema->storage->txn_begin; |
| 63 |
$logger->clear(); |
| 64 |
|
| 65 |
# Mock search to simulate database schema mismatch |
| 66 |
my $mock = Test::MockModule->new('Koha::Auth::Identity::Providers'); |
| 67 |
$mock->mock( |
| 68 |
'search', |
| 69 |
sub { |
| 70 |
die "DBD::mysql::st execute failed: Unknown column 'domains.auto_register_opac' in 'field list'"; |
| 71 |
} |
| 72 |
); |
| 73 |
|
| 74 |
my $plugin = Koha::Template::Plugin::AuthClient->new(); |
| 75 |
my $providers; |
| 76 |
|
| 77 |
lives_ok { |
| 78 |
$providers = $plugin->get_providers('staff'); |
| 79 |
} |
| 80 |
'get_providers handles database errors gracefully'; |
| 81 |
|
| 82 |
$logger->warn_like( qr/AuthClient: Unable to load identity providers/, 'Logs warning about database issue' ); |
| 83 |
|
| 84 |
$schema->storage->txn_rollback; |
| 85 |
}; |
| 86 |
}; |