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

(-)a/t/db_dependent/Accounts.t (-6 / +6 lines)
Lines 49-65 can_ok( 'C4::Accounts', Link Here
49
49
50
my $schema  = Koha::Database->new->schema;
50
my $schema  = Koha::Database->new->schema;
51
$schema->storage->txn_begin;
51
$schema->storage->txn_begin;
52
my $dbh = C4::Context->dbh;
52
53
53
my $builder = t::lib::TestBuilder->new();
54
my $builder = t::lib::TestBuilder->new();
54
55
55
my $dbh = C4::Context->dbh;
56
my $library = $builder->build({
56
$dbh->{RaiseError}=1;
57
    source => 'Branch',
57
$dbh->{AutoCommit}=0;
58
});
59
58
$dbh->do(q|DELETE FROM accountlines|);
60
$dbh->do(q|DELETE FROM accountlines|);
59
$dbh->do(q|DELETE FROM issues|);
61
$dbh->do(q|DELETE FROM issues|);
60
$dbh->do(q|DELETE FROM borrowers|);
62
$dbh->do(q|DELETE FROM borrowers|);
61
63
62
my $branchcode = 'CPL';
64
my $branchcode = $library->{branchcode};
63
my $borrower_number;
65
my $borrower_number;
64
66
65
my $context = new Test::MockModule('C4::Context');
67
my $context = new Test::MockModule('C4::Context');
Lines 293-298 subtest "makepartialpayment() tests" => sub { Link Here
293
    }
295
    }
294
};
296
};
295
297
296
$dbh->rollback;
297
298
1;
298
1;
(-)a/t/db_dependent/Acquisition/OrderUsers.t (-7 / +10 lines)
Lines 8-17 use C4::Letters; Link Here
8
use Koha::Database;
8
use Koha::Database;
9
use Koha::Acquisition::Order;
9
use Koha::Acquisition::Order;
10
10
11
my $schema = Koha::Database->new()->schema();
11
use t::lib::TestBuilder;
12
$schema->storage->txn_begin();
12
13
my $dbh = C4::Context->dbh;
13
my $schema = Koha::Database->schema;
14
$dbh->{RaiseError} = 1;
14
$schema->storage->txn_begin;
15
my $builder = t::lib::TestBuilder->new;
16
17
my $library = $builder->build({
18
    source => "Branch",
19
});
15
20
16
# Creating some orders
21
# Creating some orders
17
my $booksellerid = C4::Bookseller::AddBookseller(
22
my $booksellerid = C4::Bookseller::AddBookseller(
Lines 65-71 my $borrowernumber = C4::Members::AddMember( Link Here
65
    firstname =>  'TESTFN',
70
    firstname =>  'TESTFN',
66
    surname => 'TESTSN',
71
    surname => 'TESTSN',
67
    categorycode => 'S',
72
    categorycode => 'S',
68
    branchcode => 'CPL',
73
    branchcode => $library->{branchcode},
69
    dateofbirth => '',
74
    dateofbirth => '',
70
    dateexpiry => '9999-12-31',
75
    dateexpiry => '9999-12-31',
71
    userid => 'TESTUSERID'
76
    userid => 'TESTUSERID'
Lines 109-113 ModReceiveOrder( Link Here
109
114
110
$messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber });
115
$messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber });
111
is( scalar( @$messages ), 1, 'The letter has been sent to message queue on receiving the order');
116
is( scalar( @$messages ), 1, 'The letter has been sent to message queue on receiving the order');
112
113
$schema->storage->txn_rollback();
(-)a/t/db_dependent/Borrower_Debarments.t (-5 / +11 lines)
Lines 4-23 use Modern::Perl; Link Here
4
4
5
use C4::Context;
5
use C4::Context;
6
use C4::Members;
6
use C4::Members;
7
use Koha::Database;
8
9
use t::lib::TestBuilder;
7
10
8
use Test::More tests => 31;
11
use Test::More tests => 31;
9
12
10
use_ok('Koha::Borrower::Debarments');
13
use_ok('Koha::Borrower::Debarments');
11
14
15
my $schema = Koha::Database->schema;
16
$schema->storage->txn_begin;
17
my $builder = t::lib::TestBuilder->new;
12
my $dbh = C4::Context->dbh;
18
my $dbh = C4::Context->dbh;
13
$dbh->{AutoCommit} = 0;
19
14
$dbh->{RaiseError} = 1;
20
my $library = $builder->build({
21
    source => 'Branch',
22
});
15
23
16
my $borrowernumber = AddMember(
24
my $borrowernumber = AddMember(
17
    firstname =>  'my firstname',
25
    firstname =>  'my firstname',
18
    surname => 'my surname',
26
    surname => 'my surname',
19
    categorycode => 'S',
27
    categorycode => 'S',
20
    branchcode => 'CPL',
28
    branchcode => $library->{branchcode},
21
);
29
);
22
30
23
my $success = AddDebarment({
31
my $success = AddDebarment({
Lines 153-157 is( IsDebarred( $borrowernumber ), undef, 'A patron without a debarred date is n Link Here
153
161
154
$dbh->do(q|UPDATE borrowers SET debarred = '9999-12-31'|); # Note: Change this test before the first of January 10000!
162
$dbh->do(q|UPDATE borrowers SET debarred = '9999-12-31'|); # Note: Change this test before the first of January 10000!
155
is( IsDebarred( $borrowernumber ), '9999-12-31', 'A patron with a debarred date in the future is debarred' );
163
is( IsDebarred( $borrowernumber ), '9999-12-31', 'A patron with a debarred date in the future is debarred' );
156
157
$dbh->rollback;
(-)a/t/db_dependent/Borrower_Discharge.t (-9 / +15 lines)
Lines 25-34 use C4::Context; Link Here
25
use C4::Items qw( AddItem );
25
use C4::Items qw( AddItem );
26
use C4::Members qw( AddMember GetMember );
26
use C4::Members qw( AddMember GetMember );
27
27
28
use t::lib::TestBuilder;
29
use Koha::Borrower::Discharge;
28
use Koha::Borrower::Discharge;
30
use Koha::Database;
29
use Koha::Database;
31
30
31
use t::lib::TestBuilder;
32
32
my $schema  = Koha::Database->new->schema;
33
my $schema  = Koha::Database->new->schema;
33
$schema->storage->txn_begin;
34
$schema->storage->txn_begin;
34
35
Lines 37-69 my $builder = t::lib::TestBuilder->new; Link Here
37
my $dbh = C4::Context->dbh;
38
my $dbh = C4::Context->dbh;
38
$dbh->do(q|DELETE FROM discharges|);
39
$dbh->do(q|DELETE FROM discharges|);
39
40
41
my $library = $builder->build({
42
    source => 'Branch',
43
});
44
my $another_library = $builder->build({
45
    source => 'Branch',
46
});
47
40
C4::Context->_new_userenv('xxx');
48
C4::Context->_new_userenv('xxx');
41
C4::Context->set_userenv(0, 0, 0, 'firstname', 'surname', 'CPL', 'CPL', '', '', '', '', '');
49
C4::Context->set_userenv(0, 0, 0, 'firstname', 'surname', $library->{branchcode}, $library->{branchcode}, '', '', '', '', '');
42
my $branchcode = 'CPL';
43
my $another_branchcode = 'MPL';
44
my $borrower = $builder->build({
50
my $borrower = $builder->build({
45
    source => 'Borrower',
51
    source => 'Borrower',
46
    value => {
52
    value => {
47
        branchcode => $branchcode,
53
        branchcode => $library->{branchcode},
48
    }
54
    }
49
});
55
});
50
my $borrower2 = $builder->build({
56
my $borrower2 = $builder->build({
51
    source => 'Borrower',
57
    source => 'Borrower',
52
    value => {
58
    value => {
53
        branchcode => $branchcode,
59
        branchcode => $library->{branchcode},
54
    }
60
    }
55
});
61
});
56
my $borrower3 = $builder->build({
62
my $borrower3 = $builder->build({
57
    source => 'Borrower',
63
    source => 'Borrower',
58
    value => {
64
    value => {
59
        branchcode => $another_branchcode,
65
        branchcode => $another_library->{branchcode},
60
    }
66
    }
61
});
67
});
62
68
63
# Discharge not possible with issues
69
# Discharge not possible with issues
64
my ( $biblionumber ) = AddBiblio( MARC::Record->new, '');
70
my ( $biblionumber ) = AddBiblio( MARC::Record->new, '');
65
my $barcode = 'BARCODE42';
71
my $barcode = 'BARCODE42';
66
my ( undef, undef, $itemnumber ) = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL', barcode => $barcode }, $biblionumber);
72
my ( undef, undef, $itemnumber ) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, barcode => $barcode }, $biblionumber);
67
AddIssue( $borrower, $barcode );
73
AddIssue( $borrower, $barcode );
68
is( Koha::Borrower::Discharge::can_be_discharged({ borrowernumber => $borrower->{borrowernumber} }), 0, 'A patron with issues cannot be discharged' );
74
is( Koha::Borrower::Discharge::can_be_discharged({ borrowernumber => $borrower->{borrowernumber} }), 0, 'A patron with issues cannot be discharged' );
69
75
Lines 87-93 is( Koha::Borrower::Discharge::is_discharged( { borrowernumber => $borrower->{bo Link Here
87
is( Koha::Borrower::Debarments::IsDebarred( $borrower->{borrowernumber} ), '9999-12-31', 'The patron has been debarred after discharge' );
93
is( Koha::Borrower::Debarments::IsDebarred( $borrower->{borrowernumber} ), '9999-12-31', 'The patron has been debarred after discharge' );
88
is( scalar( @{ Koha::Borrower::Discharge::get_validated() } ),             3,            'There are 3 validated discharges' );
94
is( scalar( @{ Koha::Borrower::Discharge::get_validated() } ),             3,            'There are 3 validated discharges' );
89
is( scalar( @{ Koha::Borrower::Discharge::get_validated( { borrowernumber => $borrower->{borrowernumber} } ) } ), 1, 'There is 1 validated discharge for a given patron' );
95
is( scalar( @{ Koha::Borrower::Discharge::get_validated( { borrowernumber => $borrower->{borrowernumber} } ) } ), 1, 'There is 1 validated discharge for a given patron' );
90
is( scalar( @{ Koha::Borrower::Discharge::get_validated( { branchcode => 'CPL' } ) } ), 2, 'There is 2 validated discharges for a given branchcode' );    # This is not used in the code yet
96
is( scalar( @{ Koha::Borrower::Discharge::get_validated( { branchcode => $library->{branchcode} } ) } ), 2, 'There is 2 validated discharges for a given branchcode' );    # This is not used in the code yet
91
Koha::Borrower::Debarments::DelUniqueDebarment( { 'borrowernumber' => $borrower->{borrowernumber}, 'type' => 'DISCHARGE' } );
97
Koha::Borrower::Debarments::DelUniqueDebarment( { 'borrowernumber' => $borrower->{borrowernumber}, 'type' => 'DISCHARGE' } );
92
ok( !Koha::Borrower::Debarments::IsDebarred( $borrower->{borrowernumber} ), 'The debarment has been lifted' );
98
ok( !Koha::Borrower::Debarments::IsDebarred( $borrower->{borrowernumber} ), 'The debarment has been lifted' );
93
ok( !Koha::Borrower::Discharge::is_discharged( { borrowernumber => $borrower->{borrowernumber} } ), 'The patron is not discharged after the restriction has been lifted' );
99
ok( !Koha::Borrower::Discharge::is_discharged( { borrowernumber => $borrower->{borrowernumber} } ), 'The patron is not discharged after the restriction has been lifted' );
(-)a/t/db_dependent/Borrower_Files.t (-5 / +11 lines)
Lines 22-44 use Modern::Perl; Link Here
22
use C4::Context;
22
use C4::Context;
23
use C4::Members;
23
use C4::Members;
24
24
25
use Koha::Database;
26
use t::lib::TestBuilder;
27
25
use Test::More tests => 23;
28
use Test::More tests => 23;
26
29
27
use_ok('Koha::Borrower::Files');
30
use_ok('Koha::Borrower::Files');
28
31
32
my $schema = Koha::Database->schema;
33
$schema->storage->txn_begin;
34
my $builder = t::lib::TestBuilder->new;
29
my $dbh = C4::Context->dbh;
35
my $dbh = C4::Context->dbh;
30
$dbh->{AutoCommit} = 0;
31
$dbh->{RaiseError} = 1;
32
36
33
$dbh->do(q|DELETE FROM issues|);
37
$dbh->do(q|DELETE FROM issues|);
34
$dbh->do(q|DELETE FROM borrowers|);
38
$dbh->do(q|DELETE FROM borrowers|);
35
$dbh->do(q|DELETE FROM borrower_files|);
39
$dbh->do(q|DELETE FROM borrower_files|);
36
40
41
my $library = $builder->build({
42
    source => 'Branch',
43
});
44
37
my $borrowernumber = AddMember(
45
my $borrowernumber = AddMember(
38
    firstname =>  'my firstname',
46
    firstname =>  'my firstname',
39
    surname => 'my surname',
47
    surname => 'my surname',
40
    categorycode => 'S',
48
    categorycode => 'S',
41
    branchcode => 'CPL',
49
    branchcode => $library->{branchcode},
42
);
50
);
43
51
44
my $bf = Koha::Borrower::Files->new(
52
my $bf = Koha::Borrower::Files->new(
Lines 118-122 $bf->DelFile( Link Here
118
);
126
);
119
$files = $bf->GetFilesInfo();
127
$files = $bf->GetFilesInfo();
120
is( @$files, 0, 'DelFile delete a file' );
128
is( @$files, 0, 'DelFile delete a file' );
121
122
$dbh->rollback;
(-)a/t/db_dependent/Budgets.t (-10 / +12 lines)
Lines 11-33 use C4::Acquisition; Link Here
11
use C4::Members qw( AddMember );
11
use C4::Members qw( AddMember );
12
12
13
use Koha::Acquisition::Order;
13
use Koha::Acquisition::Order;
14
use Koha::Database;
14
15
use t::lib::TestBuilder;
15
16
16
use YAML;
17
use YAML;
17
my $dbh = C4::Context->dbh;
18
my $database = Koha::Database->new();
19
my $schema = $database->schema();
20
$schema->storage->txn_begin();
21
$dbh->{RaiseError} = 1;
22
18
19
my $schema  = Koha::Database->new->schema;
20
$schema->storage->txn_begin;
21
my $builder = t::lib::TestBuilder->new;
22
my $dbh = C4::Context->dbh;
23
$dbh->do(q|DELETE FROM aqbudgetperiods|);
23
$dbh->do(q|DELETE FROM aqbudgetperiods|);
24
$dbh->do(q|DELETE FROM aqbudgets|);
24
$dbh->do(q|DELETE FROM aqbudgets|);
25
25
26
my $library = $builder->build({
27
    source => 'Branch',
28
});
29
26
# Mock userenv
30
# Mock userenv
27
local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /redefined/ };
31
local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /redefined/ };
28
my $userenv;
32
my $userenv;
29
*C4::Context::userenv = \&Mock_userenv;
33
*C4::Context::userenv = \&Mock_userenv;
30
$userenv = { flags => 1, id => 'my_userid', branch => 'CPL' };
34
$userenv = { flags => 1, id => 'my_userid', branch => $library->{branchcode} };
31
35
32
#
36
#
33
# Budget Periods :
37
# Budget Periods :
Lines 530-536 for my $new_budget ( @new_budgets ) { Link Here
530
# Test SetOwnerToFundHierarchy
534
# Test SetOwnerToFundHierarchy
531
535
532
my $categorycode = 'S';
536
my $categorycode = 'S';
533
my $branchcode = 'CPL';
537
my $branchcode = $library->{branchcode};
534
my $john_doe = C4::Members::AddMember(
538
my $john_doe = C4::Members::AddMember(
535
    cardnumber   => '123456',
539
    cardnumber   => '123456',
536
    firstname    => 'John',
540
    firstname    => 'John',
Lines 581-588 is( C4::Budgets::GetBudget($budget_id2)->{budget_owner_id}, Link Here
581
is( C4::Budgets::GetBudget($budget_id21)->{budget_owner_id},
585
is( C4::Budgets::GetBudget($budget_id21)->{budget_owner_id},
582
    undef, "SetOwnerToFundHierarchy should have set John Doe $john_doe for budget 21 ($budget_id21)" );
586
    undef, "SetOwnerToFundHierarchy should have set John Doe $john_doe for budget 21 ($budget_id21)" );
583
587
584
$schema->storage->txn_rollback();
585
586
sub _get_dependencies {
588
sub _get_dependencies {
587
    my ($budget_hierarchy) = @_;
589
    my ($budget_hierarchy) = @_;
588
    my $graph;
590
    my $graph;
(-)a/t/db_dependent/Circulation.t (-24 / +33 lines)
Lines 27-58 use C4::Overdues qw(UpdateFine); Link Here
27
use Koha::DateUtils;
27
use Koha::DateUtils;
28
use Koha::Database;
28
use Koha::Database;
29
29
30
use t::lib::TestBuilder;
31
30
use Test::More tests => 78 ;
32
use Test::More tests => 78 ;
31
33
32
BEGIN {
34
BEGIN {
33
    use_ok('C4::Circulation');
35
    use_ok('C4::Circulation');
34
}
36
}
35
37
38
my $schema = Koha::Database->schema;
39
$schema->storage->txn_begin;
40
my $builder = t::lib::TestBuilder->new;
36
my $dbh = C4::Context->dbh;
41
my $dbh = C4::Context->dbh;
37
my $schema = Koha::Database->new()->schema();
38
42
39
# Start transaction
43
# Start transaction
40
$dbh->{RaiseError} = 1;
44
$dbh->{RaiseError} = 1;
41
$schema->storage->txn_begin();
42
45
43
# Start with a clean slate
46
# Start with a clean slate
44
$dbh->do('DELETE FROM issues');
47
$dbh->do('DELETE FROM issues');
45
48
49
my $library = $builder->build({
50
    source => 'Branch',
51
});
52
my $library2 = $builder->build({
53
    source => 'Branch',
54
});
55
46
my $CircControl = C4::Context->preference('CircControl');
56
my $CircControl = C4::Context->preference('CircControl');
47
my $HomeOrHoldingBranch = C4::Context->preference('HomeOrHoldingBranch');
57
my $HomeOrHoldingBranch = C4::Context->preference('HomeOrHoldingBranch');
48
58
49
my $item = {
59
my $item = {
50
    homebranch => 'MPL',
60
    homebranch => $library2->{branchcode},
51
    holdingbranch => 'MPL'
61
    holdingbranch => $library2->{branchcode}
52
};
62
};
53
63
54
my $borrower = {
64
my $borrower = {
55
    branchcode => 'MPL'
65
    branchcode => $library2->{branchcode}
56
};
66
};
57
67
58
# No userenv, PickupLibrary
68
# No userenv, PickupLibrary
Lines 96-103 is( Link Here
96
106
97
# Now, set a userenv
107
# Now, set a userenv
98
C4::Context->_new_userenv('xxx');
108
C4::Context->_new_userenv('xxx');
99
C4::Context->set_userenv(0,0,0,'firstname','surname', 'MPL', 'Midway Public Library', '', '', '');
109
C4::Context->set_userenv(0,0,0,'firstname','surname', $library2->{branchcode}, 'Midway Public Library', '', '', '');
100
is(C4::Context->userenv->{branch}, 'MPL', 'userenv set');
110
is(C4::Context->userenv->{branch}, $library2->{branchcode}, 'userenv set');
101
111
102
# Userenv set, PickupLibrary
112
# Userenv set, PickupLibrary
103
C4::Context->set_preference('CircControl', 'PickupLibrary');
113
C4::Context->set_preference('CircControl', 'PickupLibrary');
Lines 108-114 is( Link Here
108
);
118
);
109
is(
119
is(
110
    C4::Circulation::_GetCircControlBranch($item, $borrower),
120
    C4::Circulation::_GetCircControlBranch($item, $borrower),
111
    'MPL',
121
    $library2->{branchcode},
112
    '_GetCircControlBranch returned current branch'
122
    '_GetCircControlBranch returned current branch'
113
);
123
);
114
124
Lines 174-180 my $sth = C4::Context->dbh->prepare("SELECT COUNT(*) FROM accountlines WHERE amo Link Here
174
$sth->execute();
184
$sth->execute();
175
my ( $original_count ) = $sth->fetchrow_array();
185
my ( $original_count ) = $sth->fetchrow_array();
176
186
177
C4::Context->dbh->do("INSERT INTO borrowers ( cardnumber, surname, firstname, categorycode, branchcode ) VALUES ( '99999999999', 'Hall', 'Kyle', 'S', 'MPL' )");
187
C4::Context->dbh->do("INSERT INTO borrowers ( cardnumber, surname, firstname, categorycode, branchcode ) VALUES ( '99999999999', 'Hall', 'Kyle', 'S', ? )", undef, $library2->{branchcode} );
178
188
179
C4::Circulation::ProcessOfflinePayment({ cardnumber => '99999999999', amount => '123.45' });
189
C4::Circulation::ProcessOfflinePayment({ cardnumber => '99999999999', amount => '123.45' });
180
190
Lines 200-206 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
200
    my ($biblionumber, $biblioitemnumber) = AddBiblio($biblio, '');
210
    my ($biblionumber, $biblioitemnumber) = AddBiblio($biblio, '');
201
211
202
    my $barcode = 'R00000342';
212
    my $barcode = 'R00000342';
203
    my $branch = 'MPL';
213
    my $branch = $library2->{branchcode};
204
214
205
    my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
215
    my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
206
        {
216
        {
Lines 502-508 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
502
512
503
    LostItem( $itemnumber, 1 );
513
    LostItem( $itemnumber, 1 );
504
514
505
    my $item = $schema->resultset('Item')->find( $itemnumber );
515
    my $item = Koha::Database->new()->schema()->resultset('Item')->find($itemnumber);
506
    ok( !$item->onloan(), "Lost item marked as returned has false onloan value" );
516
    ok( !$item->onloan(), "Lost item marked as returned has false onloan value" );
507
517
508
    my $total_due = $dbh->selectrow_array(
518
    my $total_due = $dbh->selectrow_array(
Lines 522-528 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
522
532
523
    LostItem( $itemnumber2, 0 );
533
    LostItem( $itemnumber2, 0 );
524
534
525
    my $item2 = $schema->resultset('Item')->find( $itemnumber2 );
535
    my $item2 = Koha::Database->new()->schema()->resultset('Item')->find($itemnumber2);
526
    ok( $item2->onloan(), "Lost item *not* marked as returned has true onloan value" );
536
    ok( $item2->onloan(), "Lost item *not* marked as returned has true onloan value" );
527
537
528
    $total_due = $dbh->selectrow_array(
538
    $total_due = $dbh->selectrow_array(
Lines 535-541 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
535
    my $now = dt_from_string();
545
    my $now = dt_from_string();
536
    my $future = dt_from_string();
546
    my $future = dt_from_string();
537
    $future->add( days => 7 );
547
    $future->add( days => 7 );
538
    my $units = C4::Overdues::get_chargeable_units('days', $future, $now, 'MPL');
548
    my $units = C4::Overdues::get_chargeable_units('days', $future, $now, $library2->{branchcode});
539
    ok( $units == 0, '_get_chargeable_units returns 0 for items not past due date (Bug 12596)' );
549
    ok( $units == 0, '_get_chargeable_units returns 0 for items not past due date (Bug 12596)' );
540
550
541
    # Users cannot renew any item if there is an overdue item
551
    # Users cannot renew any item if there is an overdue item
Lines 552-558 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
552
    my $barcode  = 'R00000342';
562
    my $barcode  = 'R00000342';
553
    my $barcode2 = 'R00000343';
563
    my $barcode2 = 'R00000343';
554
    my $barcode3 = 'R00000344';
564
    my $barcode3 = 'R00000344';
555
    my $branch   = 'MPL';
565
    my $branch   = $library2->{branchcode};
556
566
557
    #Create another record
567
    #Create another record
558
    my $biblio2 = MARC::Record->new();
568
    my $biblio2 = MARC::Record->new();
Lines 637-643 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
637
647
638
{
648
{
639
    my $barcode  = '1234567890';
649
    my $barcode  = '1234567890';
640
    my $branch   = 'MPL';
650
    my $branch   = $library2->{branchcode};
641
651
642
    my $biblio = MARC::Record->new();
652
    my $biblio = MARC::Record->new();
643
    my ($biblionumber, $biblioitemnumber) = AddBiblio($biblio, '');
653
    my ($biblionumber, $biblioitemnumber) = AddBiblio($biblio, '');
Lines 692-699 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
692
    my $barcode1 = '1234';
702
    my $barcode1 = '1234';
693
    my ( undef, undef, $itemnumber1 ) = AddItem(
703
    my ( undef, undef, $itemnumber1 ) = AddItem(
694
        {
704
        {
695
            homebranch    => 'MPL',
705
            homebranch    => $library2->{branchcode},
696
            holdingbranch => 'MPL',
706
            holdingbranch => $library2->{branchcode},
697
            barcode       => $barcode1,
707
            barcode       => $barcode1,
698
        },
708
        },
699
        $biblionumber
709
        $biblionumber
Lines 701-708 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
701
    my $barcode2 = '4321';
711
    my $barcode2 = '4321';
702
    my ( undef, undef, $itemnumber2 ) = AddItem(
712
    my ( undef, undef, $itemnumber2 ) = AddItem(
703
        {
713
        {
704
            homebranch    => 'MPL',
714
            homebranch    => $library2->{branchcode},
705
            holdingbranch => 'MPL',
715
            holdingbranch => $library2->{branchcode},
706
            barcode       => $barcode2,
716
            barcode       => $barcode2,
707
        },
717
        },
708
        $biblionumber
718
        $biblionumber
Lines 712-724 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
712
        firstname    => 'Kyle',
722
        firstname    => 'Kyle',
713
        surname      => 'Hall',
723
        surname      => 'Hall',
714
        categorycode => 'S',
724
        categorycode => 'S',
715
        branchcode   => 'MPL',
725
        branchcode   => $library2->{branchcode},
716
    );
726
    );
717
    my $borrowernumber2 = AddMember(
727
    my $borrowernumber2 = AddMember(
718
        firstname    => 'Chelsea',
728
        firstname    => 'Chelsea',
719
        surname      => 'Hall',
729
        surname      => 'Hall',
720
        categorycode => 'S',
730
        categorycode => 'S',
721
        branchcode   => 'MPL',
731
        branchcode   => $library2->{branchcode},
722
    );
732
    );
723
733
724
    my $borrower1 = GetMember( borrowernumber => $borrowernumber1 );
734
    my $borrower1 = GetMember( borrowernumber => $borrowernumber1 );
Lines 730-736 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
730
    is( $renewokay, 1, 'Bug 14337 - Verify the borrower can renew with no hold on the record' );
740
    is( $renewokay, 1, 'Bug 14337 - Verify the borrower can renew with no hold on the record' );
731
741
732
    AddReserve(
742
    AddReserve(
733
        'MPL', $borrowernumber2, $biblionumber,
743
        $library2->{branchcode}, $borrowernumber2, $biblionumber,
734
        '',  1, undef, undef, '',
744
        '',  1, undef, undef, '',
735
        undef, undef, undef
745
        undef, undef, undef
736
    );
746
    );
Lines 765-771 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
765
{
775
{
766
    # Don't allow renewing onsite checkout
776
    # Don't allow renewing onsite checkout
767
    my $barcode  = 'R00000XXX';
777
    my $barcode  = 'R00000XXX';
768
    my $branch   = 'CPL';
778
    my $branch   = $library->{branchcode};
769
779
770
    #Create another record
780
    #Create another record
771
    my $biblio = MARC::Record->new();
781
    my $biblio = MARC::Record->new();
Lines 798-802 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
798
    is( $error, 'onsite_checkout', 'A correct error code should be returned by CanBookBeRenewed for on-site checkout' );
808
    is( $error, 'onsite_checkout', 'A correct error code should be returned by CanBookBeRenewed for on-site checkout' );
799
}
809
}
800
810
801
$schema->storage->txn_rollback();
802
1;
811
1;
(-)a/t/db_dependent/Circulation/IsItemIssued.t (-8 / +14 lines)
Lines 5-25 use C4::Biblio; Link Here
5
use C4::Circulation;
5
use C4::Circulation;
6
use C4::Items;
6
use C4::Items;
7
use C4::Members;
7
use C4::Members;
8
use Koha::Database;
8
use Koha::DateUtils;
9
use Koha::DateUtils;
9
10
11
use t::lib::TestBuilder;
12
10
use MARC::Record;
13
use MARC::Record;
11
14
12
*C4::Context::userenv = \&Mock_userenv;
15
*C4::Context::userenv = \&Mock_userenv;
13
16
17
my $schema = Koha::Database->schema;
18
$schema->storage->txn_begin;
19
my $builder = t::lib::TestBuilder->new;
14
my $dbh = C4::Context->dbh;
20
my $dbh = C4::Context->dbh;
15
$dbh->{AutoCommit} = 0;
21
16
$dbh->{RaiseError} = 1;
22
my $library = $builder->build({
23
    source => 'Branch',
24
});
17
25
18
my $borrowernumber = AddMember(
26
my $borrowernumber = AddMember(
19
    firstname =>  'my firstname',
27
    firstname =>  'my firstname',
20
    surname => 'my surname',
28
    surname => 'my surname',
21
    categorycode => 'S',
29
    categorycode => 'S',
22
    branchcode => 'CPL',
30
    branchcode => $library->{branchcode},
23
);
31
);
24
32
25
33
Lines 27-33 my $borrower = GetMember( borrowernumber => $borrowernumber ); Link Here
27
my $record = MARC::Record->new();
35
my $record = MARC::Record->new();
28
my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, '' );
36
my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, '' );
29
37
30
my ( undef, undef, $itemnumber ) = AddItem( { homebranch => 'CPL', holdingbranch => 'CPL', barcode => 'i_dont_exist' }, $biblionumber );
38
my ( undef, undef, $itemnumber ) = AddItem( { homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, barcode => 'i_dont_exist' }, $biblionumber );
31
my $item = GetItem( $itemnumber );
39
my $item = GetItem( $itemnumber );
32
40
33
is ( IsItemIssued( $item->{itemnumber} ), 0, "item is not on loan at first" );
41
is ( IsItemIssued( $item->{itemnumber} ), 0, "item is not on loan at first" );
Lines 41-47 is( Link Here
41
    'item that is on loan cannot be deleted',
49
    'item that is on loan cannot be deleted',
42
);
50
);
43
51
44
AddReturn('i_dont_exist', 'CPL');
52
AddReturn('i_dont_exist', $library->{branchcode});
45
is ( IsItemIssued( $item->{itemnumber} ), 0, "item has been returned" );
53
is ( IsItemIssued( $item->{itemnumber} ), 0, "item has been returned" );
46
54
47
is(
55
is(
Lines 50-58 is( Link Here
50
    'item that is not on loan can be deleted',
58
    'item that is not on loan can be deleted',
51
);
59
);
52
60
53
$dbh->rollback;
54
55
# C4::Context->userenv
61
# C4::Context->userenv
56
sub Mock_userenv {
62
sub Mock_userenv {
57
    return { branch => 'CPL' };
63
    return { branch => $library->{branchcode} };
58
}
64
}
(-)a/t/db_dependent/Circulation/IssuingRules/maxsuspensiondays.t (-2 / +12 lines)
Lines 10-22 use C4::Biblio qw( AddBiblio ); Link Here
10
use C4::Circulation qw( AddIssue AddReturn );
10
use C4::Circulation qw( AddIssue AddReturn );
11
use C4::Items qw( AddItem );
11
use C4::Items qw( AddItem );
12
use C4::Members qw( AddMember GetMember );
12
use C4::Members qw( AddMember GetMember );
13
use Koha::Database;
13
use Koha::DateUtils;
14
use Koha::DateUtils;
14
use Koha::Borrower::Debarments qw( GetDebarments DelDebarment );
15
use Koha::Borrower::Debarments qw( GetDebarments DelDebarment );
16
17
use t::lib::TestBuilder;
18
19
my $schema = Koha::Database->schema;
20
$schema->storage->txn_begin;
21
my $builder = t::lib::TestBuilder->new;
15
my $dbh = C4::Context->dbh;
22
my $dbh = C4::Context->dbh;
16
$dbh->{RaiseError} = 1;
23
$dbh->{RaiseError} = 1;
17
$dbh->{AutoCommit} = 0;
18
24
19
my $branchcode = 'CPL';
25
my $library = $builder->build({
26
    source => 'Branch',
27
});
28
29
my $branchcode = $library->{branchcode};
20
local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /redefined/ };
30
local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /redefined/ };
21
my $userenv->{branch} = $branchcode;
31
my $userenv->{branch} = $branchcode;
22
*C4::Context::userenv = \&Mock_userenv;
32
*C4::Context::userenv = \&Mock_userenv;
(-)a/t/db_dependent/Circulation/Returns.t (-8 / +15 lines)
Lines 5-27 use C4::Biblio; Link Here
5
use C4::Circulation;
5
use C4::Circulation;
6
use C4::Items;
6
use C4::Items;
7
use C4::Members;
7
use C4::Members;
8
use Koha::Database;
8
use Koha::DateUtils;
9
use Koha::DateUtils;
9
10
11
use t::lib::TestBuilder;
12
10
use MARC::Record;
13
use MARC::Record;
11
14
12
*C4::Context::userenv = \&Mock_userenv;
15
*C4::Context::userenv = \&Mock_userenv;
13
16
14
my $dbh = C4::Context->dbh;
17
my $schema = Koha::Database->schema;
15
$dbh->{AutoCommit} = 0;
18
$schema->storage->txn_begin;
16
$dbh->{RaiseError} = 1;
19
my $builder = t::lib::TestBuilder->new;
20
21
my $library = $builder->build({
22
    source => 'Branch',
23
});
17
24
18
my $record = MARC::Record->new();
25
my $record = MARC::Record->new();
19
my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, '' );
26
my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, '' );
20
27
21
my ( undef, undef, $itemnumber ) = AddItem(
28
my ( undef, undef, $itemnumber ) = AddItem(
22
    {
29
    {
23
        homebranch         => 'CPL',
30
        homebranch         => $library->{branchcode},
24
        holdingbranch      => 'CPL',
31
        holdingbranch      => $library->{branchcode},
25
        barcode            => 'i_dont_exist',
32
        barcode            => 'i_dont_exist',
26
        location           => 'PROC',
33
        location           => 'PROC',
27
        permanent_location => 'TEST'
34
        permanent_location => 'TEST'
Lines 32-38 my ( undef, undef, $itemnumber ) = AddItem( Link Here
32
my $item;
39
my $item;
33
40
34
C4::Context->set_preference( "InProcessingToShelvingCart", 1 );
41
C4::Context->set_preference( "InProcessingToShelvingCart", 1 );
35
AddReturn( 'i_dont_exist', 'CPL' );
42
AddReturn( 'i_dont_exist', $library->{branchcode} );
36
$item = GetItem($itemnumber);
43
$item = GetItem($itemnumber);
37
is( $item->{location}, 'CART', "InProcessingToShelvingCart functions as intended" );
44
is( $item->{location}, 'CART', "InProcessingToShelvingCart functions as intended" );
38
45
Lines 40-50 $item->{location} = 'PROC'; Link Here
40
ModItem( $item, undef, $itemnumber );
47
ModItem( $item, undef, $itemnumber );
41
48
42
C4::Context->set_preference( "InProcessingToShelvingCart", 0 );
49
C4::Context->set_preference( "InProcessingToShelvingCart", 0 );
43
AddReturn( 'i_dont_exist', 'CPL' );
50
AddReturn( 'i_dont_exist', $library->{branchcode} );
44
$item = GetItem($itemnumber);
51
$item = GetItem($itemnumber);
45
is( $item->{location}, 'TEST', "InProcessingToShelvingCart functions as intended" );
52
is( $item->{location}, 'TEST', "InProcessingToShelvingCart functions as intended" );
46
53
47
# C4::Context->userenv
54
# C4::Context->userenv
48
sub Mock_userenv {
55
sub Mock_userenv {
49
    return { branch => 'CPL' };
56
    return { branch => $library->{branchcode} };
50
}
57
}
(-)a/t/db_dependent/Circulation_transfers.t (-47 / +13 lines)
Lines 6-14 use C4::Context; Link Here
6
use C4::Items;
6
use C4::Items;
7
use C4::Branch;
7
use C4::Branch;
8
use C4::Circulation;
8
use C4::Circulation;
9
use Koha::Database;
9
use Koha::DateUtils;
10
use Koha::DateUtils;
10
use DateTime::Duration;
11
use DateTime::Duration;
11
12
13
use t::lib::TestBuilder;
14
12
use Test::More tests => 22;
15
use Test::More tests => 22;
13
use Test::Deep;
16
use Test::Deep;
14
17
Lines 26-36 can_ok( Link Here
26
      )
29
      )
27
);
30
);
28
31
29
#Start transaction
32
my $schema = Koha::Database->schema;
30
my $dbh = C4::Context->dbh;
33
$schema->storage->txn_begin;
31
$dbh->{RaiseError} = 1;
34
my $builder = t::lib::TestBuilder->new;
32
$dbh->{AutoCommit} = 0;
33
35
36
my $dbh = C4::Context->dbh;
34
$dbh->do(q|DELETE FROM issues|);
37
$dbh->do(q|DELETE FROM issues|);
35
$dbh->do(q|DELETE FROM borrowers|);
38
$dbh->do(q|DELETE FROM borrowers|);
36
$dbh->do(q|DELETE FROM items|);
39
$dbh->do(q|DELETE FROM items|);
Lines 40-85 $dbh->do(q|DELETE FROM branchtransfers|); Link Here
40
43
41
#Add sample datas
44
#Add sample datas
42
#Add branches
45
#Add branches
43
my $samplebranch1 = {
46
my $samplebranch1 = $builder->build({
44
    add            => 1,
47
    source => 'Branch',
45
    branchcode     => 'SAB1',
48
});
46
    branchname     => 'Sample Branch',
49
my $samplebranch2 = $builder->build({
47
    branchaddress1 => 'sample adr1',
50
    source => 'Branch',
48
    branchaddress2 => 'sample adr2',
51
});
49
    branchaddress3 => 'sample adr3',
50
    branchzip      => 'sample zip',
51
    branchcity     => 'sample city',
52
    branchstate    => 'sample state',
53
    branchcountry  => 'sample country',
54
    branchphone    => 'sample phone',
55
    branchfax      => 'sample fax',
56
    branchemail    => 'sample email',
57
    branchurl      => 'sample url',
58
    branchip       => 'sample ip',
59
    branchprinter  => undef,
60
    opac_info      => 'sample opac',
61
};
62
my $samplebranch2 = {
63
    add            => 1,
64
    branchcode     => 'SAB2',
65
    branchname     => 'Sample Branch2',
66
    branchaddress1 => 'sample adr1_2',
67
    branchaddress2 => 'sample adr2_2',
68
    branchaddress3 => 'sample adr3_2',
69
    branchzip      => 'sample zip2',
70
    branchcity     => 'sample city2',
71
    branchstate    => 'sample state2',
72
    branchcountry  => 'sample country2',
73
    branchphone    => 'sample phone2',
74
    branchfax      => 'sample fax2',
75
    branchemail    => 'sample email2',
76
    branchurl      => 'sample url2',
77
    branchip       => 'sample ip2',
78
    branchprinter  => undef,
79
    opac_info      => 'sample opac2',
80
};
81
ModBranch($samplebranch1);
82
ModBranch($samplebranch2);
83
52
84
#Add biblio and items
53
#Add biblio and items
85
my $record = MARC::Record->new();
54
my $record = MARC::Record->new();
Lines 208-213 cmp_deeply( Link Here
208
    C4::Circulation::TransferSlip($samplebranch1->{branchcode}, undef, 1, $samplebranch2->{branchcode}),
177
    C4::Circulation::TransferSlip($samplebranch1->{branchcode}, undef, 1, $samplebranch2->{branchcode}),
209
    "Barcode and itemnumber for same item both generate same TransferSlip"
178
    "Barcode and itemnumber for same item both generate same TransferSlip"
210
    );
179
    );
211
212
#End transaction
213
$dbh->rollback;
(-)a/t/db_dependent/CourseReserves.t (-7 / +12 lines)
Lines 7-12 use Modern::Perl; Link Here
7
7
8
use Test::More tests => 21;
8
use Test::More tests => 21;
9
9
10
use Koha::Database;
11
use t::lib::TestBuilder;
12
10
BEGIN {
13
BEGIN {
11
    use_ok('C4::Biblio');
14
    use_ok('C4::Biblio');
12
    use_ok('C4::Context');
15
    use_ok('C4::Context');
Lines 16-27 BEGIN { Link Here
16
    use_ok('MARC::Record');
19
    use_ok('MARC::Record');
17
}
20
}
18
21
22
my $schema = Koha::Database->schema;
23
$schema->storage->txn_begin;
24
my $builder = t::lib::TestBuilder->new;
19
my $dbh = C4::Context->dbh;
25
my $dbh = C4::Context->dbh;
20
21
# Start transaction
22
$dbh->{AutoCommit} = 0;
23
$dbh->{RaiseError} = 1;
26
$dbh->{RaiseError} = 1;
24
27
28
my $library = $builder->build({
29
    source => 'Branch',
30
});
31
25
my $sth = $dbh->prepare("SELECT * FROM borrowers ORDER BY RAND() LIMIT 10");
32
my $sth = $dbh->prepare("SELECT * FROM borrowers ORDER BY RAND() LIMIT 10");
26
$sth->execute();
33
$sth->execute();
27
my @borrowers = @{ $sth->fetchall_arrayref( {} ) };
34
my @borrowers = @{ $sth->fetchall_arrayref( {} ) };
Lines 29-38 my @borrowers = @{ $sth->fetchall_arrayref( {} ) }; Link Here
29
# Create the item
36
# Create the item
30
my $record = MARC::Record->new();
37
my $record = MARC::Record->new();
31
$record->append_fields(
38
$record->append_fields(
32
    MARC::Field->new( '952', '0', '0', a => 'CPL', b => 'CPL' )
39
    MARC::Field->new( '952', '0', '0', a => $library->{branchcode}, b => $library->{branchcode} )
33
);
40
);
34
my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio($record, '');
41
my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio($record, '');
35
my @iteminfo = C4::Items::AddItem( { homebranch => 'CPL', holdingbranch => 'CPL' }, $biblionumber );
42
my @iteminfo = C4::Items::AddItem( { homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode} }, $biblionumber );
36
my $itemnumber = $iteminfo[2];
43
my $itemnumber = $iteminfo[2];
37
44
38
my $course_id = ModCourse(
45
my $course_id = ModCourse(
Lines 90-94 ok( !defined( $course_reserve->{'cr_id'} ), "DelCourseReserve functions correctl Link Here
90
DelCourse($course_id);
97
DelCourse($course_id);
91
$course = GetCourse($course_id);
98
$course = GetCourse($course_id);
92
ok( !defined( $course->{'course_id'} ), "DelCourse deleted course successfully" );
99
ok( !defined( $course->{'course_id'} ), "DelCourse deleted course successfully" );
93
94
$dbh->rollback;
(-)a/t/db_dependent/Creators/Lib.t (-9 / +21 lines)
Lines 21-26 use Graphics::Magick; Link Here
21
use Test::More tests => 644;
21
use Test::More tests => 644;
22
use Test::MockModule;
22
use Test::MockModule;
23
use t::lib::Mocks;
23
use t::lib::Mocks;
24
use t::lib::TestBuilder;
25
use Koha::Database;
24
use Test::Warn;
26
use Test::Warn;
25
27
26
BEGIN {
28
BEGIN {
Lines 50-58 can_ok( Link Here
50
      html_table )
52
      html_table )
51
);
53
);
52
54
55
my $schema = Koha::Database->schema;
56
$schema->storage->txn_begin;
57
my $builder = t::lib::TestBuilder->new;
58
53
my $dbh = C4::Context->dbh;
59
my $dbh = C4::Context->dbh;
54
$dbh->{AutoCommit} = 0;
55
$dbh->{RaiseError} = 1;
56
$dbh->do('DELETE FROM issues');
60
$dbh->do('DELETE FROM issues');
57
$dbh->do('DELETE FROM creator_templates');
61
$dbh->do('DELETE FROM creator_templates');
58
$dbh->do('DELETE FROM creator_layouts');
62
$dbh->do('DELETE FROM creator_layouts');
Lines 67-72 $dbh->do('DELETE FROM biblioitems'); Link Here
67
#                     Inserted data
71
#                     Inserted data
68
###########################################################
72
###########################################################
69
73
74
my $library1 = $builder->build({
75
    source => 'Branch',
76
});
77
my $library2 = $builder->build({
78
    source => 'Branch',
79
});
80
my $library3 = $builder->build({
81
    source => 'Branch',
82
});
83
70
# ---------- Some Templates  --------------------
84
# ---------- Some Templates  --------------------
71
my $query = '
85
my $query = '
72
  INSERT INTO creator_templates
86
  INSERT INTO creator_templates
Lines 226-236 $query = ' Link Here
226
     timestamp, branch_code, creator)
240
     timestamp, branch_code, creator)
227
  VALUES (?,?,?,?,?,?)';
241
  VALUES (?,?,?,?,?,?)';
228
$insert_sth = $dbh->prepare($query);
242
$insert_sth = $dbh->prepare($query);
229
$insert_sth->execute( 11, $item_number1, $borrowernumber1, 'now()', 'CPL', 'Labels' );
243
$insert_sth->execute( 11, $item_number1, $borrowernumber1, 'now()', $library1->{branchcode}, 'Labels' );
230
244
231
$insert_sth->execute( 12, $item_number2, $borrowernumber2, 'now()', 'MPL', 'Labels' );
245
$insert_sth->execute( 12, $item_number2, $borrowernumber2, 'now()', $library2->{branchcode}, 'Labels' );
232
246
233
$insert_sth->execute( 12, $item_number3, $borrowernumber3, 'now()', 'PVL', 'Labels' );
247
$insert_sth->execute( 12, $item_number3, $borrowernumber3, 'now()', $library3->{branchcode}, 'Labels' );
234
248
235
###########################################################
249
###########################################################
236
#                     Testing Subs
250
#                     Testing Subs
Lines 792-798 is( $batches->[1]->{batch_id}, 12, 'batch_id is good' ); Link Here
792
is( $batches->[1]->{_item_count}, $count, 'item_number   is good for this batch_id' );
806
is( $batches->[1]->{_item_count}, $count, 'item_number   is good for this batch_id' );
793
807
794
# Without filter & creator params -----
808
# Without filter & creator params -----
795
$batches = get_batch_summary( filter => 'branch_code=\'MPL\'', creator => 'Labels' );
809
$batches = get_batch_summary( filter => "branch_code='$library1->{branchcode}'", creator => 'Labels' );
796
is( @$batches, 1, 'There is 1 batch matching' );
810
is( @$batches, 1, 'There is 1 batch matching' );
797
811
798
$query = '
812
$query = '
Lines 802-808 $query = ' Link Here
802
    AND    branch_code = ?
816
    AND    branch_code = ?
803
  GROUP BY batch_id
817
  GROUP BY batch_id
804
  ';
818
  ';
805
my ( $id, $nb ) = $dbh->selectrow_array( $query, {}, 'Labels', 'MPL' );
819
my ( $id, $nb ) = $dbh->selectrow_array( $query, {}, 'Labels', $library1->{branchcode} );
806
820
807
is( $batches->[0]->{batch_id},    $id, 'batch_id    is good' );
821
is( $batches->[0]->{batch_id},    $id, 'batch_id    is good' );
808
is( $batches->[0]->{_item_count}, $nb, 'item_number is good for this batch_id' );
822
is( $batches->[0]->{_item_count}, $nb, 'item_number is good for this batch_id' );
Lines 1443-1447 sub mock_preference { Link Here
1443
        }
1457
        }
1444
    );
1458
    );
1445
}
1459
}
1446
1447
$dbh->rollback;
(-)a/t/db_dependent/Holds/LocalHoldsPriority.t (-6 / +21 lines)
Lines 11-16 use MARC::Record; Link Here
11
use C4::Biblio;
11
use C4::Biblio;
12
use C4::Items;
12
use C4::Items;
13
use C4::Members;
13
use C4::Members;
14
use Koha::Database;
15
16
use t::lib::TestBuilder;
14
17
15
BEGIN {
18
BEGIN {
16
    use FindBin;
19
    use FindBin;
Lines 18-28 BEGIN { Link Here
18
    use_ok('C4::Reserves');
21
    use_ok('C4::Reserves');
19
}
22
}
20
23
21
my $dbh = C4::Context->dbh;
24
my $schema = Koha::Database->schema;
25
$schema->storage->txn_begin;
26
27
my $builder = t::lib::TestBuilder->new;
22
28
23
# Start transaction
29
my $library1 = $builder->build({
24
$dbh->{AutoCommit} = 0;
30
    source => 'Branch',
25
$dbh->{RaiseError} = 1;
31
});
32
my $library2 = $builder->build({
33
    source => 'Branch',
34
});
35
my $library3 = $builder->build({
36
    source => 'Branch',
37
});
38
my $library4 = $builder->build({
39
    source => 'Branch',
40
});
26
41
27
my $borrowers_count = 5;
42
my $borrowers_count = 5;
28
43
Lines 30-38 my $borrowers_count = 5; Link Here
30
my ( $bibnum, $title, $bibitemnum ) = create_helper_biblio();
45
my ( $bibnum, $title, $bibitemnum ) = create_helper_biblio();
31
# Create a helper item for the biblio.
46
# Create a helper item for the biblio.
32
my ( $item_bibnum, $item_bibitemnum, $itemnumber ) =
47
my ( $item_bibnum, $item_bibitemnum, $itemnumber ) =
33
  AddItem( { homebranch => 'MPL', holdingbranch => 'CPL' }, $bibnum );
48
  AddItem( { homebranch => $library4->{branchcode}, holdingbranch => $library3->{branchcode} }, $bibnum );
34
49
35
my @branchcodes = qw{XXX RPL CPL MPL CPL MPL};
50
my @branchcodes = ( $library1->{branchcode}, $library2->{branchcode}, $library3->{branchcode}, $library4->{branchcode}, $library3->{branchcode}, $library4->{branchcode} );
36
51
37
# Create some borrowers
52
# Create some borrowers
38
my @borrowernumbers;
53
my @borrowernumbers;
(-)a/t/db_dependent/Holds/RevertWaitingStatus.t (-6 / +12 lines)
Lines 13-32 use C4::Items; Link Here
13
use C4::Members;
13
use C4::Members;
14
use C4::Reserves;
14
use C4::Reserves;
15
15
16
my $dbh = C4::Context->dbh;
16
use t::lib::TestBuilder;
17
17
18
# Start transaction
18
my $schema = Koha::Database->schema;
19
$dbh->{AutoCommit} = 0;
19
$schema->storage->txn_begin;
20
my $builder = t::lib::TestBuilder->new;
21
my $dbh = C4::Context->dbh;
20
$dbh->{RaiseError} = 1;
22
$dbh->{RaiseError} = 1;
21
23
22
$dbh->do("DELETE FROM reserves");
24
$dbh->do("DELETE FROM reserves");
23
$dbh->do("DELETE FROM old_reserves");
25
$dbh->do("DELETE FROM old_reserves");
24
26
27
my $library = $builder->build({
28
    source => 'Branch',
29
});
30
25
local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /redefined/ };
31
local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /redefined/ };
26
*C4::Context::userenv = \&Mock_userenv;
32
*C4::Context::userenv = \&Mock_userenv;
27
33
28
sub Mock_userenv {
34
sub Mock_userenv {
29
    my $userenv = { flags => 1, id => '1', branch => 'CPL' };
35
    my $userenv = { flags => 1, id => '1', branch => $library->{branchcode} };
30
    return $userenv;
36
    return $userenv;
31
}
37
}
32
38
Lines 41-47 my ( $bibnum, $title, $bibitemnum ) = create_helper_biblio(); Link Here
41
diag("Creating item instance for testing.");
47
diag("Creating item instance for testing.");
42
my $item_barcode = 'my_barcode';
48
my $item_barcode = 'my_barcode';
43
my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
49
my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
44
    { homebranch => 'CPL', holdingbranch => 'CPL', barcode => $item_barcode },
50
    { homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, barcode => $item_barcode },
45
    $bibnum );
51
    $bibnum );
46
52
47
# Create some borrowers
53
# Create some borrowers
Lines 51-57 foreach my $i ( 1 .. $borrowers_count ) { Link Here
51
        firstname    => 'my firstname',
57
        firstname    => 'my firstname',
52
        surname      => 'my surname ' . $i,
58
        surname      => 'my surname ' . $i,
53
        categorycode => 'S',
59
        categorycode => 'S',
54
        branchcode   => 'CPL',
60
        branchcode   => $library->{branchcode},
55
    );
61
    );
56
    push @borrowernumbers, $borrowernumber;
62
    push @borrowernumbers, $borrowernumber;
57
}
63
}
(-)a/t/db_dependent/HoldsQueue.t (-61 / +70 lines)
Lines 14-23 use Data::Dumper; Link Here
14
14
15
use Test::More tests => 22;
15
use Test::More tests => 22;
16
16
17
18
use C4::Branch;
17
use C4::Branch;
19
use C4::ItemType;
18
use C4::ItemType;
20
use C4::Members;
19
use C4::Members;
20
use Koha::Database;
21
22
use t::lib::TestBuilder;
21
23
22
BEGIN {
24
BEGIN {
23
    use FindBin;
25
    use FindBin;
Lines 26-54 BEGIN { Link Here
26
    use_ok('C4::HoldsQueue');
28
    use_ok('C4::HoldsQueue');
27
}
29
}
28
30
29
# Start transaction
31
my $schema = Koha::Database->schema;
32
$schema->storage->txn_begin;
30
my $dbh = C4::Context->dbh;
33
my $dbh = C4::Context->dbh;
31
$dbh->{AutoCommit} = 0;
34
32
$dbh->{RaiseError} = 1;
35
my $builder = t::lib::TestBuilder->new;
36
37
my $library1 = $builder->build({
38
    source => 'Branch',
39
});
40
my $library2 = $builder->build({
41
    source => 'Branch',
42
});
43
my $library3 = $builder->build({
44
    source => 'Branch',
45
});
33
46
34
my $TITLE = "Test Holds Queue XXX";
47
my $TITLE = "Test Holds Queue XXX";
35
48
36
my %data = (
49
my $borrower = $builder->build({
37
    cardnumber => 'CARDNUMBER42',
50
    source => 'Borrower',
38
    firstname =>  'my firstname',
51
    value => {
39
    surname => 'my surname',
52
        categorycode => 'S',
40
    categorycode => 'S',
53
        branchcode => $library1->{branchcode},
41
    branchcode => 'CPL',
54
    }
42
);
55
});
43
56
44
my $borrowernumber = AddMember(%data);
57
my $borrowernumber = $borrower->{borrowernumber};
45
my $borrower = GetMember( borrowernumber => $borrowernumber );
46
# Set special (for this test) branches
58
# Set special (for this test) branches
47
my $borrower_branchcode = $borrower->{branchcode};
59
my $borrower_branchcode = $borrower->{branchcode};
48
my $branches = C4::Branch::GetBranches;
60
my @branchcodes = ( $library1->{branchcode}, $library2->{branchcode}, $library3->{branchcode} );
49
my @other_branches = grep { $_ ne $borrower_branchcode } keys %$branches;
61
my @other_branches = ( $library2->{branchcode}, $library3->{branchcode} );
50
my $least_cost_branch_code = pop @other_branches
62
my $least_cost_branch_code = pop @other_branches;
51
  or BAIL_OUT("No point testing only one branch...");
52
my @item_types = C4::ItemType->all;
63
my @item_types = C4::ItemType->all;
53
my $itemtype = grep { $_->{notforloan} == 1 } @item_types
64
my $itemtype = grep { $_->{notforloan} == 1 } @item_types
54
  or BAIL_OUT("No adequate itemtype");
65
  or BAIL_OUT("No adequate itemtype");
Lines 155-162 ok( Link Here
155
# XXX All this tests are for borrower branch pick-up.
166
# XXX All this tests are for borrower branch pick-up.
156
# Maybe needs expanding to homebranch or holdingbranch pick-up.
167
# Maybe needs expanding to homebranch or holdingbranch pick-up.
157
168
158
# Cleanup
169
$schema->txn_rollback;
159
$dbh->rollback;
170
$schema->txn_begin;
160
171
161
### Test holds queue builder does not violate holds policy ###
172
### Test holds queue builder does not violate holds policy ###
162
173
Lines 167-205 $dbh->do("DELETE FROM default_circ_rules"); Link Here
167
178
168
C4::Context->set_preference('UseTransportCostMatrix', 0);
179
C4::Context->set_preference('UseTransportCostMatrix', 0);
169
180
170
my @branchcodes = keys %$branches;
171
( $itemtype ) = @{ $dbh->selectrow_arrayref("SELECT itemtype FROM itemtypes LIMIT 1") };
181
( $itemtype ) = @{ $dbh->selectrow_arrayref("SELECT itemtype FROM itemtypes LIMIT 1") };
172
182
173
my $borrowernumber1 = AddMember(
183
$library1 = $builder->build({
174
    (
184
    source => 'Branch',
175
        cardnumber   => 'CARDNUMBER1',
185
});
176
        firstname    => 'Firstname',
186
$library2 = $builder->build({
177
        surname      => 'Surname',
187
    source => 'Branch',
188
});
189
$library3 = $builder->build({
190
    source => 'Branch',
191
});
192
@branchcodes = ( $library1->{branchcode}, $library2->{branchcode}, $library3->{branchcode} );
193
194
my $borrower1 = $builder->build({
195
    source => 'Borrower',
196
    value => {
178
        categorycode => 'S',
197
        categorycode => 'S',
179
        branchcode   => $branchcodes[0],
198
        branchcode => $branchcodes[0],
180
    )
199
    },
181
);
200
});
182
my $borrowernumber2 = AddMember(
201
my $borrower2 = $builder->build({
183
    (
202
    source => 'Borrower',
184
        cardnumber   => 'CARDNUMBER2',
203
    value => {
185
        firstname    => 'Firstname',
186
        surname      => 'Surname',
187
        categorycode => 'S',
204
        categorycode => 'S',
188
        branchcode   => $branchcodes[1],
205
        branchcode => $branchcodes[1],
189
    )
206
    },
190
);
207
});
191
my $borrowernumber3 = AddMember(
208
my $borrower3 = $builder->build({
192
    (
209
    source => 'Borrower',
193
        cardnumber   => 'CARDNUMBER3',
210
    value => {
194
        firstname    => 'Firstname',
195
        surname      => 'Surname',
196
        categorycode => 'S',
211
        categorycode => 'S',
197
        branchcode   => $branchcodes[2],
212
        branchcode => $branchcodes[2],
198
    )
213
    },
199
);
214
});
200
my $borrower1 = GetMember( borrowernumber => $borrowernumber1 );
201
my $borrower2 = GetMember( borrowernumber => $borrowernumber2 );
202
my $borrower3 = GetMember( borrowernumber => $borrowernumber3 );
203
215
204
$dbh->do(qq{
216
$dbh->do(qq{
205
    INSERT INTO biblio (
217
    INSERT INTO biblio (
Lines 277-284 my $sth = $dbh->prepare(q{ Link Here
277
$sth->execute( $borrower1->{borrowernumber}, $biblionumber, $branchcodes[0], 1 );
289
$sth->execute( $borrower1->{borrowernumber}, $biblionumber, $branchcodes[0], 1 );
278
$sth->execute( $borrower2->{borrowernumber}, $biblionumber, $branchcodes[0], 2 );
290
$sth->execute( $borrower2->{borrowernumber}, $biblionumber, $branchcodes[0], 2 );
279
$sth->execute( $borrower3->{borrowernumber}, $biblionumber, $branchcodes[0], 3 );
291
$sth->execute( $borrower3->{borrowernumber}, $biblionumber, $branchcodes[0], 3 );
280
#warn "RESERVES" . Data::Dumper::Dumper( $dbh->selectall_arrayref("SELECT * FROM reserves", { Slice => {} }) );
281
#warn "ITEMS: " . Data::Dumper::Dumper( $dbh->selectall_arrayref("SELECT * FROM items WHERE biblionumber = $biblionumber", { Slice => {} }) );
282
292
283
my $holds_queue;
293
my $holds_queue;
284
294
Lines 286-310 $dbh->do("DELETE FROM default_circ_rules"); Link Here
286
$dbh->do("INSERT INTO default_circ_rules ( holdallowed ) VALUES ( 1 )");
296
$dbh->do("INSERT INTO default_circ_rules ( holdallowed ) VALUES ( 1 )");
287
C4::HoldsQueue::CreateQueue();
297
C4::HoldsQueue::CreateQueue();
288
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
298
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
289
ok( @$holds_queue == 2, "Holds queue filling correct number for default holds policy 'from home library'" );
299
is( @$holds_queue, 2, "Holds queue filling correct number for default holds policy 'from home library'" );
290
ok( $holds_queue->[0]->{cardnumber} eq 'CARDNUMBER1', "Holds queue filling 1st correct hold for default holds policy 'from home library'");
300
is( $holds_queue->[0]->{cardnumber}, $borrower1->{cardnumber}, "Holds queue filling 1st correct hold for default holds policy 'from home library'");
291
ok( $holds_queue->[1]->{cardnumber} eq 'CARDNUMBER2', "Holds queue filling 2nd correct hold for default holds policy 'from home library'");
301
is( $holds_queue->[1]->{cardnumber}, $borrower2->{cardnumber}, "Holds queue filling 2nd correct hold for default holds policy 'from home library'");
292
302
293
$dbh->do("DELETE FROM default_circ_rules");
303
$dbh->do("DELETE FROM default_circ_rules");
294
$dbh->do("INSERT INTO default_circ_rules ( holdallowed ) VALUES ( 2 )");
304
$dbh->do("INSERT INTO default_circ_rules ( holdallowed ) VALUES ( 2 )");
295
C4::HoldsQueue::CreateQueue();
305
C4::HoldsQueue::CreateQueue();
296
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
306
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
297
ok( @$holds_queue == 3, "Holds queue filling correct number for holds for default holds policy 'from any library'" );
307
is( @$holds_queue, 3, "Holds queue filling correct number for holds for default holds policy 'from any library'" );
298
#warn "HOLDS QUEUE: " . Data::Dumper::Dumper( $holds_queue );
308
#warn "HOLDS QUEUE: " . Data::Dumper::Dumper( $holds_queue );
299
309
300
# Bug 14297
310
# Bug 14297
301
$borrowernumber = AddMember(%data);
302
$borrower = GetMember( borrowernumber => $borrowernumber );
303
$borrower_branchcode = $borrower->{branchcode};
304
$itemtype = $item_types[0]->{itemtype};
311
$itemtype = $item_types[0]->{itemtype};
305
my $library_A = 'CPL';
312
$borrowernumber = $borrower3->{borrowernumber};
306
my $library_B = 'FFL';
313
my $library_A = $library1->{branchcode};
307
my $library_C = 'MPL'; # Same as our borrower's home library
314
my $library_B = $library2->{branchcode};
315
my $library_C = $borrower3->{branchcode};
308
$dbh->do("DELETE FROM reserves");
316
$dbh->do("DELETE FROM reserves");
309
$dbh->do("DELETE FROM issues");
317
$dbh->do("DELETE FROM issues");
310
$dbh->do("DELETE FROM items");
318
$dbh->do("DELETE FROM items");
Lines 353-363 $dbh->do( "UPDATE systempreferences SET value = 0 WHERE variable = 'RandomizeHol Link Here
353
my $reserve_id = AddReserve ( $library_C, $borrowernumber, $biblionumber, '', 1 );
361
my $reserve_id = AddReserve ( $library_C, $borrowernumber, $biblionumber, '', 1 );
354
C4::HoldsQueue::CreateQueue();
362
C4::HoldsQueue::CreateQueue();
355
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
363
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
356
is( @$holds_queue, 1, "Bug 14297 - Holds Queue building ignoring holds where pickup & home branch don't match and item is not from least cost branch" );
364
is( @$holds_queue, 1, "Bug 14297 - Holds Queue building ignoring holds where pickup & home branch don't match and item is not from le");
357
# End Bug 14297
365
# End Bug 14297
358
366
367
359
# Cleanup
368
# Cleanup
360
$dbh->rollback;
369
$schema->storage->txn_rollback;
361
370
362
### END Test holds queue builder does not violate holds policy ###
371
### END Test holds queue builder does not violate holds policy ###
363
372
(-)a/t/db_dependent/Items.t (-57 / +89 lines)
Lines 24-29 use C4::Branch; Link Here
24
use Koha::Database;
24
use Koha::Database;
25
25
26
use t::lib::Mocks;
26
use t::lib::Mocks;
27
use t::lib::TestBuilder;
27
28
28
use Test::More tests => 9;
29
use Test::More tests => 9;
29
30
Lines 34-43 BEGIN { Link Here
34
    use_ok('Koha::Items');
35
    use_ok('Koha::Items');
35
}
36
}
36
37
37
my $schema  = Koha::Database->new->schema;
38
my $schema = Koha::Database->new->schema;
38
39
my $branches = GetBranches;
40
my ($branch1, $branch2) = keys %$branches;
41
my $location = 'My Location';
39
my $location = 'My Location';
42
40
43
subtest 'General Add, Get and Del tests' => sub {
41
subtest 'General Add, Get and Del tests' => sub {
Lines 46-57 subtest 'General Add, Get and Del tests' => sub { Link Here
46
44
47
    $schema->storage->txn_begin;
45
    $schema->storage->txn_begin;
48
46
47
    my $builder = t::lib::TestBuilder->new;
48
    my $library = $builder->build({
49
        source => 'Branch',
50
    });
51
49
    # Create a biblio instance for testing
52
    # Create a biblio instance for testing
50
    C4::Context->set_preference('marcflavour', 'MARC21');
53
    C4::Context->set_preference('marcflavour', 'MARC21');
51
    my ($bibnum, $bibitemnum) = get_biblio();
54
    my ($bibnum, $bibitemnum) = get_biblio();
52
55
53
    # Add an item.
56
    # Add an item.
54
    my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch1, holdingbranch => $branch1, location => $location } , $bibnum);
57
    my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location } , $bibnum);
55
    cmp_ok($item_bibnum, '==', $bibnum, "New item is linked to correct biblionumber.");
58
    cmp_ok($item_bibnum, '==', $bibnum, "New item is linked to correct biblionumber.");
56
    cmp_ok($item_bibitemnum, '==', $bibitemnum, "New item is linked to correct biblioitemnumber.");
59
    cmp_ok($item_bibitemnum, '==', $bibitemnum, "New item is linked to correct biblioitemnumber.");
57
60
Lines 72-78 subtest 'General Add, Get and Del tests' => sub { Link Here
72
    my $getdeleted = GetItem($itemnumber);
75
    my $getdeleted = GetItem($itemnumber);
73
    is($getdeleted->{'itemnumber'}, undef, "Item deleted as expected.");
76
    is($getdeleted->{'itemnumber'}, undef, "Item deleted as expected.");
74
77
75
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch1, holdingbranch => $branch1, location => $location, permanent_location => 'my permanent location' } , $bibnum);
78
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, permanent_location => 'my permanent location' } , $bibnum);
76
    $getitem = GetItem($itemnumber);
79
    $getitem = GetItem($itemnumber);
77
    is( $getitem->{location}, $location, "The location should not have been modified" );
80
    is( $getitem->{location}, $location, "The location should not have been modified" );
78
    is( $getitem->{permanent_location}, 'my permanent location', "The permanent_location should not have modified" );
81
    is( $getitem->{permanent_location}, 'my permanent location', "The permanent_location should not have modified" );
Lines 98-125 subtest 'GetHiddenItemnumbers tests' => sub { Link Here
98
101
99
    $schema->storage->txn_begin;
102
    $schema->storage->txn_begin;
100
103
104
    my $builder = t::lib::TestBuilder->new;
105
    my $library1 = $builder->build({
106
        source => 'Branch',
107
    });
108
109
    my $library2 = $builder->build({
110
        source => 'Branch',
111
    });
112
101
    # Create a new biblio
113
    # Create a new biblio
102
    C4::Context->set_preference('marcflavour', 'MARC21');
114
    C4::Context->set_preference('marcflavour', 'MARC21');
103
    my ($biblionumber, $biblioitemnumber) = get_biblio();
115
    my ($biblionumber, $biblioitemnumber) = get_biblio();
104
116
105
    # Add branches if they don't exist
106
    if (not defined GetBranchDetail('CPL')) {
107
        ModBranch({add => 1, branchcode => 'CPL', branchname => 'Centerville'});
108
    }
109
    if (not defined GetBranchDetail('MPL')) {
110
        ModBranch({add => 1, branchcode => 'MPL', branchname => 'Midway'});
111
    }
112
113
    # Add two items
117
    # Add two items
114
    my ($item1_bibnum, $item1_bibitemnum, $item1_itemnumber) = AddItem(
118
    my ($item1_bibnum, $item1_bibitemnum, $item1_itemnumber) = AddItem(
115
            { homebranch => $branch1,
119
            { homebranch => $library1->{branchcode},
116
              holdingbranch => $branch1,
120
              holdingbranch => $library1->{branchcode},
117
              withdrawn => 1 },
121
              withdrawn => 1 },
118
            $biblionumber
122
            $biblionumber
119
    );
123
    );
120
    my ($item2_bibnum, $item2_bibitemnum, $item2_itemnumber) = AddItem(
124
    my ($item2_bibnum, $item2_bibitemnum, $item2_itemnumber) = AddItem(
121
            { homebranch => $branch2,
125
            { homebranch => $library2->{branchcode},
122
              holdingbranch => $branch2,
126
              holdingbranch => $library2->{branchcode},
123
              withdrawn => 0 },
127
              withdrawn => 0 },
124
            $biblionumber
128
            $biblionumber
125
    );
129
    );
Lines 160-171 subtest 'GetHiddenItemnumbers tests' => sub { Link Here
160
    # Two variables, a value each
164
    # Two variables, a value each
161
    $opachiddenitems = "
165
    $opachiddenitems = "
162
        withdrawn: [1]
166
        withdrawn: [1]
163
        homebranch: [$branch2]
167
        homebranch: [$library2->{branchcode}]
164
    ";
168
    ";
165
    C4::Context->set_preference( 'OpacHiddenItems', $opachiddenitems );
169
    C4::Context->set_preference( 'OpacHiddenItems', $opachiddenitems );
166
    @hidden = GetHiddenItemnumbers( @items );
170
    @hidden = GetHiddenItemnumbers( @items );
167
    ok( scalar @hidden == 2, "Two items hidden");
171
    ok( scalar @hidden == 2, "Two items hidden");
168
    is_deeply( \@hidden, \@itemnumbers, "withdrawn=1 and homebranch=MPL hidden");
172
    is_deeply( \@hidden, \@itemnumbers, "withdrawn=1 and homebranch library2 hidden");
169
173
170
    # Valid OpacHiddenItems, empty list
174
    # Valid OpacHiddenItems, empty list
171
    @items = ();
175
    @items = ();
Lines 181-200 subtest 'GetItemsInfo tests' => sub { Link Here
181
185
182
    $schema->storage->txn_begin;
186
    $schema->storage->txn_begin;
183
187
188
    my $builder = t::lib::TestBuilder->new;
189
    my $library1 = $builder->build({
190
        source => 'Branch',
191
    });
192
    my $library2 = $builder->build({
193
        source => 'Branch',
194
    });
195
184
    # Add a biblio
196
    # Add a biblio
185
    my ($biblionumber, $biblioitemnumber) = get_biblio();
197
    my ($biblionumber, $biblioitemnumber) = get_biblio();
186
    # Add an item
198
    # Add an item
187
    my ($item_bibnum, $item_bibitemnum, $itemnumber)
199
    my ($item_bibnum, $item_bibitemnum, $itemnumber)
188
        = AddItem({
200
        = AddItem({
189
                homebranch    => $branch1,
201
                homebranch    => $library1->{branchcode},
190
                holdingbranch => $branch2
202
                holdingbranch => $library2->{branchcode},
191
            }, $biblionumber );
203
            }, $biblionumber );
192
204
193
    my $branch = GetBranchDetail( $branch1 );
205
    my $branch = GetBranchDetail( $library1->{branchcode} );
194
    $branch->{ opac_info } = "homebranch OPAC info";
206
    $branch->{ opac_info } = "homebranch OPAC info";
195
    ModBranch($branch);
207
    ModBranch($branch);
196
208
197
    $branch = GetBranchDetail( $branch2 );
209
    $branch = GetBranchDetail( $library2->{branchcode} );
198
    $branch->{ opac_info } = "holdingbranch OPAC info";
210
    $branch->{ opac_info } = "holdingbranch OPAC info";
199
    ModBranch($branch);
211
    ModBranch($branch);
200
212
Lines 259-288 subtest 'SearchItems test' => sub { Link Here
259
271
260
    $schema->storage->txn_begin;
272
    $schema->storage->txn_begin;
261
    my $dbh = C4::Context->dbh;
273
    my $dbh = C4::Context->dbh;
274
    my $builder = t::lib::TestBuilder->new;
275
276
    my $library1 = $builder->build({
277
        source => 'Branch',
278
    });
279
    my $library2 = $builder->build({
280
        source => 'Branch',
281
    });
262
282
263
    C4::Context->set_preference('marcflavour', 'MARC21');
283
    C4::Context->set_preference('marcflavour', 'MARC21');
264
    my $cpl_items_before = SearchItemsByField( 'homebranch', 'CPL');
284
    my $cpl_items_before = SearchItemsByField( 'homebranch', $library1->{branchcode});
265
285
266
    my ($biblionumber) = get_biblio();
286
    my ($biblionumber) = get_biblio();
267
287
268
    # Add branches if they don't exist
269
    if (not defined GetBranchDetail('CPL')) {
270
        ModBranch({add => 1, branchcode => 'CPL', branchname => 'Centerville'});
271
    }
272
    if (not defined GetBranchDetail('MPL')) {
273
        ModBranch({add => 1, branchcode => 'MPL', branchname => 'Midway'});
274
    }
275
276
    my (undef, $initial_items_count) = SearchItems(undef, {rows => 1});
288
    my (undef, $initial_items_count) = SearchItems(undef, {rows => 1});
277
289
278
    # Add two items
290
    # Add two items
279
    my (undef, undef, $item1_itemnumber) = AddItem({
291
    my (undef, undef, $item1_itemnumber) = AddItem({
280
        homebranch => 'CPL',
292
        homebranch => $library1->{branchcode},
281
        holdingbranch => 'CPL',
293
        holdingbranch => $library1->{branchcode},
282
    }, $biblionumber);
294
    }, $biblionumber);
283
    my (undef, undef, $item2_itemnumber) = AddItem({
295
    my (undef, undef, $item2_itemnumber) = AddItem({
284
        homebranch => 'MPL',
296
        homebranch => $library2->{branchcode},
285
        holdingbranch => 'MPL',
297
        holdingbranch => $library2->{branchcode},
286
    }, $biblionumber);
298
    }, $biblionumber);
287
299
288
    my ($items, $total_results);
300
    my ($items, $total_results);
Lines 298-311 subtest 'SearchItems test' => sub { Link Here
298
    # Search all items where homebranch = 'CPL'
310
    # Search all items where homebranch = 'CPL'
299
    my $filter = {
311
    my $filter = {
300
        field => 'homebranch',
312
        field => 'homebranch',
301
        query => 'CPL',
313
        query => $library1->{branchcode},
302
        operator => '=',
314
        operator => '=',
303
    };
315
    };
304
    ($items, $total_results) = SearchItems($filter);
316
    ($items, $total_results) = SearchItems($filter);
305
    ok($total_results > 0, "There is at least one CPL item");
317
    ok($total_results > 0, "There is at least one CPL item");
306
    my $all_items_are_CPL = 1;
318
    my $all_items_are_CPL = 1;
307
    foreach my $item (@$items) {
319
    foreach my $item (@$items) {
308
        if ($item->{homebranch} ne 'CPL') {
320
        if ($item->{homebranch} ne $library1->{branchcode}) {
309
            $all_items_are_CPL = 0;
321
            $all_items_are_CPL = 0;
310
            last;
322
            last;
311
        }
323
        }
Lines 315-328 subtest 'SearchItems test' => sub { Link Here
315
    # Search all items where homebranch != 'CPL'
327
    # Search all items where homebranch != 'CPL'
316
    $filter = {
328
    $filter = {
317
        field => 'homebranch',
329
        field => 'homebranch',
318
        query => 'CPL',
330
        query => $library1->{branchcode},
319
        operator => '!=',
331
        operator => '!=',
320
    };
332
    };
321
    ($items, $total_results) = SearchItems($filter);
333
    ($items, $total_results) = SearchItems($filter);
322
    ok($total_results > 0, "There is at least one non-CPL item");
334
    ok($total_results > 0, "There is at least one non-CPL item");
323
    my $all_items_are_not_CPL = 1;
335
    my $all_items_are_not_CPL = 1;
324
    foreach my $item (@$items) {
336
    foreach my $item (@$items) {
325
        if ($item->{homebranch} eq 'CPL') {
337
        if ($item->{homebranch} eq $library1->{branchcode}) {
326
            $all_items_are_not_CPL = 0;
338
            $all_items_are_not_CPL = 0;
327
            last;
339
            last;
328
        }
340
        }
Lines 350-356 subtest 'SearchItems test' => sub { Link Here
350
            },
362
            },
351
            {
363
            {
352
                field => 'homebranch',
364
                field => 'homebranch',
353
                query => 'CPL',
365
                query => $library1->{branchcode},
354
                operator => '=',
366
                operator => '=',
355
            },
367
            },
356
        ],
368
        ],
Lines 411-417 subtest 'SearchItems test' => sub { Link Here
411
    ($items, $total_results) = SearchItems($filter);
423
    ($items, $total_results) = SearchItems($filter);
412
    ok(scalar @$items == 1, 'found 1 item with itemnotes = "foobar"');
424
    ok(scalar @$items == 1, 'found 1 item with itemnotes = "foobar"');
413
425
414
    my $cpl_items_after = SearchItemsByField( 'homebranch', 'CPL');
426
    my $cpl_items_after = SearchItemsByField( 'homebranch', $library1->{branchcode});
415
    is( ( scalar( @$cpl_items_after ) - scalar ( @$cpl_items_before ) ), 1, 'SearchItemsByField should return something' );
427
    is( ( scalar( @$cpl_items_after ) - scalar ( @$cpl_items_before ) ), 1, 'SearchItemsByField should return something' );
416
428
417
    $schema->storage->txn_rollback;
429
    $schema->storage->txn_rollback;
Lines 423-432 subtest 'Koha::Item(s) tests' => sub { Link Here
423
435
424
    $schema->storage->txn_begin();
436
    $schema->storage->txn_begin();
425
437
438
    my $builder = t::lib::TestBuilder->new;
439
    my $library1 = $builder->build({
440
        source => 'Branch',
441
    });
442
    my $library2 = $builder->build({
443
        source => 'Branch',
444
    });
445
426
    # Create a biblio and item for testing
446
    # Create a biblio and item for testing
427
    C4::Context->set_preference('marcflavour', 'MARC21');
447
    C4::Context->set_preference('marcflavour', 'MARC21');
428
    my ($bibnum, $bibitemnum) = get_biblio();
448
    my ($bibnum, $bibitemnum) = get_biblio();
429
    my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch1, holdingbranch => $branch2 } , $bibnum);
449
    my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library1->{branchcode}, holdingbranch => $library2->{branchcode} } , $bibnum);
430
450
431
    # Get item.
451
    # Get item.
432
    my $item = Koha::Items->find( $itemnumber );
452
    my $item = Koha::Items->find( $itemnumber );
Lines 434-444 subtest 'Koha::Item(s) tests' => sub { Link Here
434
454
435
    my $homebranch = $item->home_branch();
455
    my $homebranch = $item->home_branch();
436
    is( ref($homebranch), 'Koha::Branch', "Got Koha::Branch from home_branch method" );
456
    is( ref($homebranch), 'Koha::Branch', "Got Koha::Branch from home_branch method" );
437
    is( $homebranch->branchcode(), $branch1, "Home branch code matches homebranch" );
457
    is( $homebranch->branchcode(), $library1->{branchcode}, "Home branch code matches homebranch" );
438
458
439
    my $holdingbranch = $item->holding_branch();
459
    my $holdingbranch = $item->holding_branch();
440
    is( ref($holdingbranch), 'Koha::Branch', "Got Koha::Branch from holding_branch method" );
460
    is( ref($holdingbranch), 'Koha::Branch', "Got Koha::Branch from holding_branch method" );
441
    is( $holdingbranch->branchcode(), $branch2, "Home branch code matches holdingbranch" );
461
    is( $holdingbranch->branchcode(), $library2->{branchcode}, "Home branch code matches holdingbranch" );
462
463
    $schema->storage->txn_rollback;
442
};
464
};
443
465
444
subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub {
466
subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub {
Lines 446-465 subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { Link Here
446
468
447
    $schema->storage->txn_begin();
469
    $schema->storage->txn_begin();
448
470
471
    my $builder = t::lib::TestBuilder->new;
472
    my $library1 = $builder->build({
473
        source => 'Branch',
474
    });
475
    my $library2 = $builder->build({
476
        source => 'Branch',
477
    });
478
449
    my ( $biblionumber, $biblioitemnumber ) = get_biblio();
479
    my ( $biblionumber, $biblioitemnumber ) = get_biblio();
450
    my $item_infos = [
480
    my $item_infos = [
451
        { homebranch => 'CPL', holdingbranch => 'CPL' },
481
        { homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} },
452
        { homebranch => 'CPL', holdingbranch => 'CPL' },
482
        { homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} },
453
        { homebranch => 'CPL', holdingbranch => 'CPL' },
483
        { homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} },
454
        { homebranch => 'MPL', holdingbranch => 'MPL' },
484
        { homebranch => $library2->{branchcode}, holdingbranch => $library2->{branchcode} },
455
        { homebranch => 'MPL', holdingbranch => 'MPL' },
485
        { homebranch => $library2->{branchcode}, holdingbranch => $library2->{branchcode} },
456
        { homebranch => 'CPL', holdingbranch => 'MPL' },
486
        { homebranch => $library1->{branchcode}, holdingbranch => $library2->{branchcode} },
457
        { homebranch => 'CPL', holdingbranch => 'MPL' },
487
        { homebranch => $library1->{branchcode}, holdingbranch => $library2->{branchcode} },
458
        { homebranch => 'CPL', holdingbranch => 'MPL' },
488
        { homebranch => $library1->{branchcode}, holdingbranch => $library2->{branchcode} },
459
    ];
489
    ];
460
    my $number_of_items = scalar @$item_infos;
490
    my $number_of_items = scalar @$item_infos;
461
    my $number_of_items_with_homebranch_is_CPL =
491
    my $number_of_items_with_homebranch_is_CPL =
462
      grep { $_->{homebranch} eq 'CPL' } @$item_infos;
492
      grep { $_->{homebranch} eq $library1->{branchcode} } @$item_infos;
463
493
464
    my @itemnumbers;
494
    my @itemnumbers;
465
    for my $item_info (@$item_infos) {
495
    for my $item_info (@$item_infos) {
Lines 497-503 subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { Link Here
497
    is( scalar @items, $number_of_items, 'Should return all items for opac' );
527
    is( scalar @items, $number_of_items, 'Should return all items for opac' );
498
528
499
    my $opachiddenitems = "
529
    my $opachiddenitems = "
500
        homebranch: ['CPL']";
530
        homebranch: ['$library1->{branchcode}']";
501
    t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems );
531
    t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems );
502
532
503
    C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber );
533
    C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber );
Lines 515-521 subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { Link Here
515
    );
545
    );
516
546
517
    $opachiddenitems = "
547
    $opachiddenitems = "
518
        homebranch: ['CPL', 'MPL']";
548
        homebranch: ['$library1->{branchcode}', '$library2->{branchcode}']";
519
    t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems );
549
    t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems );
520
    C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, undef, 1 );
550
    C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, undef, 1 );
521
    @items = $record->field($itemfield);
551
    @items = $record->field($itemfield);
Lines 524-529 subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { Link Here
524
        0,
554
        0,
525
'For OPAC, If all items are hidden, no item should have been embeded'
555
'For OPAC, If all items are hidden, no item should have been embeded'
526
    );
556
    );
557
558
    $schema->storage->txn_rollback;
527
};
559
};
528
560
529
# Helper method to set up a Biblio.
561
# Helper method to set up a Biblio.
(-)a/t/db_dependent/Items_DelItem.t (-5 / +11 lines)
Lines 3-23 use Modern::Perl; Link Here
3
use MARC::Record;
3
use MARC::Record;
4
use C4::Biblio;
4
use C4::Biblio;
5
5
6
use t::lib::TestBuilder;
7
6
use Test::More tests => 7;
8
use Test::More tests => 7;
7
9
8
BEGIN {
10
BEGIN {
9
    use_ok('C4::Items');
11
    use_ok('C4::Items');
10
}
12
}
11
13
12
my $dbh = C4::Context->dbh;
14
my $schema = Koha::Database->schema;
13
$dbh->{AutoCommit} = 0;
15
$schema->storage->txn_begin;
14
$dbh->{RaiseError} = 1;
16
my $builder = t::lib::TestBuilder->new;
17
18
my $library = $builder->build({
19
    source => 'Branch',
20
});
15
21
16
my ( $biblionumber, $bibitemnum ) = get_biblio();
22
my ( $biblionumber, $bibitemnum ) = get_biblio();
17
23
18
my ( $item_bibnum, $item_bibitemnum, $itemnumber );
24
my ( $item_bibnum, $item_bibitemnum, $itemnumber );
19
( $item_bibnum, $item_bibitemnum, $itemnumber ) =
25
( $item_bibnum, $item_bibitemnum, $itemnumber ) =
20
  AddItem( { homebranch => 'CPL', holdingbranch => 'CPL' }, $biblionumber );
26
  AddItem( { homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode} }, $biblionumber );
21
27
22
my $deleted = DelItem( { biblionumber => $biblionumber, itemnumber => $itemnumber } );
28
my $deleted = DelItem( { biblionumber => $biblionumber, itemnumber => $itemnumber } );
23
is( $deleted, 1, "DelItem should return 1 if the item has been deleted" );
29
is( $deleted, 1, "DelItem should return 1 if the item has been deleted" );
Lines 25-31 my $deleted_item = GetItem($itemnumber); Link Here
25
is( $deleted_item->{itemnumber}, undef, "DelItem with biblionumber parameter - the item should be deleted." );
31
is( $deleted_item->{itemnumber}, undef, "DelItem with biblionumber parameter - the item should be deleted." );
26
32
27
( $item_bibnum, $item_bibitemnum, $itemnumber ) =
33
( $item_bibnum, $item_bibitemnum, $itemnumber ) =
28
  AddItem( { homebranch => 'CPL', holdingbranch => 'CPL' }, $biblionumber );
34
  AddItem( { homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode} }, $biblionumber );
29
$deleted = DelItem( { biblionumber => $biblionumber, itemnumber => $itemnumber } );
35
$deleted = DelItem( { biblionumber => $biblionumber, itemnumber => $itemnumber } );
30
is( $deleted, 1, "DelItem should return 1 if the item has been deleted" );
36
is( $deleted, 1, "DelItem should return 1 if the item has been deleted" );
31
$deleted_item = GetItem($itemnumber);
37
$deleted_item = GetItem($itemnumber);
(-)a/t/db_dependent/Koha_template_plugin_Branches.t (-3 / +14 lines)
Lines 21-35 use Modern::Perl; Link Here
21
use Test::More tests => 7;
21
use Test::More tests => 7;
22
22
23
use C4::Context;
23
use C4::Context;
24
use Koha::Database;
25
26
use t::lib::TestBuilder;
27
24
BEGIN {
28
BEGIN {
25
    use_ok('Koha::Template::Plugin::Branches');
29
    use_ok('Koha::Template::Plugin::Branches');
26
}
30
}
27
31
32
my $schema = Koha::Database->schema;
33
$schema->storage->txn_begin;
34
my $builder = t::lib::TestBuilder->new;
35
my $library = $builder->build({
36
    source => 'Branch',
37
});
38
28
my $plugin = Koha::Template::Plugin::Branches->new();
39
my $plugin = Koha::Template::Plugin::Branches->new();
29
ok($plugin, "initialized Branches plugin");
40
ok($plugin, "initialized Branches plugin");
30
41
31
my $name = $plugin->GetName('CPL');
42
my $name = $plugin->GetName($library->{branchcode});
32
is($name, 'Centerville', 'retrieved expected name for CPL');
43
is($name, $library->{branchname}, 'retrieved expected name for library');
33
44
34
$name = $plugin->GetName('__ANY__');
45
$name = $plugin->GetName('__ANY__');
35
is($name, '', 'received empty string as name of the "__ANY__" placeholder library code');
46
is($name, '', 'received empty string as name of the "__ANY__" placeholder library code');
Lines 37-43 is($name, '', 'received empty string as name of the "__ANY__" placeholder librar Link Here
37
$name = $plugin->GetName(undef);
48
$name = $plugin->GetName(undef);
38
is($name, '', 'received empty string as name of NULL/undefined library code');
49
is($name, '', 'received empty string as name of NULL/undefined library code');
39
50
40
my $library = $plugin->GetLoggedInBranchcode();
51
$library = $plugin->GetLoggedInBranchcode();
41
is($library, '', 'no active library if there is no active user session');
52
is($library, '', 'no active library if there is no active user session');
42
53
43
C4::Context->_new_userenv('DUMMY_SESSION_ID');
54
C4::Context->_new_userenv('DUMMY_SESSION_ID');
(-)a/t/db_dependent/Letters.t (-21 / +19 lines)
Lines 42-71 use_ok('C4::Biblio'); Link Here
42
use_ok('C4::Bookseller');
42
use_ok('C4::Bookseller');
43
use_ok('C4::Letters');
43
use_ok('C4::Letters');
44
use t::lib::Mocks;
44
use t::lib::Mocks;
45
use t::lib::TestBuilder;
46
use Koha::Database;
45
use Koha::DateUtils qw( dt_from_string output_pref );
47
use Koha::DateUtils qw( dt_from_string output_pref );
46
use Koha::Acquisition::Order;
48
use Koha::Acquisition::Order;
47
use Koha::Acquisition::Bookseller;
49
use Koha::Acquisition::Bookseller;
48
use Koha::Database;
50
my $schema = Koha::Database->schema;
49
50
my $dbh = C4::Context->dbh;
51
52
my $database = Koha::Database->new();
53
my $schema = $database->schema();
54
$schema->storage->txn_begin();
51
$schema->storage->txn_begin();
55
52
56
# Start transaction
53
my $builder = t::lib::TestBuilder->new;
54
my $dbh = C4::Context->dbh;
57
$dbh->{RaiseError} = 1;
55
$dbh->{RaiseError} = 1;
58
56
59
$dbh->do(q|DELETE FROM letter|);
57
$dbh->do(q|DELETE FROM letter|);
60
$dbh->do(q|DELETE FROM message_queue|);
58
$dbh->do(q|DELETE FROM message_queue|);
61
$dbh->do(q|DELETE FROM message_transport_types|);
59
$dbh->do(q|DELETE FROM message_transport_types|);
62
60
61
my $library = $builder->build({
62
    source => 'Branch',
63
});
63
my $date = dt_from_string;
64
my $date = dt_from_string;
64
my $borrowernumber = AddMember(
65
my $borrowernumber = AddMember(
65
    firstname    => 'Jane',
66
    firstname    => 'Jane',
66
    surname      => 'Smith',
67
    surname      => 'Smith',
67
    categorycode => 'PT',
68
    categorycode => 'PT',
68
    branchcode   => 'CPL',
69
    branchcode   => $library->{branchcode},
69
    dateofbirth  => $date,
70
    dateofbirth  => $date,
70
);
71
);
71
72
Lines 157-174 Don't forget your date of birth: <<borrowers.dateofbirth>>. Link Here
157
Look at this wonderful biblio timestamp: <<biblio.timestamp>>.
158
Look at this wonderful biblio timestamp: <<biblio.timestamp>>.
158
};
159
};
159
160
160
$dbh->do( q|INSERT INTO letter(branchcode,module,code,name,is_html,title,content,message_transport_type) VALUES ('CPL','my module','my code','my name',1,?,?,'email')|, undef, $title, $content );
161
$dbh->do( q|INSERT INTO letter(branchcode,module,code,name,is_html,title,content,message_transport_type) VALUES (?,'my module','my code','my name',1,?,?,'email')|, undef, $library->{branchcode}, $title, $content );
161
$letters = C4::Letters::GetLetters();
162
$letters = C4::Letters::GetLetters();
162
is( @$letters, 1, 'GetLetters returns the correct number of letters' );
163
is( @$letters, 1, 'GetLetters returns the correct number of letters' );
163
is( $letters->[0]->{branchcode}, 'CPL', 'GetLetters gets the branch code correctly' );
164
is( $letters->[0]->{branchcode}, $library->{branchcode}, 'GetLetters gets the branch code correctly' );
164
is( $letters->[0]->{module}, 'my module', 'GetLetters gets the module correctly' );
165
is( $letters->[0]->{module}, 'my module', 'GetLetters gets the module correctly' );
165
is( $letters->[0]->{code}, 'my code', 'GetLetters gets the code correctly' );
166
is( $letters->[0]->{code}, 'my code', 'GetLetters gets the code correctly' );
166
is( $letters->[0]->{name}, 'my name', 'GetLetters gets the name correctly' );
167
is( $letters->[0]->{name}, 'my name', 'GetLetters gets the name correctly' );
167
168
168
169
169
# getletter
170
# getletter
170
my $letter = C4::Letters::getletter('my module', 'my code', 'CPL', 'email');
171
my $letter = C4::Letters::getletter('my module', 'my code', $library->{branchcode}, 'email');
171
is( $letter->{branchcode}, 'CPL', 'GetLetters gets the branch code correctly' );
172
is( $letter->{branchcode}, $library->{branchcode}, 'GetLetters gets the branch code correctly' );
172
is( $letter->{module}, 'my module', 'GetLetters gets the module correctly' );
173
is( $letter->{module}, 'my module', 'GetLetters gets the module correctly' );
173
is( $letter->{code}, 'my code', 'GetLetters gets the code correctly' );
174
is( $letter->{code}, 'my code', 'GetLetters gets the code correctly' );
174
is( $letter->{name}, 'my name', 'GetLetters gets the name correctly' );
175
is( $letter->{name}, 'my name', 'GetLetters gets the name correctly' );
Lines 234-244 is( @$alerts, 0, 'delalert removes an alert' ); Link Here
234
t::lib::Mocks::mock_preference('OPACBaseURL', 'http://thisisatest.com');
235
t::lib::Mocks::mock_preference('OPACBaseURL', 'http://thisisatest.com');
235
236
236
my $sms_content = 'This is a SMS for an <<status>>';
237
my $sms_content = 'This is a SMS for an <<status>>';
237
$dbh->do( q|INSERT INTO letter(branchcode,module,code,name,is_html,title,content,message_transport_type) VALUES ('CPL','my module','my code','my name',1,'my title',?,'sms')|, undef, $sms_content );
238
$dbh->do( q|INSERT INTO letter(branchcode,module,code,name,is_html,title,content,message_transport_type) VALUES (?,'my module','my code','my name',1,'my title',?,'sms')|, undef, $library->{branchcode}, $sms_content );
238
239
239
my $tables = {
240
my $tables = {
240
    borrowers => $borrowernumber,
241
    borrowers => $borrowernumber,
241
    branches => 'CPL',
242
    branches => $library->{branchcode},
242
    biblio => $biblionumber,
243
    biblio => $biblionumber,
243
};
244
};
244
my $substitute = {
245
my $substitute = {
Lines 256-268 my $repeat = [ Link Here
256
];
257
];
257
my $prepared_letter = GetPreparedLetter((
258
my $prepared_letter = GetPreparedLetter((
258
    module      => 'my module',
259
    module      => 'my module',
259
    branchcode  => 'CPL',
260
    branchcode  => $library->{branchcode},
260
    letter_code => 'my code',
261
    letter_code => 'my code',
261
    tables      => $tables,
262
    tables      => $tables,
262
    substitute  => $substitute,
263
    substitute  => $substitute,
263
    repeat      => $repeat,
264
    repeat      => $repeat,
264
));
265
));
265
my $branch = GetBranchDetail('CPL');
266
my $branch = GetBranchDetail($library->{branchcode});
266
my $my_title_letter = qq|$branch->{branchname} - $substitute->{status}|;
267
my $my_title_letter = qq|$branch->{branchname} - $substitute->{status}|;
267
my $my_content_letter = qq|Dear Jane Smith,
268
my $my_content_letter = qq|Dear Jane Smith,
268
According to our current records, you have items that are overdue.Your library does not charge late fines, but please return or renew them at the branch below as soon as possible.
269
According to our current records, you have items that are overdue.Your library does not charge late fines, but please return or renew them at the branch below as soon as possible.
Lines 285-291 is( $prepared_letter->{content}, $my_content_letter, 'GetPreparedLetter returns Link Here
285
286
286
$prepared_letter = GetPreparedLetter((
287
$prepared_letter = GetPreparedLetter((
287
    module                 => 'my module',
288
    module                 => 'my module',
288
    branchcode             => 'CPL',
289
    branchcode             => $library->{branchcode},
289
    letter_code            => 'my code',
290
    letter_code            => 'my code',
290
    tables                 => $tables,
291
    tables                 => $tables,
291
    substitute             => $substitute,
292
    substitute             => $substitute,
Lines 418-424 my $borrowernumber = AddMember( Link Here
418
    firstname    => 'John',
419
    firstname    => 'John',
419
    surname      => 'Smith',
420
    surname      => 'Smith',
420
    categorycode => 'PT',
421
    categorycode => 'PT',
421
    branchcode   => 'CPL',
422
    branchcode   => $library->{branchcode},
422
    dateofbirth  => $date,
423
    dateofbirth  => $date,
423
    email        => 'john.smith@test.de',
424
    email        => 'john.smith@test.de',
424
);
425
);
Lines 434-439 is($err2, "", "Successfully sent serial notification"); Link Here
434
is($mail{'To'}, 'john.smith@test.de', "mailto correct in sent serial notification");
435
is($mail{'To'}, 'john.smith@test.de', "mailto correct in sent serial notification");
435
is($mail{'Message'}, 'Silence in the library,'.$subscriptionid.',No. 0', 'Serial notification text constructed successfully');
436
is($mail{'Message'}, 'Silence in the library,'.$subscriptionid.',No. 0', 'Serial notification text constructed successfully');
436
}
437
}
437
438
439
$schema->storage->txn_rollback();
(-)a/t/db_dependent/Members.t (-13 / +17 lines)
Lines 21-42 use Test::More tests => 74; Link Here
21
use Test::MockModule;
21
use Test::MockModule;
22
use Data::Dumper;
22
use Data::Dumper;
23
use C4::Context;
23
use C4::Context;
24
use Koha::Database;
25
26
use t::lib::TestBuilder;
24
27
25
BEGIN {
28
BEGIN {
26
        use_ok('C4::Members');
29
        use_ok('C4::Members');
27
}
30
}
28
31
32
my $schema = Koha::Database->schema;
33
$schema->storage->txn_begin;
34
my $builder = t::lib::TestBuilder->new;
29
my $dbh = C4::Context->dbh;
35
my $dbh = C4::Context->dbh;
30
31
# Start transaction
32
$dbh->{AutoCommit} = 0;
33
$dbh->{RaiseError} = 1;
36
$dbh->{RaiseError} = 1;
34
37
38
my $library1 = $builder->build({
39
    source => 'Branch',
40
});
41
my $library2 = $builder->build({
42
    source => 'Branch',
43
});
35
my $CARDNUMBER   = 'TESTCARD01';
44
my $CARDNUMBER   = 'TESTCARD01';
36
my $FIRSTNAME    = 'Marie';
45
my $FIRSTNAME    = 'Marie';
37
my $SURNAME      = 'Mcknight';
46
my $SURNAME      = 'Mcknight';
38
my $CATEGORYCODE = 'S';
47
my $CATEGORYCODE = 'S';
39
my $BRANCHCODE   = 'CPL';
48
my $BRANCHCODE   = $library1->{branchcode};
40
49
41
my $CHANGED_FIRSTNAME = "Marry Ann";
50
my $CHANGED_FIRSTNAME = "Marry Ann";
42
my $EMAIL             = "Marie\@email.com";
51
my $EMAIL             = "Marie\@email.com";
Lines 46-53 my $PHONE = "555-12123"; Link Here
46
# XXX should be randomised and checked against the database
55
# XXX should be randomised and checked against the database
47
my $IMPOSSIBLE_CARDNUMBER = "XYZZZ999";
56
my $IMPOSSIBLE_CARDNUMBER = "XYZZZ999";
48
57
49
# XXX make a non-commit transaction and rollback rather than insert/delete
50
51
#my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, $emailaddress, $branchprinter)= @_;
58
#my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, $emailaddress, $branchprinter)= @_;
52
my @USERENV = (
59
my @USERENV = (
53
    1,
60
    1,
Lines 212-218 is( $borrower, undef, 'DelMember should remove the patron' ); Link Here
212
    firstname    => "Tomasito",
219
    firstname    => "Tomasito",
213
    surname      => "None",
220
    surname      => "None",
214
    categorycode => "S",
221
    categorycode => "S",
215
    branchcode   => "MPL",
222
    branchcode   => $library2->{branchcode},
216
    dateofbirth  => '',
223
    dateofbirth  => '',
217
    debarred     => '',
224
    debarred     => '',
218
    dateexpiry   => '',
225
    dateexpiry   => '',
Lines 269-278 is( $borrower->{userid}, $data{userid}, 'AddMember should insert the given useri Link Here
269
## Remove all entries with userid='' (should be only 1 max)
276
## Remove all entries with userid='' (should be only 1 max)
270
$dbh->do(q|DELETE FROM borrowers WHERE userid = ''|);
277
$dbh->do(q|DELETE FROM borrowers WHERE userid = ''|);
271
## And create a patron with a userid=''
278
## And create a patron with a userid=''
272
$borrowernumber = AddMember( categorycode => 'S', branchcode => 'MPL' );
279
$borrowernumber = AddMember( categorycode => 'S', branchcode => $library2->{branchcode} );
273
$dbh->do(q|UPDATE borrowers SET userid = '' WHERE borrowernumber = ?|, undef, $borrowernumber);
280
$dbh->do(q|UPDATE borrowers SET userid = '' WHERE borrowernumber = ?|, undef, $borrowernumber);
274
# Create another patron and verify the userid has been generated
281
# Create another patron and verify the userid has been generated
275
$borrowernumber = AddMember( categorycode => 'S', branchcode => 'MPL' );
282
$borrowernumber = AddMember( categorycode => 'S', branchcode => $library2->{branchcode} );
276
ok( $borrowernumber > 0, 'AddMember should have inserted the patron even if no userid is given' );
283
ok( $borrowernumber > 0, 'AddMember should have inserted the patron even if no userid is given' );
277
$borrower = GetMember( borrowernumber => $borrowernumber );
284
$borrower = GetMember( borrowernumber => $borrowernumber );
278
ok( $borrower->{userid},  'A userid should have been generated correctly' );
285
ok( $borrower->{userid},  'A userid should have been generated correctly' );
Lines 329-336 subtest 'GetMemberAccountBalance' => sub { Link Here
329
    is( $total, 15 , "Total calculated correctly");
336
    is( $total, 15 , "Total calculated correctly");
330
    is( $total_minus_charges, 10, "Holds charges are count if HoldsInNoissuesCharge=0");
337
    is( $total_minus_charges, 10, "Holds charges are count if HoldsInNoissuesCharge=0");
331
    is( $other_charges, 5, "Holds charges are considered if HoldsInNoissuesCharge=1");
338
    is( $other_charges, 5, "Holds charges are considered if HoldsInNoissuesCharge=1");
332
333
    $dbh->rollback();
334
};
339
};
335
340
336
subtest 'purgeSelfRegistration' => sub {
341
subtest 'purgeSelfRegistration' => sub {
Lines 350-358 subtest 'purgeSelfRegistration' => sub { Link Here
350
    C4::Context->set_preference('PatronSelfRegistrationDefaultCategory', $c );
355
    C4::Context->set_preference('PatronSelfRegistrationDefaultCategory', $c );
351
    C4::Context->set_preference('PatronSelfRegistrationExpireTemporaryAccountsDelay', 360);
356
    C4::Context->set_preference('PatronSelfRegistrationExpireTemporaryAccountsDelay', 360);
352
    C4::Members::DeleteExpiredOpacRegistrations();
357
    C4::Members::DeleteExpiredOpacRegistrations();
353
    $dbh->do("INSERT INTO borrowers (surname, address, city, branchcode, categorycode, dateenrolled) VALUES ('Testaabbcc', 'Street 1', 'CITY', 'CPL', '$c', '2014-01-01 01:02:03')");
358
    $dbh->do("INSERT INTO borrowers (surname, address, city, branchcode, categorycode, dateenrolled) VALUES ('Testaabbcc', 'Street 1', 'CITY', ?, '$c', '2014-01-01 01:02:03')", undef, $library1->{branchcode});
354
    is( C4::Members::DeleteExpiredOpacRegistrations(), 1, 'Test for DeleteExpiredOpacRegistrations');
359
    is( C4::Members::DeleteExpiredOpacRegistrations(), 1, 'Test for DeleteExpiredOpacRegistrations');
355
    $dbh->rollback();
356
};
360
};
357
361
358
sub _find_member {
362
sub _find_member {
(-)a/t/db_dependent/Members/AddEnrolmentFeeIfNeeded.t (-4 / +11 lines)
Lines 3-13 use Test::More tests => 4; Link Here
3
3
4
use C4::Context;
4
use C4::Context;
5
use C4::Members;
5
use C4::Members;
6
use Koha::Database;
6
7
8
use t::lib::TestBuilder;
9
10
my $schema = Koha::Database->schema;
11
$schema->storage->txn_begin;
12
my $builder = t::lib::TestBuilder->new;
7
my $dbh = C4::Context->dbh;
13
my $dbh = C4::Context->dbh;
8
$dbh->{AutoCommit} = 0;
9
$dbh->{RaiseError} = 1;
14
$dbh->{RaiseError} = 1;
10
15
16
my $library = $builder->build({
17
    source => 'Branch',
18
});
19
11
my $enrolmentfee_K = 5;
20
my $enrolmentfee_K = 5;
12
my $enrolmentfee_J = 10;
21
my $enrolmentfee_J = 10;
13
my $enrolmentfee_YA = 20;
22
my $enrolmentfee_YA = 20;
Lines 34-40 my %borrower_data = ( Link Here
34
    firstname =>  'my firstname',
43
    firstname =>  'my firstname',
35
    surname => 'my surname',
44
    surname => 'my surname',
36
    categorycode => 'K',
45
    categorycode => 'K',
37
    branchcode => 'CPL',
46
    branchcode => $library->{branchcode},
38
);
47
);
39
48
40
my $borrowernumber = C4::Members::AddMember( %borrower_data );
49
my $borrowernumber = C4::Members::AddMember( %borrower_data );
Lines 62-66 is( $total, $enrolmentfee_K + $enrolmentfee_J, "Kid growing and become a juvenil Link Here
62
C4::Members::AddEnrolmentFeeIfNeeded( 'YA', $borrowernumber );
71
C4::Members::AddEnrolmentFeeIfNeeded( 'YA', $borrowernumber );
63
( $total ) = C4::Members::GetMemberAccountRecords( $borrowernumber );
72
( $total ) = C4::Members::GetMemberAccountRecords( $borrowernumber );
64
is( $total, $enrolmentfee_K + $enrolmentfee_J + $enrolmentfee_YA, "Juvenile growing and become an young adult, he should pay " . ( $enrolmentfee_K + $enrolmentfee_J + $enrolmentfee_YA ) );
73
is( $total, $enrolmentfee_K + $enrolmentfee_J + $enrolmentfee_YA, "Juvenile growing and become an young adult, he should pay " . ( $enrolmentfee_K + $enrolmentfee_J + $enrolmentfee_YA ) );
65
66
$dbh->rollback;
(-)a/t/db_dependent/Members_Attributes.t (-4 / +10 lines)
Lines 22-34 use Modern::Perl; Link Here
22
use C4::Context;
22
use C4::Context;
23
use C4::Members;
23
use C4::Members;
24
use C4::Members::AttributeTypes;
24
use C4::Members::AttributeTypes;
25
use Koha::Database;
25
26
26
use Test::More tests => 60;
27
use Test::More tests => 60;
27
28
29
use t::lib::TestBuilder;
30
28
use_ok('C4::Members::Attributes');
31
use_ok('C4::Members::Attributes');
29
32
33
my $schema = Koha::Database->schema;
34
$schema->storage->txn_begin;
35
my $builder = t::lib::TestBuilder->new;
30
my $dbh = C4::Context->dbh;
36
my $dbh = C4::Context->dbh;
31
$dbh->{AutoCommit} = 0;
32
$dbh->{RaiseError} = 1;
37
$dbh->{RaiseError} = 1;
33
38
34
$dbh->do(q|DELETE FROM issues|);
39
$dbh->do(q|DELETE FROM issues|);
Lines 36-46 $dbh->do(q|DELETE FROM borrowers|); Link Here
36
$dbh->do(q|DELETE FROM borrower_attributes|);
41
$dbh->do(q|DELETE FROM borrower_attributes|);
37
$dbh->do(q|DELETE FROM borrower_attribute_types|);
42
$dbh->do(q|DELETE FROM borrower_attribute_types|);
38
43
44
my $library = $builder->build({
45
    source => 'Branch',
46
});
39
my $borrowernumber = AddMember(
47
my $borrowernumber = AddMember(
40
    firstname =>  'my firstname',
48
    firstname =>  'my firstname',
41
    surname => 'my surname',
49
    surname => 'my surname',
42
    categorycode => 'S',
50
    categorycode => 'S',
43
    branchcode => 'CPL',
51
    branchcode => $library->{branchcode},
44
);
52
);
45
53
46
54
Lines 196-200 is( $borrower_attributes->[0]->{password}, $attributes->[1]->{password}, 'Delete Link Here
196
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber, $attributes->[1]);
204
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber, $attributes->[1]);
197
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
205
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
198
is( @$borrower_attributes, 0, 'DeleteBorrowerAttribute deletes a borrower attribute' );
206
is( @$borrower_attributes, 0, 'DeleteBorrowerAttribute deletes a borrower attribute' );
199
200
$dbh->rollback;
(-)a/t/db_dependent/Ratings.t (-3 / +12 lines)
Lines 23-40 use C4::Biblio qw/AddBiblio/; Link Here
23
use C4::Members;
23
use C4::Members;
24
use C4::Context;
24
use C4::Context;
25
use C4::Category;
25
use C4::Category;
26
use Koha::Database;
27
28
use t::lib::TestBuilder;
26
29
27
use_ok('C4::Ratings');
30
use_ok('C4::Ratings');
28
31
32
my $schema = Koha::Database->schema;
33
$schema->storage->txn_begin;
34
my $builder = t::lib::TestBuilder->new;
29
my $dbh = C4::Context->dbh;
35
my $dbh = C4::Context->dbh;
30
$dbh->{RaiseError} = 1;
36
$dbh->{RaiseError} = 1;
31
$dbh->{AutoCommit} = 0;
37
38
my $library = $builder->build({
39
    source => 'Branch',
40
});
32
41
33
my ($biblionumber) = AddBiblio( MARC::Record->new, '' );
42
my ($biblionumber) = AddBiblio( MARC::Record->new, '' );
34
43
35
my @categories   = C4::Category->all;
44
my @categories   = C4::Category->all;
36
my $categorycode = $categories[0]->categorycode;
45
my $categorycode = $categories[0]->categorycode;
37
my $branchcode   = 'CPL';
46
my $branchcode   = $library->{branchcode};
38
47
39
my %john_doe = (
48
my %john_doe = (
40
    cardnumber   => '123456',
49
    cardnumber   => '123456',
Lines 109-112 ok( defined $rating7, 'delete another rating' ); Link Here
109
is( GetRating( $biblionumber, $borrowernumber1 ),
118
is( GetRating( $biblionumber, $borrowernumber1 ),
110
    undef, 'GetRating should return undef if no rating exist' );
119
    undef, 'GetRating should return undef if no rating exist' );
111
120
112
1;
121
1;
(-)a/t/db_dependent/Reserves/GetReserveFee.t (-3 / +6 lines)
Lines 32-43 use Koha::Database; Link Here
32
my $schema = Koha::Database->new->schema;
32
my $schema = Koha::Database->new->schema;
33
$schema->storage->txn_begin;
33
$schema->storage->txn_begin;
34
34
35
my $builder = t::lib::TestBuilder->new();
36
my $library = $builder->build({
37
    source => 'Branch',
38
});
35
my $mContext = new Test::MockModule('C4::Context');
39
my $mContext = new Test::MockModule('C4::Context');
36
$mContext->mock( 'userenv', sub {
40
$mContext->mock( 'userenv', sub {
37
    return { branch => 'CPL' };
41
    return { branch => $library->{branchcode} };
38
});
42
});
39
43
40
my $builder = t::lib::TestBuilder->new();
41
my $dbh = C4::Context->dbh; # after start transaction of testbuilder
44
my $dbh = C4::Context->dbh; # after start transaction of testbuilder
42
45
43
# Category with hold fee, two patrons
46
# Category with hold fee, two patrons
Lines 116-122 sub acctlines { #calculate number of accountlines for a patron Link Here
116
119
117
sub addreserve {
120
sub addreserve {
118
    return AddReserve(
121
    return AddReserve(
119
        'CPL',
122
        $library->{branchcode},
120
        $_[0],
123
        $_[0],
121
        $biblio->{biblionumber},
124
        $biblio->{biblionumber},
122
        undef,
125
        undef,
(-)a/t/db_dependent/Serials_2.t (-5 / +15 lines)
Lines 7-13 use MARC::Record; Link Here
7
7
8
use C4::Biblio qw( AddBiblio );
8
use C4::Biblio qw( AddBiblio );
9
use C4::Members qw( AddMember );
9
use C4::Members qw( AddMember );
10
use Koha::Database;
10
use t::lib::Mocks;
11
use t::lib::Mocks;
12
use t::lib::TestBuilder;
11
use_ok('C4::Serials');
13
use_ok('C4::Serials');
12
use_ok('C4::Budgets');
14
use_ok('C4::Budgets');
13
15
Lines 16-33 local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /redefined/ }; Link Here
16
my $userenv;
18
my $userenv;
17
*C4::Context::userenv = \&Mock_userenv;
19
*C4::Context::userenv = \&Mock_userenv;
18
20
21
my $schema = Koha::Database->schema;
22
$schema->storage->txn_begin;
23
my $builder = t::lib::TestBuilder->new;
24
my $library1 = $builder->build({
25
    source => 'Branch',
26
});
27
my $library2 = $builder->build({
28
    source => 'Branch',
29
});
19
my $dbh = C4::Context->dbh;
30
my $dbh = C4::Context->dbh;
20
$dbh->{AutoCommit} = 0;
21
$dbh->{RaiseError} = 1;
31
$dbh->{RaiseError} = 1;
22
32
23
my $record = MARC::Record->new();
33
my $record = MARC::Record->new();
24
$record->append_fields(
34
$record->append_fields(
25
    MARC::Field->new( '952', '0', '0', a => 'CPL', b => 'CPL' )
35
    MARC::Field->new( '952', '0', '0', a => $library1->{branchcode}, b => $library1->{branchcode} )
26
);
36
);
27
my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio($record, '');
37
my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio($record, '');
28
38
29
my $my_branch = 'CPL';
39
my $my_branch = $library1->{branchcode};
30
my $another_branch = 'MPL';
40
my $another_branch = $library2->{branchcode};
31
my $budgetid;
41
my $budgetid;
32
my $bpid = AddBudgetPeriod({
42
my $bpid = AddBudgetPeriod({
33
    budget_period_startdate   => '2015-01-01',
43
    budget_period_startdate   => '2015-01-01',
Lines 234-240 is( C4::Serials::can_show_subscription($subscription_from_another_branch), 1, Link Here
234
"Without IndependentBranches, renew_subscription cannot show a subscription from another branch"
244
"Without IndependentBranches, renew_subscription cannot show a subscription from another branch"
235
);
245
);
236
246
237
$dbh->rollback;
247
$schema->storage->txn_rollback;
238
248
239
# C4::Context->userenv
249
# C4::Context->userenv
240
sub Mock_userenv {
250
sub Mock_userenv {
(-)a/t/db_dependent/ShelfBrowser.t (-6 / +12 lines)
Lines 9-25 use MARC::Record; Link Here
9
use C4::Biblio;
9
use C4::Biblio;
10
use C4::Context;
10
use C4::Context;
11
use C4::Items;
11
use C4::Items;
12
use Koha::Database;
13
14
use t::lib::TestBuilder;
12
15
13
use_ok('C4::ShelfBrowser');
16
use_ok('C4::ShelfBrowser');
14
17
18
my $schema = Koha::Database->schema;
19
$schema->storage->txn_begin;
20
my $builder = t::lib::TestBuilder->new;
15
my $dbh = C4::Context->dbh;
21
my $dbh = C4::Context->dbh;
16
$dbh->{AutoCommit} = 0;
17
$dbh->{RaiseError} = 1;
22
$dbh->{RaiseError} = 1;
18
23
19
$dbh->do(q|DELETE FROM reserves|);
24
$dbh->do(q|DELETE FROM reserves|);
20
$dbh->do(q|DELETE FROM issues|);
25
$dbh->do(q|DELETE FROM issues|);
21
$dbh->do(q|DELETE FROM items|);
26
$dbh->do(q|DELETE FROM items|);
22
27
28
my $library = $builder->build({
29
    source => 'Branch',
30
});
31
23
my $cn;
32
my $cn;
24
33
25
# 100.100 150.100 200.100 210.100 300.000 320.000 400.100 410.100 500.100 510.100 520.100 600.000 610.000 700.100 710.100 720.100 730.100 740.100 750.100
34
# 100.100 150.100 200.100 210.100 300.000 320.000 400.100 410.100 500.100 510.100 520.100 600.000 610.000 700.100 710.100 720.100 730.100 740.100 750.100
Lines 54-61 my ( $biblionumber, undef, undef ) = C4::Biblio::AddBiblio($record, ''); Link Here
54
63
55
for my $callnumber ( shuffle @callnumbers ) {
64
for my $callnumber ( shuffle @callnumbers ) {
56
    my ( $biblionumber, undef, $itemnumber ) = C4::Items::AddItem({
65
    my ( $biblionumber, undef, $itemnumber ) = C4::Items::AddItem({
57
        homebranch => 'CPL',
66
        homebranch => $library->{branchcode},
58
        holdingbranch => 'CPL',
67
        holdingbranch => $library->{branchcode},
59
        itemcallnumber => $callnumber,
68
        itemcallnumber => $callnumber,
60
    }, $biblionumber);
69
    }, $biblionumber);
61
    $cn->{$callnumber} = {
70
    $cn->{$callnumber} = {
Lines 208-212 is( $nearby->{prev_item}{itemnumber}, $cn->{'600.000'}{itemnumber}, "Test last i Link Here
208
is( $nearby->{next_item}, undef, "Test end of the shelf: no next link" );
217
is( $nearby->{next_item}, undef, "Test end of the shelf: no next link" );
209
218
210
is( scalar( @{$nearby->{items}} ), 4, "Test last item of the shelf: got 4 items" );
219
is( scalar( @{$nearby->{items}} ), 4, "Test last item of the shelf: got 4 items" );
211
212
$dbh->rollback;
213
- 

Return to bug 14878