3 # Copyright 2019 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
=> 2;
28 use t
::lib
::TestBuilder
;
30 my $builder = t
::lib
::TestBuilder
->new;
31 my $schema = Koha
::Database
->new->schema;
33 subtest
'library' => sub {
36 $schema->storage->txn_begin;
38 my $library = $builder->build_object( { class => 'Koha::Libraries' } );
39 my $register = $builder->build_object(
41 class => 'Koha::Cash::Registers',
42 value
=> { branch
=> $library->branchcode },
46 is
( ref( $register->library ),
48 'Koha::Cash::Register->library should return a Koha::Library' );
50 is
( $register->library->id,
52 'Koha::Cash::Register->library returns the correct Koha::Library' );
54 $schema->storage->txn_rollback;
57 subtest
'branch_default' => sub {
60 $schema->storage->txn_begin;
61 my $library = $builder->build_object( { class => 'Koha::Libraries' } );
62 my $register1 = $builder->build_object(
64 class => 'Koha::Cash::Registers',
65 value
=> { branch
=> $library->branchcode, branch_default
=> 1 },
68 my $register2 = $builder->build_object(
70 class => 'Koha::Cash::Registers',
71 value
=> { branch
=> $library->branchcode, branch_default
=> 0 },
75 subtest
'store' => sub {
78 $register1->name('Test till 1');
79 ok
( $register1->store(),
80 "Store works as expected when branch_default is not changed" );
82 $register1->branch_default(0);
83 throws_ok
{ $register1->store(); }
84 'Koha::Exceptions::Object::ReadOnlyProperty',
85 'Exception thrown if direct update to branch_default is attempted';
89 subtest
'make_default' => sub {
92 ok
($register2->make_default,'Koha::Register->make_default ran');
94 $register1 = $register1->get_from_storage;
95 $register2 = $register2->get_from_storage;
96 is
($register1->branch_default, 0, 'register1 was unset as expected');
97 is
($register2->branch_default, 1, 'register2 was set as expected');
100 subtest
'drop_default' => sub {
103 ok
($register2->drop_default,'Koha::Register->drop_default ran');
105 $register2 = $register2->get_from_storage;
106 is
($register2->branch_default, 0, 'register2 was unset as expected');
109 $schema->storage->txn_rollback;