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>.
22 use Test
::More tests
=> 4;
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',
42 my $new_library_2 = Koha
::Library
->new({
43 branchcode
=> 'my_bc_2',
44 branchname
=> 'my_branchname_2',
45 branchnotes
=> 'my_branchnotes_2',
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 {
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;