View | Details | Raw Unified | Return to bug 22688
Collapse All | Expand All

(-)a/t/db_dependent/Template/Plugin/Branches.t (-2 / +80 lines)
Lines 16-24 Link Here
16
16
17
use Modern::Perl;
17
use Modern::Perl;
18
18
19
use Test::More tests => 17;
19
use Test::More tests => 18;
20
20
21
use C4::Context;
21
use C4::Context;
22
use C4::Biblio qw(AddBiblio);
23
use C4::Items qw(AddItem);
22
use Koha::Database;
24
use Koha::Database;
23
25
24
use t::lib::TestBuilder;
26
use t::lib::TestBuilder;
Lines 94-96 $libraries = $plugin->all(); Link Here
94
is( scalar(@$libraries), 1, 'If IndependentBranches is set, only 1 library should be returned' );
96
is( scalar(@$libraries), 1, 'If IndependentBranches is set, only 1 library should be returned' );
95
$libraries = $plugin->all( { unfiltered => 1 } );
97
$libraries = $plugin->all( { unfiltered => 1 } );
96
ok( scalar(@$libraries) > 1, 'If IndependentBranches is set, all libraries should be returned if the unfiltered flag is set' );
98
ok( scalar(@$libraries) > 1, 'If IndependentBranches is set, all libraries should be returned if the unfiltered flag is set' );
97
- 
99
100
subtest 'UseBranchTransferLimits = OFF' => sub {
101
    plan tests => 5;
102
103
    my $from = Koha::Library->new({
104
        branchcode => 'zzzfrom',
105
        branchname => 'zzzfrom',
106
        branchnotes => 'zzzfrom',
107
    })->store;
108
    my $to = Koha::Library->new({
109
        branchcode => 'zzzto',
110
        branchname => 'zzzto',
111
        branchnotes => 'zzzto',
112
    })->store;
113
114
    my ($bibnum, $title, $bibitemnum) = create_helper_biblio('DUMMY');
115
    # Create item instance for testing.
116
    my ($item_bibnum1, $item_bibitemnum1, $itemnumber1)
117
    = AddItem({ homebranch => $from->branchcode,
118
                holdingbranch => $from->branchcode } , $bibnum);
119
    my ($item_bibnum2, $item_bibitemnum2, $itemnumber2)
120
    = AddItem({ homebranch => $from->branchcode,
121
                holdingbranch => $from->branchcode } , $bibnum);
122
    my ($item_bibnum3, $item_bibitemnum3, $itemnumber3)
123
    = AddItem({ homebranch => $from->branchcode,
124
                holdingbranch => $from->branchcode } , $bibnum);
125
    my $biblio = Koha::Biblios->find($bibnum);
126
127
    t::lib::Mocks::mock_preference('UseBranchTransferLimits', 0);
128
    t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype');
129
    t::lib::Mocks::mock_preference('item-level_itypes', 1);
130
    Koha::Item::Transfer::Limits->delete;
131
    Koha::Item::Transfer::Limit->new({
132
        fromBranch => $from->branchcode,
133
        toBranch => $to->branchcode,
134
        itemtype => $biblio->itemtype,
135
    })->store;
136
    my $total_pickup = Koha::Libraries->search({
137
        pickup_location => 1
138
    })->count;
139
140
    # Test TT plugin
141
    my $pickup = Koha::Template::Plugin::Branches::pickup_locations({ biblio => $bibnum });
142
    is(C4::Context->preference('UseBranchTransferLimits'), 0, 'Given system '
143
       .'preference UseBranchTransferLimits is switched OFF,');
144
    is(@{$pickup}, $total_pickup, 'Then the total number of pickup locations '
145
       .'equal number of libraries with pickup_location => 1');
146
147
    t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype');
148
    t::lib::Mocks::mock_preference('item-level_itypes', 1);
149
    $pickup = Koha::Template::Plugin::Branches::pickup_locations({ biblio => $bibnum });
150
    is(@{$pickup}, $total_pickup, '...when '
151
       .'BranchTransferLimitsType = itemtype and item-level_itypes = 1');
152
    t::lib::Mocks::mock_preference('item-level_itypes', 0);
153
    $pickup = Koha::Template::Plugin::Branches::pickup_locations({ biblio => $bibnum });
154
    is(@{$pickup}, $total_pickup, '...as well as when '
155
       .'BranchTransferLimitsType = itemtype and item-level_itypes = 0');
156
    t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'ccode');
157
    $pickup = Koha::Template::Plugin::Branches::pickup_locations({ biblio => $bibnum });
158
    is(@{$pickup}, $total_pickup, '...as well as when '
159
       .'BranchTransferLimitsType = ccode');
160
161
    t::lib::Mocks::mock_preference('item-level_itypes', 1);
162
};
163
164
sub create_helper_biblio {
165
    my $itemtype = shift;
166
    my ($bibnum, $title, $bibitemnum);
167
    my $bib = MARC::Record->new();
168
    $title = 'Silence in the library';
169
    $bib->append_fields(
170
        MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'),
171
        MARC::Field->new('245', ' ', ' ', a => $title),
172
        MARC::Field->new('942', ' ', ' ', c => $itemtype),
173
    );
174
    return ($bibnum, $title, $bibitemnum) = AddBiblio($bib, '');
175
}

Return to bug 22688