Bug 9302: (QA follow-up) Consistency follow-up
[koha.git] / t / db_dependent / Koha / Libraries.t
blobd24ba3d6feee49e89e92335109d5eb9d87af80c8
1 #!/usr/bin/perl
3 # Copyright 2015 Koha Development team
5 # This file is part of Koha
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Modern::Perl;
22 use Test::More tests => 4;
24 use Koha::Library;
25 use Koha::Libraries;
26 use Koha::Database;
28 use t::lib::Mocks;
29 use t::lib::TestBuilder;
31 my $schema = Koha::Database->new->schema;
32 $schema->storage->txn_begin;
34 my $builder = t::lib::TestBuilder->new;
35 my $nb_of_libraries = Koha::Libraries->search->count;
36 my $new_library_1 = Koha::Library->new({
37 branchcode => 'my_bc_1',
38 branchname => 'my_branchname_1',
39 branchnotes => 'my_branchnotes_1',
40 marcorgcode => 'US-MyLib',
41 })->store;
42 my $new_library_2 = Koha::Library->new({
43 branchcode => 'my_bc_2',
44 branchname => 'my_branchname_2',
45 branchnotes => 'my_branchnotes_2',
46 })->store;
48 is( Koha::Libraries->search->count, $nb_of_libraries + 2, 'The 2 libraries should have been added' );
50 my $retrieved_library_1 = Koha::Libraries->find( $new_library_1->branchcode );
51 is( $retrieved_library_1->branchname, $new_library_1->branchname, 'Find a library by branchcode should return the correct library' );
53 $retrieved_library_1->delete;
54 is( Koha::Libraries->search->count, $nb_of_libraries + 1, 'Delete should have deleted the library' );
56 $schema->storage->txn_rollback;
58 subtest '->get_effective_marcorgcode' => sub {
60 plan tests => 4;
62 $schema->storage->txn_begin;
64 my $library_1 = $builder->build_object({ class => 'Koha::Libraries',
65 value => { marcorgcode => 'US-MyLib' } });
66 my $library_2 = $builder->build_object({ class => 'Koha::Libraries',
67 value => { marcorgcode => undef } });
69 t::lib::Mocks::mock_preference('MARCOrgCode', 'US-Default');
71 is( $library_1->get_effective_marcorgcode, 'US-MyLib',
72 'If defined, use library\'s own marc org code');
73 is( $library_2->get_effective_marcorgcode, 'US-Default',
74 'If not defined library\' marc org code, use the one from system preferences');
76 t::lib::Mocks::mock_preference('MARCOrgCode', 'Blah');
77 is( $library_2->get_effective_marcorgcode, 'Blah',
78 'Fallback is always MARCOrgCode syspref');
80 $library_2->marcorgcode('ThisIsACode')->store();
81 is( $library_2->get_effective_marcorgcode, 'ThisIsACode',
82 'Pick library_2 code');
84 $schema->storage->txn_rollback;