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

(-)a/t/db_dependent/Accounts.t (-6 / +7 lines)
Lines 48-63 can_ok( 'C4::Accounts', Link Here
48
);
48
);
49
49
50
my $builder = t::lib::TestBuilder->new();
50
my $builder = t::lib::TestBuilder->new();
51
my $schema  = Koha::Database->new()->schema();
52
53
my $dbh = C4::Context->dbh;
51
my $dbh = C4::Context->dbh;
54
$dbh->{RaiseError}=1;
52
$dbh->{RaiseError}=1;
55
$dbh->{AutoCommit}=0;
53
my $schema  = Koha::Database->new()->schema();
54
55
my $library = $builder->build({
56
    source => 'Branch',
57
});
58
56
$dbh->do(q|DELETE FROM accountlines|);
59
$dbh->do(q|DELETE FROM accountlines|);
57
$dbh->do(q|DELETE FROM issues|);
60
$dbh->do(q|DELETE FROM issues|);
58
$dbh->do(q|DELETE FROM borrowers|);
61
$dbh->do(q|DELETE FROM borrowers|);
59
62
60
my $branchcode = 'CPL';
63
my $branchcode = $library->{branchcode};
61
my $borrower_number;
64
my $borrower_number;
62
65
63
my $context = new Test::MockModule('C4::Context');
66
my $context = new Test::MockModule('C4::Context');
Lines 291-296 subtest "makepartialpayment() tests" => sub { Link Here
291
    }
294
    }
292
};
295
};
293
296
294
$dbh->rollback;
295
296
1;
297
1;
(-)a/t/db_dependent/Acquisition/OrderUsers.t (-4 / +10 lines)
Lines 8-18 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
use t::lib::TestBuilder;
12
13
my $builder = t::lib::TestBuilder->new;
14
11
my $schema = Koha::Database->new()->schema();
15
my $schema = Koha::Database->new()->schema();
12
$schema->storage->txn_begin();
16
13
my $dbh = C4::Context->dbh;
17
my $dbh = C4::Context->dbh;
14
$dbh->{RaiseError} = 1;
18
$dbh->{RaiseError} = 1;
15
19
20
my $library = $builder->build({
21
    source => "Branch",
22
});
23
16
# Creating some orders
24
# Creating some orders
17
my $booksellerid = C4::Bookseller::AddBookseller(
25
my $booksellerid = C4::Bookseller::AddBookseller(
18
    {
26
    {
Lines 65-71 my $borrowernumber = C4::Members::AddMember( Link Here
65
    firstname =>  'TESTFN',
73
    firstname =>  'TESTFN',
66
    surname => 'TESTSN',
74
    surname => 'TESTSN',
67
    categorycode => 'S',
75
    categorycode => 'S',
68
    branchcode => 'CPL',
76
    branchcode => $library->{branchcode},
69
    dateofbirth => '',
77
    dateofbirth => '',
70
    dateexpiry => '9999-12-31',
78
    dateexpiry => '9999-12-31',
71
    userid => 'TESTUSERID'
79
    userid => 'TESTUSERID'
Lines 109-113 ModReceiveOrder( Link Here
109
117
110
$messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber });
118
$messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber });
111
is( scalar( @$messages ), 1, 'The letter has been sent to message queue on receiving the order');
119
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 (-4 / +8 lines)
Lines 5-23 use Modern::Perl; Link Here
5
use C4::Context;
5
use C4::Context;
6
use C4::Members;
6
use C4::Members;
7
7
8
use t::lib::TestBuilder;
9
8
use Test::More tests => 31;
10
use Test::More tests => 31;
9
11
10
use_ok('Koha::Borrower::Debarments');
12
use_ok('Koha::Borrower::Debarments');
11
13
14
my $builder = t::lib::TestBuilder->new;
12
my $dbh = C4::Context->dbh;
15
my $dbh = C4::Context->dbh;
13
$dbh->{AutoCommit} = 0;
14
$dbh->{RaiseError} = 1;
16
$dbh->{RaiseError} = 1;
15
17
18
my $library = $builder->build({
19
    source => 'Branch',
20
});
21
16
my $borrowernumber = AddMember(
22
my $borrowernumber = AddMember(
17
    firstname =>  'my firstname',
23
    firstname =>  'my firstname',
18
    surname => 'my surname',
24
    surname => 'my surname',
19
    categorycode => 'S',
25
    categorycode => 'S',
20
    branchcode => 'CPL',
26
    branchcode => $library->{branchcode},
21
);
27
);
22
28
23
my $success = AddDebarment({
29
my $success = AddDebarment({
Lines 153-157 is( IsDebarred( $borrowernumber ), undef, 'A patron without a debarred date is n Link Here
153
159
154
$dbh->do(q|UPDATE borrowers SET debarred = '9999-12-31'|); # Note: Change this test before the first of January 10000!
160
$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' );
161
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 (-4 / +10 lines)
Lines 13-40 use C4::Members qw( AddMember GetMember ); Link Here
13
13
14
use Koha::Borrower::Discharge;
14
use Koha::Borrower::Discharge;
15
15
16
use t::lib::TestBuilder;
17
18
my $builder = t::lib::TestBuilder->new;
16
my $dbh = C4::Context->dbh;
19
my $dbh = C4::Context->dbh;
17
$dbh->{AutoCommit} = 0;
18
$dbh->{RaiseError} = 1;
20
$dbh->{RaiseError} = 1;
19
21
20
$dbh->do(q|DELETE FROM discharges|);
22
$dbh->do(q|DELETE FROM discharges|);
21
23
24
my $library = $builder->build({
25
    source => 'Branch',
26
});
27
22
C4::Context->_new_userenv('xxx');
28
C4::Context->_new_userenv('xxx');
23
C4::Context->set_userenv(0, 0, 0, 'firstname', 'surname', 'CPL', 'CPL', '', '', '', '', '');
29
C4::Context->set_userenv(0, 0, 0, 'firstname', 'surname', $library->{branchcode}, $library->{branchcode}, '', '', '', '', '');
24
30
25
my $borrowernumber = AddMember(
31
my $borrowernumber = AddMember(
26
    cardnumber => 'UTCARD1',
32
    cardnumber => 'UTCARD1',
27
    firstname => 'my firstname',
33
    firstname => 'my firstname',
28
    surname => 'my surname',
34
    surname => 'my surname',
29
    categorycode => 'S',
35
    categorycode => 'S',
30
    branchcode => 'CPL',
36
    branchcode => $library->{branchcode},
31
);
37
);
32
my $borrower = GetMember( borrowernumber => $borrowernumber );
38
my $borrower = GetMember( borrowernumber => $borrowernumber );
33
39
34
# Discharge not possible with issues
40
# Discharge not possible with issues
35
my ( $biblionumber ) = AddBiblio( MARC::Record->new, '');
41
my ( $biblionumber ) = AddBiblio( MARC::Record->new, '');
36
my $barcode = 'BARCODE42';
42
my $barcode = 'BARCODE42';
37
my ( undef, undef, $itemnumber ) = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL', barcode => $barcode }, $biblionumber);
43
my ( undef, undef, $itemnumber ) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, barcode => $barcode }, $biblionumber);
38
AddIssue( $borrower, $barcode );
44
AddIssue( $borrower, $barcode );
39
is( Koha::Borrower::Discharge::can_be_discharged({ borrowernumber => $borrowernumber }), 0, 'A patron with issues cannot be discharged' );
45
is( Koha::Borrower::Discharge::can_be_discharged({ borrowernumber => $borrowernumber }), 0, 'A patron with issues cannot be discharged' );
40
46
(-)a/t/db_dependent/Borrower_Files.t (-4 / +8 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 t::lib::TestBuilder;
26
25
use Test::More tests => 23;
27
use Test::More tests => 23;
26
28
27
use_ok('Koha::Borrower::Files');
29
use_ok('Koha::Borrower::Files');
28
30
31
my $builder = t::lib::TestBuilder->new;
29
my $dbh = C4::Context->dbh;
32
my $dbh = C4::Context->dbh;
30
$dbh->{AutoCommit} = 0;
31
$dbh->{RaiseError} = 1;
33
$dbh->{RaiseError} = 1;
32
34
33
$dbh->do(q|DELETE FROM issues|);
35
$dbh->do(q|DELETE FROM issues|);
34
$dbh->do(q|DELETE FROM borrowers|);
36
$dbh->do(q|DELETE FROM borrowers|);
35
$dbh->do(q|DELETE FROM borrower_files|);
37
$dbh->do(q|DELETE FROM borrower_files|);
36
38
39
my $library = $builder->build({
40
    source => 'Branch',
41
});
42
37
my $borrowernumber = AddMember(
43
my $borrowernumber = AddMember(
38
    firstname =>  'my firstname',
44
    firstname =>  'my firstname',
39
    surname => 'my surname',
45
    surname => 'my surname',
40
    categorycode => 'S',
46
    categorycode => 'S',
41
    branchcode => 'CPL',
47
    branchcode => $library->{branchcode},
42
);
48
);
43
49
44
my $bf = Koha::Borrower::Files->new(
50
my $bf = Koha::Borrower::Files->new(
Lines 118-122 $bf->DelFile( Link Here
118
);
124
);
119
$files = $bf->GetFilesInfo();
125
$files = $bf->GetFilesInfo();
120
is( @$files, 0, 'DelFile delete a file' );
126
is( @$files, 0, 'DelFile delete a file' );
121
122
$dbh->rollback;
(-)a/t/db_dependent/Budgets.t (-8 / +9 lines)
Lines 12-34 use C4::Dates; Link Here
12
use C4::Members qw( AddMember );
12
use C4::Members qw( AddMember );
13
13
14
use Koha::Acquisition::Order;
14
use Koha::Acquisition::Order;
15
use Koha::Database;
15
16
use t::lib::TestBuilder;
16
17
17
use YAML;
18
use YAML;
19
my $builder = t::lib::TestBuilder->new;
18
my $dbh = C4::Context->dbh;
20
my $dbh = C4::Context->dbh;
19
my $database = Koha::Database->new();
20
my $schema = $database->schema();
21
$schema->storage->txn_begin();
22
$dbh->{RaiseError} = 1;
21
$dbh->{RaiseError} = 1;
23
22
24
$dbh->do(q|DELETE FROM aqbudgetperiods|);
23
$dbh->do(q|DELETE FROM aqbudgetperiods|);
25
$dbh->do(q|DELETE FROM aqbudgets|);
24
$dbh->do(q|DELETE FROM aqbudgets|);
26
25
26
my $library = $builder->build({
27
    source => 'Branch',
28
});
29
27
# Mock userenv
30
# Mock userenv
28
local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /redefined/ };
31
local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /redefined/ };
29
my $userenv;
32
my $userenv;
30
*C4::Context::userenv = \&Mock_userenv;
33
*C4::Context::userenv = \&Mock_userenv;
31
$userenv = { flags => 1, id => 'my_userid', branch => 'CPL' };
34
$userenv = { flags => 1, id => 'my_userid', branch => $library->{branchcode} };
32
35
33
#
36
#
34
# Budget Periods :
37
# Budget Periods :
Lines 531-537 for my $new_budget ( @new_budgets ) { Link Here
531
# Test SetOwnerToFundHierarchy
534
# Test SetOwnerToFundHierarchy
532
535
533
my $categorycode = 'S';
536
my $categorycode = 'S';
534
my $branchcode = 'CPL';
537
my $branchcode = $library->{branchcode};
535
my $john_doe = C4::Members::AddMember(
538
my $john_doe = C4::Members::AddMember(
536
    cardnumber   => '123456',
539
    cardnumber   => '123456',
537
    firstname    => 'John',
540
    firstname    => 'John',
Lines 582-589 is( C4::Budgets::GetBudget($budget_id2)->{budget_owner_id}, Link Here
582
is( C4::Budgets::GetBudget($budget_id21)->{budget_owner_id},
585
is( C4::Budgets::GetBudget($budget_id21)->{budget_owner_id},
583
    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)" );
584
587
585
$schema->storage->txn_rollback();
586
587
sub _get_dependencies {
588
sub _get_dependencies {
588
    my ($budget_hierarchy) = @_;
589
    my ($budget_hierarchy) = @_;
589
    my $graph;
590
    my $graph;
(-)a/t/db_dependent/Circulation.t (-24 / +31 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 => 69;
32
use Test::More tests => 69;
31
33
32
BEGIN {
34
BEGIN {
33
    use_ok('C4::Circulation');
35
    use_ok('C4::Circulation');
34
}
36
}
35
37
38
my $builder = t::lib::TestBuilder->new;
36
my $dbh = C4::Context->dbh;
39
my $dbh = C4::Context->dbh;
37
my $schema = Koha::Database->new()->schema();
38
40
39
# Start transaction
41
# Start transaction
40
$dbh->{RaiseError} = 1;
42
$dbh->{RaiseError} = 1;
41
$schema->storage->txn_begin();
42
43
43
# Start with a clean slate
44
# Start with a clean slate
44
$dbh->do('DELETE FROM issues');
45
$dbh->do('DELETE FROM issues');
45
46
47
my $library = $builder->build({
48
    source => 'Branch',
49
});
50
my $library2 = $builder->build({
51
    source => 'Branch',
52
});
53
46
my $CircControl = C4::Context->preference('CircControl');
54
my $CircControl = C4::Context->preference('CircControl');
47
my $HomeOrHoldingBranch = C4::Context->preference('HomeOrHoldingBranch');
55
my $HomeOrHoldingBranch = C4::Context->preference('HomeOrHoldingBranch');
48
56
49
my $item = {
57
my $item = {
50
    homebranch => 'MPL',
58
    homebranch => $library2->{branchcode},
51
    holdingbranch => 'MPL'
59
    holdingbranch => $library2->{branchcode}
52
};
60
};
53
61
54
my $borrower = {
62
my $borrower = {
55
    branchcode => 'MPL'
63
    branchcode => $library2->{branchcode}
56
};
64
};
57
65
58
# No userenv, PickupLibrary
66
# No userenv, PickupLibrary
Lines 96-103 is( Link Here
96
104
97
# Now, set a userenv
105
# Now, set a userenv
98
C4::Context->_new_userenv('xxx');
106
C4::Context->_new_userenv('xxx');
99
C4::Context->set_userenv(0,0,0,'firstname','surname', 'MPL', 'Midway Public Library', '', '', '');
107
C4::Context->set_userenv(0,0,0,'firstname','surname', $library2->{branchcode}, 'Midway Public Library', '', '', '');
100
is(C4::Context->userenv->{branch}, 'MPL', 'userenv set');
108
is(C4::Context->userenv->{branch}, $library2->{branchcode}, 'userenv set');
101
109
102
# Userenv set, PickupLibrary
110
# Userenv set, PickupLibrary
103
C4::Context->set_preference('CircControl', 'PickupLibrary');
111
C4::Context->set_preference('CircControl', 'PickupLibrary');
Lines 108-114 is( Link Here
108
);
116
);
109
is(
117
is(
110
    C4::Circulation::_GetCircControlBranch($item, $borrower),
118
    C4::Circulation::_GetCircControlBranch($item, $borrower),
111
    'MPL',
119
    $library2->{branchcode},
112
    '_GetCircControlBranch returned current branch'
120
    '_GetCircControlBranch returned current branch'
113
);
121
);
114
122
Lines 174-180 my $sth = C4::Context->dbh->prepare("SELECT COUNT(*) FROM accountlines WHERE amo Link Here
174
$sth->execute();
182
$sth->execute();
175
my ( $original_count ) = $sth->fetchrow_array();
183
my ( $original_count ) = $sth->fetchrow_array();
176
184
177
C4::Context->dbh->do("INSERT INTO borrowers ( cardnumber, surname, firstname, categorycode, branchcode ) VALUES ( '99999999999', 'Hall', 'Kyle', 'S', 'MPL' )");
185
C4::Context->dbh->do("INSERT INTO borrowers ( cardnumber, surname, firstname, categorycode, branchcode ) VALUES ( '99999999999', 'Hall', 'Kyle', 'S', ? )", undef, $library2->{branchcode} );
178
186
179
C4::Circulation::ProcessOfflinePayment({ cardnumber => '99999999999', amount => '123.45' });
187
C4::Circulation::ProcessOfflinePayment({ cardnumber => '99999999999', amount => '123.45' });
180
188
Lines 200-206 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
200
    my ($biblionumber, $biblioitemnumber) = AddBiblio($biblio, '');
208
    my ($biblionumber, $biblioitemnumber) = AddBiblio($biblio, '');
201
209
202
    my $barcode = 'R00000342';
210
    my $barcode = 'R00000342';
203
    my $branch = 'MPL';
211
    my $branch = $library2->{branchcode};
204
212
205
    my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
213
    my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
206
        {
214
        {
Lines 433-439 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
433
441
434
    LostItem( $itemnumber, 1 );
442
    LostItem( $itemnumber, 1 );
435
443
436
    my $item = $schema->resultset('Item')->find( $itemnumber );
444
    my $item = Koha::Database->new()->schema()->resultset('Item')->find($itemnumber);
437
    ok( !$item->onloan(), "Lost item marked as returned has false onloan value" );
445
    ok( !$item->onloan(), "Lost item marked as returned has false onloan value" );
438
446
439
    my $total_due = $dbh->selectrow_array(
447
    my $total_due = $dbh->selectrow_array(
Lines 453-459 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
453
461
454
    LostItem( $itemnumber2, 0 );
462
    LostItem( $itemnumber2, 0 );
455
463
456
    my $item2 = $schema->resultset('Item')->find( $itemnumber2 );
464
    my $item2 = Koha::Database->new()->schema()->resultset('Item')->find($itemnumber2);
457
    ok( $item2->onloan(), "Lost item *not* marked as returned has true onloan value" );
465
    ok( $item2->onloan(), "Lost item *not* marked as returned has true onloan value" );
458
466
459
    $total_due = $dbh->selectrow_array(
467
    $total_due = $dbh->selectrow_array(
Lines 466-472 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
466
    my $now = dt_from_string();
474
    my $now = dt_from_string();
467
    my $future = dt_from_string();
475
    my $future = dt_from_string();
468
    $future->add( days => 7 );
476
    $future->add( days => 7 );
469
    my $units = C4::Overdues::get_chargeable_units('days', $future, $now, 'MPL');
477
    my $units = C4::Overdues::get_chargeable_units('days', $future, $now, $library2->{branchcode});
470
    ok( $units == 0, '_get_chargeable_units returns 0 for items not past due date (Bug 12596)' );
478
    ok( $units == 0, '_get_chargeable_units returns 0 for items not past due date (Bug 12596)' );
471
}
479
}
472
480
Lines 475-481 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
475
    my $barcode  = 'R00000342';
483
    my $barcode  = 'R00000342';
476
    my $barcode2 = 'R00000343';
484
    my $barcode2 = 'R00000343';
477
    my $barcode3 = 'R00000344';
485
    my $barcode3 = 'R00000344';
478
    my $branch   = 'MPL';
486
    my $branch   = $library2->{branchcode};
479
487
480
    #Create another record
488
    #Create another record
481
    my $biblio2 = MARC::Record->new();
489
    my $biblio2 = MARC::Record->new();
Lines 560-566 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
560
568
561
{
569
{
562
    my $barcode  = '1234567890';
570
    my $barcode  = '1234567890';
563
    my $branch   = 'MPL';
571
    my $branch   = $library2->{branchcode};
564
572
565
    my $biblio = MARC::Record->new();
573
    my $biblio = MARC::Record->new();
566
    my ($biblionumber, $biblioitemnumber) = AddBiblio($biblio, '');
574
    my ($biblionumber, $biblioitemnumber) = AddBiblio($biblio, '');
Lines 615-622 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
615
    my $barcode1 = '1234';
623
    my $barcode1 = '1234';
616
    my ( undef, undef, $itemnumber1 ) = AddItem(
624
    my ( undef, undef, $itemnumber1 ) = AddItem(
617
        {
625
        {
618
            homebranch    => 'MPL',
626
            homebranch    => $library2->{branchcode},
619
            holdingbranch => 'MPL',
627
            holdingbranch => $library2->{branchcode},
620
            barcode       => $barcode1,
628
            barcode       => $barcode1,
621
        },
629
        },
622
        $biblionumber
630
        $biblionumber
Lines 624-631 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
624
    my $barcode2 = '4321';
632
    my $barcode2 = '4321';
625
    my ( undef, undef, $itemnumber2 ) = AddItem(
633
    my ( undef, undef, $itemnumber2 ) = AddItem(
626
        {
634
        {
627
            homebranch    => 'MPL',
635
            homebranch    => $library2->{branchcode},
628
            holdingbranch => 'MPL',
636
            holdingbranch => $library2->{branchcode},
629
            barcode       => $barcode2,
637
            barcode       => $barcode2,
630
        },
638
        },
631
        $biblionumber
639
        $biblionumber
Lines 635-647 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
635
        firstname    => 'Kyle',
643
        firstname    => 'Kyle',
636
        surname      => 'Hall',
644
        surname      => 'Hall',
637
        categorycode => 'S',
645
        categorycode => 'S',
638
        branchcode   => 'MPL',
646
        branchcode   => $library2->{branchcode},
639
    );
647
    );
640
    my $borrowernumber2 = AddMember(
648
    my $borrowernumber2 = AddMember(
641
        firstname    => 'Chelsea',
649
        firstname    => 'Chelsea',
642
        surname      => 'Hall',
650
        surname      => 'Hall',
643
        categorycode => 'S',
651
        categorycode => 'S',
644
        branchcode   => 'MPL',
652
        branchcode   => $library2->{branchcode},
645
    );
653
    );
646
654
647
    my $borrower1 = GetMember( borrowernumber => $borrowernumber1 );
655
    my $borrower1 = GetMember( borrowernumber => $borrowernumber1 );
Lines 653-659 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
653
    is( $renewokay, 1, 'Bug 14337 - Verify the borrower can renew with no hold on the record' );
661
    is( $renewokay, 1, 'Bug 14337 - Verify the borrower can renew with no hold on the record' );
654
662
655
    AddReserve(
663
    AddReserve(
656
        'MPL', $borrowernumber2, $biblionumber,
664
        $library2->{branchcode}, $borrowernumber2, $biblionumber,
657
        '',  1, undef, undef, '',
665
        '',  1, undef, undef, '',
658
        undef, undef, undef
666
        undef, undef, undef
659
    );
667
    );
Lines 688-694 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
688
{
696
{
689
    # Don't allow renewing onsite checkout
697
    # Don't allow renewing onsite checkout
690
    my $barcode  = 'R00000XXX';
698
    my $barcode  = 'R00000XXX';
691
    my $branch   = 'CPL';
699
    my $branch   = $library->{branchcode};
692
700
693
    #Create another record
701
    #Create another record
694
    my $biblio = MARC::Record->new();
702
    my $biblio = MARC::Record->new();
Lines 721-725 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
721
    is( $error, 'onsite_checkout', 'A correct error code should be returned by CanBookBeRenewed for on-site checkout' );
729
    is( $error, 'onsite_checkout', 'A correct error code should be returned by CanBookBeRenewed for on-site checkout' );
722
}
730
}
723
731
724
$schema->storage->txn_rollback();
725
1;
732
1;
(-)a/t/db_dependent/Circulation/IsItemIssued.t (-7 / +11 lines)
Lines 7-25 use C4::Items; Link Here
7
use C4::Members;
7
use C4::Members;
8
use Koha::DateUtils;
8
use Koha::DateUtils;
9
9
10
use t::lib::TestBuilder;
11
10
use MARC::Record;
12
use MARC::Record;
11
13
12
*C4::Context::userenv = \&Mock_userenv;
14
*C4::Context::userenv = \&Mock_userenv;
13
15
16
my $builder = t::lib::TestBuilder->new;
14
my $dbh = C4::Context->dbh;
17
my $dbh = C4::Context->dbh;
15
$dbh->{AutoCommit} = 0;
16
$dbh->{RaiseError} = 1;
18
$dbh->{RaiseError} = 1;
17
19
20
my $library = $builder->build({
21
    source => 'Branch',
22
});
23
18
my $borrowernumber = AddMember(
24
my $borrowernumber = AddMember(
19
    firstname =>  'my firstname',
25
    firstname =>  'my firstname',
20
    surname => 'my surname',
26
    surname => 'my surname',
21
    categorycode => 'S',
27
    categorycode => 'S',
22
    branchcode => 'CPL',
28
    branchcode => $library->{branchcode},
23
);
29
);
24
30
25
31
Lines 27-33 my $borrower = GetMember( borrowernumber => $borrowernumber ); Link Here
27
my $record = MARC::Record->new();
33
my $record = MARC::Record->new();
28
my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, '' );
34
my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, '' );
29
35
30
my ( undef, undef, $itemnumber ) = AddItem( { homebranch => 'CPL', holdingbranch => 'CPL', barcode => 'i_dont_exist' }, $biblionumber );
36
my ( undef, undef, $itemnumber ) = AddItem( { homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, barcode => 'i_dont_exist' }, $biblionumber );
31
my $item = GetItem( $itemnumber );
37
my $item = GetItem( $itemnumber );
32
38
33
is ( IsItemIssued( $item->{itemnumber} ), 0, "item is not on loan at first" );
39
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',
47
    'item that is on loan cannot be deleted',
42
);
48
);
43
49
44
AddReturn('i_dont_exist', 'CPL');
50
AddReturn('i_dont_exist', $library->{branchcode});
45
is ( IsItemIssued( $item->{itemnumber} ), 0, "item has been returned" );
51
is ( IsItemIssued( $item->{itemnumber} ), 0, "item has been returned" );
46
52
47
is(
53
is(
Lines 50-58 is( Link Here
50
    'item that is not on loan can be deleted',
56
    'item that is not on loan can be deleted',
51
);
57
);
52
58
53
$dbh->rollback;
54
55
# C4::Context->userenv
59
# C4::Context->userenv
56
sub Mock_userenv {
60
sub Mock_userenv {
57
    return { branch => 'CPL' };
61
    return { branch => $library->{branchcode} };
58
}
62
}
(-)a/t/db_dependent/Circulation/IssuingRules/maxsuspensiondays.t (-2 / +9 lines)
Lines 12-22 use C4::Items qw( AddItem ); Link Here
12
use C4::Members qw( AddMember GetMember );
12
use C4::Members qw( AddMember GetMember );
13
use Koha::DateUtils;
13
use Koha::DateUtils;
14
use Koha::Borrower::Debarments qw( GetDebarments DelDebarment );
14
use Koha::Borrower::Debarments qw( GetDebarments DelDebarment );
15
16
use t::lib::TestBuilder;
17
18
my $builder = t::lib::TestBuilder->new;
15
my $dbh = C4::Context->dbh;
19
my $dbh = C4::Context->dbh;
16
$dbh->{RaiseError} = 1;
20
$dbh->{RaiseError} = 1;
17
$dbh->{AutoCommit} = 0;
18
21
19
my $branchcode = 'CPL';
22
my $library = $builder->build({
23
    source => 'Branch',
24
});
25
26
my $branchcode = $library->{branchcode};
20
local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /redefined/ };
27
local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /redefined/ };
21
my $userenv->{branch} = $branchcode;
28
my $userenv->{branch} = $branchcode;
22
*C4::Context::userenv = \&Mock_userenv;
29
*C4::Context::userenv = \&Mock_userenv;
(-)a/t/db_dependent/Circulation/Returns.t (-6 / +12 lines)
Lines 7-27 use C4::Items; Link Here
7
use C4::Members;
7
use C4::Members;
8
use Koha::DateUtils;
8
use Koha::DateUtils;
9
9
10
use t::lib::TestBuilder;
11
10
use MARC::Record;
12
use MARC::Record;
11
13
12
*C4::Context::userenv = \&Mock_userenv;
14
*C4::Context::userenv = \&Mock_userenv;
13
15
16
my $builder = t::lib::TestBuilder->new;
14
my $dbh = C4::Context->dbh;
17
my $dbh = C4::Context->dbh;
15
$dbh->{AutoCommit} = 0;
16
$dbh->{RaiseError} = 1;
18
$dbh->{RaiseError} = 1;
17
19
20
my $library = $builder->build({
21
    source => 'Branch',
22
});
23
18
my $record = MARC::Record->new();
24
my $record = MARC::Record->new();
19
my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, '' );
25
my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, '' );
20
26
21
my ( undef, undef, $itemnumber ) = AddItem(
27
my ( undef, undef, $itemnumber ) = AddItem(
22
    {
28
    {
23
        homebranch         => 'CPL',
29
        homebranch         => $library->{branchcode},
24
        holdingbranch      => 'CPL',
30
        holdingbranch      => $library->{branchcode},
25
        barcode            => 'i_dont_exist',
31
        barcode            => 'i_dont_exist',
26
        location           => 'PROC',
32
        location           => 'PROC',
27
        permanent_location => 'TEST'
33
        permanent_location => 'TEST'
Lines 32-38 my ( undef, undef, $itemnumber ) = AddItem( Link Here
32
my $item;
38
my $item;
33
39
34
C4::Context->set_preference( "InProcessingToShelvingCart", 1 );
40
C4::Context->set_preference( "InProcessingToShelvingCart", 1 );
35
AddReturn( 'i_dont_exist', 'CPL' );
41
AddReturn( 'i_dont_exist', $library->{branchcode} );
36
$item = GetItem($itemnumber);
42
$item = GetItem($itemnumber);
37
is( $item->{location}, 'CART', "InProcessingToShelvingCart functions as intended" );
43
is( $item->{location}, 'CART', "InProcessingToShelvingCart functions as intended" );
38
44
Lines 40-50 $item->{location} = 'PROC'; Link Here
40
ModItem( $item, undef, $itemnumber );
46
ModItem( $item, undef, $itemnumber );
41
47
42
C4::Context->set_preference( "InProcessingToShelvingCart", 0 );
48
C4::Context->set_preference( "InProcessingToShelvingCart", 0 );
43
AddReturn( 'i_dont_exist', 'CPL' );
49
AddReturn( 'i_dont_exist', $library->{branchcode} );
44
$item = GetItem($itemnumber);
50
$item = GetItem($itemnumber);
45
is( $item->{location}, 'TEST', "InProcessingToShelvingCart functions as intended" );
51
is( $item->{location}, 'TEST', "InProcessingToShelvingCart functions as intended" );
46
52
47
# C4::Context->userenv
53
# C4::Context->userenv
48
sub Mock_userenv {
54
sub Mock_userenv {
49
    return { branch => 'CPL' };
55
    return { branch => $library->{branchcode} };
50
}
56
}
(-)a/t/db_dependent/Circulation_transfers.t (-44 / +9 lines)
Lines 9-14 use C4::Circulation; Link Here
9
use Koha::DateUtils;
9
use Koha::DateUtils;
10
use DateTime::Duration;
10
use DateTime::Duration;
11
11
12
use t::lib::TestBuilder;
13
12
use Test::More tests => 22;
14
use Test::More tests => 22;
13
use Test::Deep;
15
use Test::Deep;
14
16
Lines 26-35 can_ok( Link Here
26
      )
28
      )
27
);
29
);
28
30
31
my $builder = t::lib::TestBuilder->new;
29
#Start transaction
32
#Start transaction
30
my $dbh = C4::Context->dbh;
33
my $dbh = C4::Context->dbh;
31
$dbh->{RaiseError} = 1;
34
$dbh->{RaiseError} = 1;
32
$dbh->{AutoCommit} = 0;
33
35
34
$dbh->do(q|DELETE FROM issues|);
36
$dbh->do(q|DELETE FROM issues|);
35
$dbh->do(q|DELETE FROM borrowers|);
37
$dbh->do(q|DELETE FROM borrowers|);
Lines 40-85 $dbh->do(q|DELETE FROM branchtransfers|); Link Here
40
42
41
#Add sample datas
43
#Add sample datas
42
#Add branches
44
#Add branches
43
my $samplebranch1 = {
45
my $samplebranch1 = $builder->build({
44
    add            => 1,
46
    source => 'Branch',
45
    branchcode     => 'SAB1',
47
});
46
    branchname     => 'Sample Branch',
48
my $samplebranch2 = $builder->build({
47
    branchaddress1 => 'sample adr1',
49
    source => 'Branch',
48
    branchaddress2 => 'sample adr2',
50
});
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
51
84
#Add biblio and items
52
#Add biblio and items
85
my $record = MARC::Record->new();
53
my $record = MARC::Record->new();
Lines 208-213 cmp_deeply( Link Here
208
    C4::Circulation::TransferSlip($samplebranch1->{branchcode}, undef, 1, $samplebranch2->{branchcode}),
176
    C4::Circulation::TransferSlip($samplebranch1->{branchcode}, undef, 1, $samplebranch2->{branchcode}),
209
    "Barcode and itemnumber for same item both generate same TransferSlip"
177
    "Barcode and itemnumber for same item both generate same TransferSlip"
210
    );
178
    );
211
212
#End transaction
213
$dbh->rollback;
(-)a/t/db_dependent/CourseReserves.t (-7 / +9 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 t::lib::TestBuilder;
11
10
BEGIN {
12
BEGIN {
11
    use_ok('C4::Biblio');
13
    use_ok('C4::Biblio');
12
    use_ok('C4::Context');
14
    use_ok('C4::Context');
Lines 16-27 BEGIN { Link Here
16
    use_ok('MARC::Record');
18
    use_ok('MARC::Record');
17
}
19
}
18
20
21
my $builder = t::lib::TestBuilder->new;
19
my $dbh = C4::Context->dbh;
22
my $dbh = C4::Context->dbh;
20
21
# Start transaction
22
$dbh->{AutoCommit} = 0;
23
$dbh->{RaiseError} = 1;
23
$dbh->{RaiseError} = 1;
24
24
25
my $library = $builder->build({
26
    source => 'Branch',
27
});
28
25
my $sth = $dbh->prepare("SELECT * FROM borrowers ORDER BY RAND() LIMIT 10");
29
my $sth = $dbh->prepare("SELECT * FROM borrowers ORDER BY RAND() LIMIT 10");
26
$sth->execute();
30
$sth->execute();
27
my @borrowers = @{ $sth->fetchall_arrayref( {} ) };
31
my @borrowers = @{ $sth->fetchall_arrayref( {} ) };
Lines 29-38 my @borrowers = @{ $sth->fetchall_arrayref( {} ) }; Link Here
29
# Create the item
33
# Create the item
30
my $record = MARC::Record->new();
34
my $record = MARC::Record->new();
31
$record->append_fields(
35
$record->append_fields(
32
    MARC::Field->new( '952', '0', '0', a => 'CPL', b => 'CPL' )
36
    MARC::Field->new( '952', '0', '0', a => $library->{branchcode}, b => $library->{branchcode} )
33
);
37
);
34
my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio($record, '');
38
my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio($record, '');
35
my @iteminfo = C4::Items::AddItem( { homebranch => 'CPL', holdingbranch => 'CPL' }, $biblionumber );
39
my @iteminfo = C4::Items::AddItem( { homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode} }, $biblionumber );
36
my $itemnumber = $iteminfo[2];
40
my $itemnumber = $iteminfo[2];
37
41
38
my $course_id = ModCourse(
42
my $course_id = ModCourse(
Lines 90-94 ok( !defined( $course_reserve->{'cr_id'} ), "DelCourseReserve functions correctl Link Here
90
DelCourse($course_id);
94
DelCourse($course_id);
91
$course = GetCourse($course_id);
95
$course = GetCourse($course_id);
92
ok( !defined( $course->{'course_id'} ), "DelCourse deleted course successfully" );
96
ok( !defined( $course->{'course_id'} ), "DelCourse deleted course successfully" );
93
94
$dbh->rollback;
(-)a/t/db_dependent/Creators/Lib.t (-8 / +18 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;
24
use Test::Warn;
25
use Test::Warn;
25
26
26
BEGIN {
27
BEGIN {
Lines 50-58 can_ok( Link Here
50
      html_table )
51
      html_table )
51
);
52
);
52
53
54
my $builder = t::lib::TestBuilder->new;
53
my $dbh = C4::Context->dbh;
55
my $dbh = C4::Context->dbh;
54
$dbh->{AutoCommit} = 0;
55
$dbh->{RaiseError} = 1;
56
$dbh->{RaiseError} = 1;
57
56
$dbh->do('DELETE FROM issues');
58
$dbh->do('DELETE FROM issues');
57
$dbh->do('DELETE FROM creator_templates');
59
$dbh->do('DELETE FROM creator_templates');
58
$dbh->do('DELETE FROM creator_layouts');
60
$dbh->do('DELETE FROM creator_layouts');
Lines 67-72 $dbh->do('DELETE FROM biblioitems'); Link Here
67
#                     Inserted data
69
#                     Inserted data
68
###########################################################
70
###########################################################
69
71
72
my $library1 = $builder->build({
73
    source => 'Branch',
74
});
75
my $library2 = $builder->build({
76
    source => 'Branch',
77
});
78
my $library3 = $builder->build({
79
    source => 'Branch',
80
});
81
70
# ---------- Some Templates  --------------------
82
# ---------- Some Templates  --------------------
71
my $query = '
83
my $query = '
72
  INSERT INTO creator_templates
84
  INSERT INTO creator_templates
Lines 226-236 $query = ' Link Here
226
     timestamp, branch_code, creator)
238
     timestamp, branch_code, creator)
227
  VALUES (?,?,?,?,?,?)';
239
  VALUES (?,?,?,?,?,?)';
228
$insert_sth = $dbh->prepare($query);
240
$insert_sth = $dbh->prepare($query);
229
$insert_sth->execute( 11, $item_number1, $borrowernumber1, 'now()', 'CPL', 'Labels' );
241
$insert_sth->execute( 11, $item_number1, $borrowernumber1, 'now()', $library1->{branchcode}, 'Labels' );
230
242
231
$insert_sth->execute( 12, $item_number2, $borrowernumber2, 'now()', 'MPL', 'Labels' );
243
$insert_sth->execute( 12, $item_number2, $borrowernumber2, 'now()', $library2->{branchcode}, 'Labels' );
232
244
233
$insert_sth->execute( 12, $item_number3, $borrowernumber3, 'now()', 'PVL', 'Labels' );
245
$insert_sth->execute( 12, $item_number3, $borrowernumber3, 'now()', $library3->{branchcode}, 'Labels' );
234
246
235
###########################################################
247
###########################################################
236
#                     Testing Subs
248
#                     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' );
804
is( $batches->[1]->{_item_count}, $count, 'item_number   is good for this batch_id' );
793
805
794
# Without filter & creator params -----
806
# Without filter & creator params -----
795
$batches = get_batch_summary( filter => 'branch_code=\'MPL\'', creator => 'Labels' );
807
$batches = get_batch_summary( filter => "branch_code='$library1->{branchcode}'", creator => 'Labels' );
796
is( @$batches, 1, 'There is 1 batch matching' );
808
is( @$batches, 1, 'There is 1 batch matching' );
797
809
798
$query = '
810
$query = '
Lines 802-808 $query = ' Link Here
802
    AND    branch_code = ?
814
    AND    branch_code = ?
803
  GROUP BY batch_id
815
  GROUP BY batch_id
804
  ';
816
  ';
805
my ( $id, $nb ) = $dbh->selectrow_array( $query, {}, 'Labels', 'MPL' );
817
my ( $id, $nb ) = $dbh->selectrow_array( $query, {}, 'Labels', $library1->{branchcode} );
806
818
807
is( $batches->[0]->{batch_id},    $id, 'batch_id    is good' );
819
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' );
820
is( $batches->[0]->{_item_count}, $nb, 'item_number is good for this batch_id' );
Lines 1443-1447 sub mock_preference { Link Here
1443
        }
1455
        }
1444
    );
1456
    );
1445
}
1457
}
1446
1447
$dbh->rollback;
(-)a/t/db_dependent/Holds.t (-28 / +32 lines)
Lines 17-32 use Koha::Holds; Link Here
17
17
18
use Koha::DateUtils qw( dt_from_string output_pref );
18
use Koha::DateUtils qw( dt_from_string output_pref );
19
19
20
use t::lib::TestBuilder;
21
20
BEGIN {
22
BEGIN {
21
    use FindBin;
23
    use FindBin;
22
    use lib $FindBin::Bin;
24
    use lib $FindBin::Bin;
23
    use_ok('C4::Reserves');
25
    use_ok('C4::Reserves');
24
}
26
}
25
27
28
my $builder = t::lib::TestBuilder->new;
26
my $dbh = C4::Context->dbh;
29
my $dbh = C4::Context->dbh;
27
28
# Start transaction
29
$dbh->{AutoCommit} = 0;
30
$dbh->{RaiseError} = 1;
30
$dbh->{RaiseError} = 1;
31
31
32
my $borrowers_count = 5;
32
my $borrowers_count = 5;
Lines 43-50 $insert_sth->execute('ONLY1'); Link Here
43
# Create a biblio instance for testing
43
# Create a biblio instance for testing
44
my ($bibnum, $title, $bibitemnum) = create_helper_biblio('DUMMY');
44
my ($bibnum, $title, $bibitemnum) = create_helper_biblio('DUMMY');
45
45
46
my $library1 = $builder->build({
47
    source => 'Branch',
48
});
49
my $library2 = $builder->build({
50
    source => 'Branch',
51
});
52
46
# Create item instance for testing.
53
# Create item instance for testing.
47
my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL' } , $bibnum);
54
my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} } , $bibnum);
48
55
49
# Create some borrowers
56
# Create some borrowers
50
my @borrowernumbers;
57
my @borrowernumbers;
Lines 53-72 foreach (1..$borrowers_count) { Link Here
53
        firstname =>  'my firstname',
60
        firstname =>  'my firstname',
54
        surname => 'my surname ' . $_,
61
        surname => 'my surname ' . $_,
55
        categorycode => 'S',
62
        categorycode => 'S',
56
        branchcode => 'CPL',
63
        branchcode => $library1->{branchcode},
57
    );
64
    );
58
    push @borrowernumbers, $borrowernumber;
65
    push @borrowernumbers, $borrowernumber;
59
}
66
}
60
67
61
my $biblionumber   = $bibnum;
68
my $biblionumber   = $bibnum;
62
69
63
my @branches = GetBranchesLoop();
64
my $branch = $branches[0][0]{value};
65
66
# Create five item level holds
70
# Create five item level holds
67
foreach my $borrowernumber ( @borrowernumbers ) {
71
foreach my $borrowernumber ( @borrowernumbers ) {
68
    AddReserve(
72
    AddReserve(
69
        $branch,
73
        $library1->{branchcode},
70
        $borrowernumber,
74
        $borrowernumber,
71
        $biblionumber,
75
        $biblionumber,
72
        my $bibitems = q{},
76
        my $bibitems = q{},
Lines 88-94 is( scalar(@$reserves), $borrowers_count, "Test GetReserves()" ); Link Here
88
my ( $reservedate, $borrowernumber, $branchcode, $reserve_id ) = GetReservesFromItemnumber($itemnumber);
92
my ( $reservedate, $borrowernumber, $branchcode, $reserve_id ) = GetReservesFromItemnumber($itemnumber);
89
is( $reservedate, output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }), "GetReservesFromItemnumber should return a valid reserve date");
93
is( $reservedate, output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }), "GetReservesFromItemnumber should return a valid reserve date");
90
is( $borrowernumber, $borrowernumbers[0], "GetReservesFromItemnumber should return a valid borrowernumber");
94
is( $borrowernumber, $borrowernumbers[0], "GetReservesFromItemnumber should return a valid borrowernumber");
91
is( $branchcode, 'CPL', "GetReservesFromItemnumber should return a valid branchcode");
95
is( $branchcode, $library1->{branchcode}, "GetReservesFromItemnumber should return a valid branchcode");
92
ok($reserve_id, "Test GetReservesFromItemnumber()");
96
ok($reserve_id, "Test GetReservesFromItemnumber()");
93
97
94
my $hold = Koha::Holds->find( $reserve_id );
98
my $hold = Koha::Holds->find( $reserve_id );
Lines 122-128 is( scalar(@$reserves), $borrowers_count - 1, "Test CancelReserve()" ); Link Here
122
ModReserve({
126
ModReserve({
123
    reserve_id    => $reserve_id,
127
    reserve_id    => $reserve_id,
124
    rank          => '4',
128
    rank          => '4',
125
    branchcode    => $branch,
129
    branchcode    => $library1->{branchcode},
126
    itemnumber    => $itemnumber,
130
    itemnumber    => $itemnumber,
127
    suspend_until => C4::Dates->new("2013-01-01","iso")->output(),
131
    suspend_until => C4::Dates->new("2013-01-01","iso")->output(),
128
});
132
});
Lines 145-151 ok( !$reserve->{'suspend'}, "Test AutoUnsuspendReserves()" ); Link Here
145
149
146
# Add a new hold for the borrower whose hold we canceled earlier, this time at the bib level
150
# Add a new hold for the borrower whose hold we canceled earlier, this time at the bib level
147
AddReserve(
151
AddReserve(
148
    $branch,
152
    $library1->{branchcode},
149
    $borrowernumber,
153
    $borrowernumber,
150
    $biblionumber,
154
    $biblionumber,
151
    my $bibitems = q{},
155
    my $bibitems = q{},
Lines 205-211 ok( $reserve->{'priority'} eq '5', "Test AlterPriority(), move to bottom" ); Link Here
205
209
206
my ($foreign_bibnum, $foreign_title, $foreign_bibitemnum) = create_helper_biblio('DUMMY');
210
my ($foreign_bibnum, $foreign_title, $foreign_bibitemnum) = create_helper_biblio('DUMMY');
207
my ($foreign_item_bibnum, $foreign_item_bibitemnum, $foreign_itemnumber)
211
my ($foreign_item_bibnum, $foreign_item_bibitemnum, $foreign_itemnumber)
208
  = AddItem({ homebranch => 'MPL', holdingbranch => 'MPL' } , $foreign_bibnum);
212
  = AddItem({ homebranch => $library2->{branchcode}, holdingbranch => $library2->{branchcode} } , $foreign_bibnum);
209
$dbh->do('DELETE FROM issuingrules');
213
$dbh->do('DELETE FROM issuingrules');
210
$dbh->do(
214
$dbh->do(
211
    q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed)
215
    q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed)
Lines 248-256 ok( Link Here
248
252
249
# Regression test for bug 11336
253
# Regression test for bug 11336
250
($bibnum, $title, $bibitemnum) = create_helper_biblio('DUMMY');
254
($bibnum, $title, $bibitemnum) = create_helper_biblio('DUMMY');
251
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL' } , $bibnum);
255
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} } , $bibnum);
252
AddReserve(
256
AddReserve(
253
    $branch,
257
    $library1->{branchcode},
254
    $borrowernumbers[0],
258
    $borrowernumbers[0],
255
    $bibnum,
259
    $bibnum,
256
    '',
260
    '',
Lines 264-272 my $reserveid1 = C4::Reserves::GetReserveId( Link Here
264
    }
268
    }
265
);
269
);
266
270
267
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL' } , $bibnum);
271
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} } , $bibnum);
268
AddReserve(
272
AddReserve(
269
    $branch,
273
    $library1->{branchcode},
270
    $borrowernumbers[1],
274
    $borrowernumbers[1],
271
    $bibnum,
275
    $bibnum,
272
    '',
276
    '',
Lines 284-292 CancelReserve({ reserve_id => $reserveid1 }); Link Here
284
$reserve2 = GetReserve( $reserveid2 );
288
$reserve2 = GetReserve( $reserveid2 );
285
is( $reserve2->{priority}, 1, "After cancelreserve, the 2nd reserve becomes the first on the waiting list" );
289
is( $reserve2->{priority}, 1, "After cancelreserve, the 2nd reserve becomes the first on the waiting list" );
286
290
287
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL' } , $bibnum);
291
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} } , $bibnum);
288
AddReserve(
292
AddReserve(
289
    $branch,
293
    $library1->{branchcode},
290
    $borrowernumbers[0],
294
    $borrowernumbers[0],
291
    $bibnum,
295
    $bibnum,
292
    '',
296
    '',
Lines 316-324 ok( !defined( ( CheckReserves($itemnumber) )[1] ), "Hold cannot be trapped for d Link Here
316
320
317
# Regression test for bug 9532
321
# Regression test for bug 9532
318
($bibnum, $title, $bibitemnum) = create_helper_biblio('CANNOT');
322
($bibnum, $title, $bibitemnum) = create_helper_biblio('CANNOT');
319
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL', itype => 'CANNOT' } , $bibnum);
323
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode}, itype => 'CANNOT' } , $bibnum);
320
AddReserve(
324
AddReserve(
321
    $branch,
325
    $library1->{branchcode},
322
    $borrowernumbers[0],
326
    $borrowernumbers[0],
323
    $bibnum,
327
    $bibnum,
324
    '',
328
    '',
Lines 358-382 $dbh->do('DELETE FROM default_circ_rules'); Link Here
358
$dbh->do(q{
362
$dbh->do(q{
359
    INSERT INTO branch_item_rules (branchcode, itemtype, holdallowed, returnbranch)
363
    INSERT INTO branch_item_rules (branchcode, itemtype, holdallowed, returnbranch)
360
    VALUES (?, ?, ?, ?)
364
    VALUES (?, ?, ?, ?)
361
}, {}, 'CPL', 'CANNOT', 0, 'homebranch');
365
}, {}, $library1->{branchcode}, 'CANNOT', 0, 'homebranch');
362
$dbh->do(q{
366
$dbh->do(q{
363
    INSERT INTO branch_item_rules (branchcode, itemtype, holdallowed, returnbranch)
367
    INSERT INTO branch_item_rules (branchcode, itemtype, holdallowed, returnbranch)
364
    VALUES (?, ?, ?, ?)
368
    VALUES (?, ?, ?, ?)
365
}, {}, 'CPL', 'CAN', 1, 'homebranch');
369
}, {}, $library1->{branchcode}, 'CAN', 1, 'homebranch');
366
($bibnum, $title, $bibitemnum) = create_helper_biblio('CANNOT');
370
($bibnum, $title, $bibitemnum) = create_helper_biblio('CANNOT');
367
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem(
371
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem(
368
    { homebranch => 'CPL', holdingbranch => 'CPL', itype => 'CANNOT' } , $bibnum);
372
    { homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode}, itype => 'CANNOT' } , $bibnum);
369
is(CanItemBeReserved($borrowernumbers[0], $itemnumber), 'notReservable',
373
is(CanItemBeReserved($borrowernumbers[0], $itemnumber), 'notReservable',
370
    "CanItemBeReserved should returns 'notReservable'");
374
    "CanItemBeReserved should returns 'notReservable'");
371
375
372
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem(
376
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem(
373
    { homebranch => 'MPL', holdingbranch => 'CPL', itype => 'CAN' } , $bibnum);
377
    { homebranch => $library2->{branchcode}, holdingbranch => $library1->{branchcode}, itype => 'CAN' } , $bibnum);
374
is(CanItemBeReserved($borrowernumbers[0], $itemnumber),
378
is(CanItemBeReserved($borrowernumbers[0], $itemnumber),
375
    'cannotReserveFromOtherBranches',
379
    'cannotReserveFromOtherBranches',
376
    "CanItemBeReserved should returns 'cannotReserveFromOtherBranches'");
380
    "CanItemBeReserved should returns 'cannotReserveFromOtherBranches'");
377
381
378
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem(
382
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem(
379
    { homebranch => 'CPL', holdingbranch => 'CPL', itype => 'CAN' } , $bibnum);
383
    { homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode}, itype => 'CAN' } , $bibnum);
380
is(CanItemBeReserved($borrowernumbers[0], $itemnumber), 'OK',
384
is(CanItemBeReserved($borrowernumbers[0], $itemnumber), 'OK',
381
    "CanItemBeReserved should returns 'OK'");
385
    "CanItemBeReserved should returns 'OK'");
382
386
Lines 427-433 $dbh->do('DELETE FROM items'); Link Here
427
$dbh->do('DELETE FROM biblio');
431
$dbh->do('DELETE FROM biblio');
428
432
429
( $bibnum, $title, $bibitemnum ) = create_helper_biblio('ONLY1');
433
( $bibnum, $title, $bibitemnum ) = create_helper_biblio('ONLY1');
430
( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem( { homebranch => 'CPL', holdingbranch => 'CPL' }, $bibnum );
434
( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem( { homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} }, $bibnum );
431
435
432
$dbh->do(
436
$dbh->do(
433
    q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed)
437
    q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed)
Lines 438-444 $dbh->do( Link Here
438
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber ),
442
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber ),
439
    'OK', 'Patron can reserve item with hold limit of 1, no holds placed' );
443
    'OK', 'Patron can reserve item with hold limit of 1, no holds placed' );
440
444
441
my $res_id = AddReserve( $branch, $borrowernumbers[0], $bibnum, '', 1, );
445
my $res_id = AddReserve( $library1->{branchcode}, $borrowernumbers[0], $bibnum, '', 1, );
442
446
443
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber ),
447
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber ),
444
    'tooManyReserves', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' );
448
    'tooManyReserves', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' );
(-)a/t/db_dependent/Holds/LocalHoldsPriority.t (-5 / +18 lines)
Lines 12-38 use C4::Biblio; Link Here
12
use C4::Items;
12
use C4::Items;
13
use C4::Members;
13
use C4::Members;
14
14
15
use t::lib::TestBuilder;
16
15
BEGIN {
17
BEGIN {
16
    use FindBin;
18
    use FindBin;
17
    use lib $FindBin::Bin;
19
    use lib $FindBin::Bin;
18
    use_ok('C4::Reserves');
20
    use_ok('C4::Reserves');
19
}
21
}
20
22
23
my $builder = t::lib::TestBuilder->new;
21
my $dbh = C4::Context->dbh;
24
my $dbh = C4::Context->dbh;
22
23
# Start transaction
24
$dbh->{AutoCommit} = 0;
25
$dbh->{RaiseError} = 1;
25
$dbh->{RaiseError} = 1;
26
26
27
my $library1 = $builder->build({
28
    source => 'Branch',
29
});
30
my $library2 = $builder->build({
31
    source => 'Branch',
32
});
33
my $library3 = $builder->build({
34
    source => 'Branch',
35
});
36
my $library4 = $builder->build({
37
    source => 'Branch',
38
});
39
27
my $borrowers_count = 5;
40
my $borrowers_count = 5;
28
41
29
# Create a helper biblio
42
# Create a helper biblio
30
my ( $bibnum, $title, $bibitemnum ) = create_helper_biblio();
43
my ( $bibnum, $title, $bibitemnum ) = create_helper_biblio();
31
# Create a helper item for the biblio.
44
# Create a helper item for the biblio.
32
my ( $item_bibnum, $item_bibitemnum, $itemnumber ) =
45
my ( $item_bibnum, $item_bibitemnum, $itemnumber ) =
33
  AddItem( { homebranch => 'MPL', holdingbranch => 'CPL' }, $bibnum );
46
  AddItem( { homebranch => $library4->{branchcode}, holdingbranch => $library3->{branchcode} }, $bibnum );
34
47
35
my @branchcodes = qw{XXX RPL CPL MPL CPL MPL};
48
my @branchcodes = ( $library1->{branchcode}, $library2->{branchcode}, $library3->{branchcode}, $library4->{branchcode}, $library3->{branchcode}, $library4->{branchcode} );
36
49
37
# Create some borrowers
50
# Create some borrowers
38
my @borrowernumbers;
51
my @borrowernumbers;
(-)a/t/db_dependent/Holds/RevertWaitingStatus.t (-6 / +10 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 $builder = t::lib::TestBuilder->new;
19
$dbh->{AutoCommit} = 0;
19
my $dbh = C4::Context->dbh;
20
$dbh->{RaiseError} = 1;
20
$dbh->{RaiseError} = 1;
21
21
22
$dbh->do("DELETE FROM reserves");
22
$dbh->do("DELETE FROM reserves");
23
$dbh->do("DELETE FROM old_reserves");
23
$dbh->do("DELETE FROM old_reserves");
24
24
25
my $library = $builder->build({
26
    source => 'Branch',
27
});
28
25
local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /redefined/ };
29
local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /redefined/ };
26
*C4::Context::userenv = \&Mock_userenv;
30
*C4::Context::userenv = \&Mock_userenv;
27
31
28
sub Mock_userenv {
32
sub Mock_userenv {
29
    my $userenv = { flags => 1, id => '1', branch => 'CPL' };
33
    my $userenv = { flags => 1, id => '1', branch => $library->{branchcode} };
30
    return $userenv;
34
    return $userenv;
31
}
35
}
32
36
Lines 41-47 my ( $bibnum, $title, $bibitemnum ) = create_helper_biblio(); Link Here
41
diag("Creating item instance for testing.");
45
diag("Creating item instance for testing.");
42
my $item_barcode = 'my_barcode';
46
my $item_barcode = 'my_barcode';
43
my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
47
my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
44
    { homebranch => 'CPL', holdingbranch => 'CPL', barcode => $item_barcode },
48
    { homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, barcode => $item_barcode },
45
    $bibnum );
49
    $bibnum );
46
50
47
# Create some borrowers
51
# Create some borrowers
Lines 51-57 foreach my $i ( 1 .. $borrowers_count ) { Link Here
51
        firstname    => 'my firstname',
55
        firstname    => 'my firstname',
52
        surname      => 'my surname ' . $i,
56
        surname      => 'my surname ' . $i,
53
        categorycode => 'S',
57
        categorycode => 'S',
54
        branchcode   => 'CPL',
58
        branchcode   => $library->{branchcode},
55
    );
59
    );
56
    push @borrowernumbers, $borrowernumber;
60
    push @borrowernumbers, $borrowernumber;
57
}
61
}
(-)a/t/db_dependent/HoldsQueue.t (-54 / +45 lines)
Lines 14-24 use Data::Dumper; Link Here
14
14
15
use Test::More tests => 21;
15
use Test::More tests => 21;
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;
21
20
21
use t::lib::TestBuilder;
22
22
BEGIN {
23
BEGIN {
23
    use FindBin;
24
    use FindBin;
24
    use lib $FindBin::Bin;
25
    use lib $FindBin::Bin;
Lines 26-54 BEGIN { Link Here
26
    use_ok('C4::HoldsQueue');
27
    use_ok('C4::HoldsQueue');
27
}
28
}
28
29
29
# Start transaction
30
my $builder = t::lib::TestBuilder->new;
30
my $dbh = C4::Context->dbh;
31
my $dbh = C4::Context->dbh;
31
$dbh->{AutoCommit} = 0;
32
$dbh->{RaiseError} = 1;
32
$dbh->{RaiseError} = 1;
33
$dbh->{AutoCommit} = 0;
34
35
my $library1 = $builder->build({
36
    source => 'Branch',
37
});
38
my $library2 = $builder->build({
39
    source => 'Branch',
40
});
41
my $library3 = $builder->build({
42
    source => 'Branch',
43
});
33
44
34
my $TITLE = "Test Holds Queue XXX";
45
my $TITLE = "Test Holds Queue XXX";
35
46
36
my %data = (
47
my $borrower = $builder->build({
37
    cardnumber => 'CARDNUMBER42',
48
    source => 'Borrower',
38
    firstname =>  'my firstname',
49
    value => {
39
    surname => 'my surname',
50
        categorycode => 'S',
40
    categorycode => 'S',
51
        branchcode => $library1->{branchcode},
41
    branchcode => 'CPL',
52
    }
42
);
53
});
43
54
44
my $borrowernumber = AddMember(%data);
55
my $borrowernumber = $borrower->{borrowernumber};
45
my $borrower = GetMember( borrowernumber => $borrowernumber );
46
# Set special (for this test) branches
56
# Set special (for this test) branches
47
my $borrower_branchcode = $borrower->{branchcode};
57
my $borrower_branchcode = $borrower->{branchcode};
48
my $branches = C4::Branch::GetBranches;
58
my @branchcodes = ( $library1->{branchcode}, $library2->{branchcode}, $library3->{branchcode} );
49
my @other_branches = grep { $_ ne $borrower_branchcode } keys %$branches;
59
my @other_branches = ( $library2->{branchcode}, $library3->{branchcode} );
50
my $least_cost_branch_code = pop @other_branches
60
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;
61
my @item_types = C4::ItemType->all;
53
my $itemtype = grep { $_->{notforloan} == 1 } @item_types
62
my $itemtype = grep { $_->{notforloan} == 1 } @item_types
54
  or BAIL_OUT("No adequate itemtype");
63
  or BAIL_OUT("No adequate itemtype");
Lines 155-163 ok( Link Here
155
# XXX All this tests are for borrower branch pick-up.
164
# XXX All this tests are for borrower branch pick-up.
156
# Maybe needs expanding to homebranch or holdingbranch pick-up.
165
# Maybe needs expanding to homebranch or holdingbranch pick-up.
157
166
158
# Cleanup
159
$dbh->rollback;
160
161
### Test holds queue builder does not violate holds policy ###
167
### Test holds queue builder does not violate holds policy ###
162
168
163
# Clear out existing rules relating to holdallowed
169
# Clear out existing rules relating to holdallowed
Lines 167-205 $dbh->do("DELETE FROM default_circ_rules"); Link Here
167
173
168
C4::Context->set_preference('UseTransportCostMatrix', 0);
174
C4::Context->set_preference('UseTransportCostMatrix', 0);
169
175
170
my @branchcodes = keys %$branches;
171
( $itemtype ) = @{ $dbh->selectrow_arrayref("SELECT itemtype FROM itemtypes LIMIT 1") };
176
( $itemtype ) = @{ $dbh->selectrow_arrayref("SELECT itemtype FROM itemtypes LIMIT 1") };
172
177
173
my $borrowernumber1 = AddMember(
178
my $borrower1 = $builder->build({
174
    (
179
    source => 'Borrower',
175
        cardnumber   => 'CARDNUMBER1',
180
    value => {
176
        firstname    => 'Firstname',
177
        surname      => 'Surname',
178
        categorycode => 'S',
181
        categorycode => 'S',
179
        branchcode   => $branchcodes[0],
182
        branchcode => $branchcodes[0],
180
    )
183
    },
181
);
184
});
182
my $borrowernumber2 = AddMember(
185
my $borrower2 = $builder->build({
183
    (
186
    source => 'Borrower',
184
        cardnumber   => 'CARDNUMBER2',
187
    value => {
185
        firstname    => 'Firstname',
186
        surname      => 'Surname',
187
        categorycode => 'S',
188
        categorycode => 'S',
188
        branchcode   => $branchcodes[1],
189
        branchcode => $branchcodes[1],
189
    )
190
    },
190
);
191
});
191
my $borrowernumber3 = AddMember(
192
my $borrower3 = $builder->build({
192
    (
193
    source => 'Borrower',
193
        cardnumber   => 'CARDNUMBER3',
194
    value => {
194
        firstname    => 'Firstname',
195
        surname      => 'Surname',
196
        categorycode => 'S',
195
        categorycode => 'S',
197
        branchcode   => $branchcodes[2],
196
        branchcode => $branchcodes[2],
198
    )
197
    },
199
);
198
});
200
my $borrower1 = GetMember( borrowernumber => $borrowernumber1 );
201
my $borrower2 = GetMember( borrowernumber => $borrowernumber2 );
202
my $borrower3 = GetMember( borrowernumber => $borrowernumber3 );
203
199
204
$dbh->do(qq{
200
$dbh->do(qq{
205
    INSERT INTO biblio (
201
    INSERT INTO biblio (
Lines 277-284 my $sth = $dbh->prepare(q{ Link Here
277
$sth->execute( $borrower1->{borrowernumber}, $biblionumber, $branchcodes[0], 1 );
273
$sth->execute( $borrower1->{borrowernumber}, $biblionumber, $branchcodes[0], 1 );
278
$sth->execute( $borrower2->{borrowernumber}, $biblionumber, $branchcodes[0], 2 );
274
$sth->execute( $borrower2->{borrowernumber}, $biblionumber, $branchcodes[0], 2 );
279
$sth->execute( $borrower3->{borrowernumber}, $biblionumber, $branchcodes[0], 3 );
275
$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
276
283
my $holds_queue;
277
my $holds_queue;
284
278
Lines 287-294 $dbh->do("INSERT INTO default_circ_rules ( holdallowed ) VALUES ( 1 )"); Link Here
287
C4::HoldsQueue::CreateQueue();
281
C4::HoldsQueue::CreateQueue();
288
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
282
$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'" );
283
ok( @$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'");
284
is( $holds_queue->[0]->{cardnumber}, $borrower2->{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'");
285
is( $holds_queue->[1]->{cardnumber}, $borrower1->{cardnumber}, "Holds queue filling 2nd correct hold for default holds policy 'from home library'");
292
286
293
$dbh->do("DELETE FROM default_circ_rules");
287
$dbh->do("DELETE FROM default_circ_rules");
294
$dbh->do("INSERT INTO default_circ_rules ( holdallowed ) VALUES ( 2 )");
288
$dbh->do("INSERT INTO default_circ_rules ( holdallowed ) VALUES ( 2 )");
Lines 297-305 $holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice Link Here
297
ok( @$holds_queue == 3, "Holds queue filling correct number for holds for default holds policy 'from any library'" );
291
ok( @$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 );
292
#warn "HOLDS QUEUE: " . Data::Dumper::Dumper( $holds_queue );
299
293
300
# Cleanup
301
$dbh->rollback;
302
303
### END Test holds queue builder does not violate holds policy ###
294
### END Test holds queue builder does not violate holds policy ###
304
295
305
sub test_queue {
296
sub test_queue {
(-)a/t/db_dependent/Items.t (-86 / +81 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 35-58 BEGIN { Link Here
35
}
36
}
36
37
37
my $dbh = C4::Context->dbh;
38
my $dbh = C4::Context->dbh;
38
my $branches = GetBranches;
39
my ($branch1, $branch2) = keys %$branches;
40
my $location = 'My Location';
39
my $location = 'My Location';
41
40
42
subtest 'General Add, Get and Del tests' => sub {
41
subtest 'General Add, Get and Del tests' => sub {
43
42
44
    plan tests => 10;
43
    plan tests => 10;
45
44
46
    # Start transaction
45
    my $builder = t::lib::TestBuilder->new;
47
    $dbh->{AutoCommit} = 0;
46
    my $library = $builder->build({
48
    $dbh->{RaiseError} = 1;
47
        source => 'Branch',
48
    });
49
49
50
    # Create a biblio instance for testing
50
    # Create a biblio instance for testing
51
    C4::Context->set_preference('marcflavour', 'MARC21');
51
    C4::Context->set_preference('marcflavour', 'MARC21');
52
    my ($bibnum, $bibitemnum) = get_biblio();
52
    my ($bibnum, $bibitemnum) = get_biblio();
53
53
54
    # Add an item.
54
    # Add an item.
55
    my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch1, holdingbranch => $branch1, location => $location } , $bibnum);
55
    my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location } , $bibnum);
56
    cmp_ok($item_bibnum, '==', $bibnum, "New item is linked to correct biblionumber.");
56
    cmp_ok($item_bibnum, '==', $bibnum, "New item is linked to correct biblionumber.");
57
    cmp_ok($item_bibitemnum, '==', $bibitemnum, "New item is linked to correct biblioitemnumber.");
57
    cmp_ok($item_bibitemnum, '==', $bibitemnum, "New item is linked to correct biblioitemnumber.");
58
58
Lines 73-84 subtest 'General Add, Get and Del tests' => sub { Link Here
73
    my $getdeleted = GetItem($itemnumber);
73
    my $getdeleted = GetItem($itemnumber);
74
    is($getdeleted->{'itemnumber'}, undef, "Item deleted as expected.");
74
    is($getdeleted->{'itemnumber'}, undef, "Item deleted as expected.");
75
75
76
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch1, holdingbranch => $branch1, location => $location, permanent_location => 'my permanent location' } , $bibnum);
76
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, permanent_location => 'my permanent location' } , $bibnum);
77
    $getitem = GetItem($itemnumber);
77
    $getitem = GetItem($itemnumber);
78
    is( $getitem->{location}, $location, "The location should not have been modified" );
78
    is( $getitem->{location}, $location, "The location should not have been modified" );
79
    is( $getitem->{permanent_location}, 'my permanent location', "The permanent_location should not have modified" );
79
    is( $getitem->{permanent_location}, 'my permanent location', "The permanent_location should not have modified" );
80
81
    $dbh->rollback;
82
};
80
};
83
81
84
subtest 'GetHiddenItemnumbers tests' => sub {
82
subtest 'GetHiddenItemnumbers tests' => sub {
Lines 87-118 subtest 'GetHiddenItemnumbers tests' => sub { Link Here
87
85
88
    # This sub is controlled by the OpacHiddenItems system preference.
86
    # This sub is controlled by the OpacHiddenItems system preference.
89
87
90
    # Start transaction
88
    my $builder = t::lib::TestBuilder->new;
91
    $dbh->{AutoCommit} = 0;
89
    my $library1 = $builder->build({
92
    $dbh->{RaiseError} = 1;
90
        source => 'Branch',
91
    });
92
93
    my $library2 = $builder->build({
94
        source => 'Branch',
95
    });
93
96
94
    # Create a new biblio
97
    # Create a new biblio
95
    C4::Context->set_preference('marcflavour', 'MARC21');
98
    C4::Context->set_preference('marcflavour', 'MARC21');
96
    my ($biblionumber, $biblioitemnumber) = get_biblio();
99
    my ($biblionumber, $biblioitemnumber) = get_biblio();
97
100
98
    # Add branches if they don't exist
99
    if (not defined GetBranchDetail('CPL')) {
100
        ModBranch({add => 1, branchcode => 'CPL', branchname => 'Centerville'});
101
    }
102
    if (not defined GetBranchDetail('MPL')) {
103
        ModBranch({add => 1, branchcode => 'MPL', branchname => 'Midway'});
104
    }
105
106
    # Add two items
101
    # Add two items
107
    my ($item1_bibnum, $item1_bibitemnum, $item1_itemnumber) = AddItem(
102
    my ($item1_bibnum, $item1_bibitemnum, $item1_itemnumber) = AddItem(
108
            { homebranch => $branch1,
103
            { homebranch => $library1->{branchcode},
109
              holdingbranch => $branch1,
104
              holdingbranch => $library1->{branchcode},
110
              withdrawn => 1 },
105
              withdrawn => 1 },
111
            $biblionumber
106
            $biblionumber
112
    );
107
    );
113
    my ($item2_bibnum, $item2_bibitemnum, $item2_itemnumber) = AddItem(
108
    my ($item2_bibnum, $item2_bibitemnum, $item2_itemnumber) = AddItem(
114
            { homebranch => $branch2,
109
            { homebranch => $library2->{branchcode},
115
              holdingbranch => $branch2,
110
              holdingbranch => $library2->{branchcode},
116
              withdrawn => 0 },
111
              withdrawn => 0 },
117
            $biblionumber
112
            $biblionumber
118
    );
113
    );
Lines 153-195 subtest 'GetHiddenItemnumbers tests' => sub { Link Here
153
    # Two variables, a value each
148
    # Two variables, a value each
154
    $opachiddenitems = "
149
    $opachiddenitems = "
155
        withdrawn: [1]
150
        withdrawn: [1]
156
        homebranch: [$branch2]
151
        homebranch: [$library2->{branchcode}]
157
    ";
152
    ";
158
    C4::Context->set_preference( 'OpacHiddenItems', $opachiddenitems );
153
    C4::Context->set_preference( 'OpacHiddenItems', $opachiddenitems );
159
    @hidden = GetHiddenItemnumbers( @items );
154
    @hidden = GetHiddenItemnumbers( @items );
160
    ok( scalar @hidden == 2, "Two items hidden");
155
    ok( scalar @hidden == 2, "Two items hidden");
161
    is_deeply( \@hidden, \@itemnumbers, "withdrawn=1 and homebranch=MPL hidden");
156
    is_deeply( \@hidden, \@itemnumbers, "withdrawn=1 and homebranch library2 hidden");
162
157
163
    # Valid OpacHiddenItems, empty list
158
    # Valid OpacHiddenItems, empty list
164
    @items = ();
159
    @items = ();
165
    @hidden = GetHiddenItemnumbers( @items );
160
    @hidden = GetHiddenItemnumbers( @items );
166
    ok( scalar @hidden == 0, "Empty items list, no item hidden");
161
    ok( scalar @hidden == 0, "Empty items list, no item hidden");
167
168
    $dbh->rollback;
169
};
162
};
170
163
171
subtest 'GetItemsInfo tests' => sub {
164
subtest 'GetItemsInfo tests' => sub {
172
165
173
    plan tests => 4;
166
    plan tests => 4;
174
167
175
    # Start transaction
168
    my $builder = t::lib::TestBuilder->new;
176
    $dbh->{AutoCommit} = 0;
169
    my $library1 = $builder->build({
177
    $dbh->{RaiseError} = 1;
170
        source => 'Branch',
171
    });
172
    my $library2 = $builder->build({
173
        source => 'Branch',
174
    });
178
175
179
    # Add a biblio
176
    # Add a biblio
180
    my ($biblionumber, $biblioitemnumber) = get_biblio();
177
    my ($biblionumber, $biblioitemnumber) = get_biblio();
181
    # Add an item
178
    # Add an item
182
    my ($item_bibnum, $item_bibitemnum, $itemnumber)
179
    my ($item_bibnum, $item_bibitemnum, $itemnumber)
183
        = AddItem({
180
        = AddItem({
184
                homebranch    => $branch1,
181
                homebranch    => $library1->{branchcode},
185
                holdingbranch => $branch2
182
                holdingbranch => $library2->{branchcode},
186
            }, $biblionumber );
183
            }, $biblionumber );
187
184
188
    my $branch = GetBranchDetail( $branch1 );
185
    my $branch = GetBranchDetail( $library1->{branchcode} );
189
    $branch->{ opac_info } = "homebranch OPAC info";
186
    $branch->{ opac_info } = "homebranch OPAC info";
190
    ModBranch($branch);
187
    ModBranch($branch);
191
188
192
    $branch = GetBranchDetail( $branch2 );
189
    $branch = GetBranchDetail( $library2->{branchcode} );
193
    $branch->{ opac_info } = "holdingbranch OPAC info";
190
    $branch->{ opac_info } = "holdingbranch OPAC info";
194
    ModBranch($branch);
191
    ModBranch($branch);
195
192
Lines 201-217 subtest 'GetItemsInfo tests' => sub { Link Here
201
        'GetItemsInfo returns the correct holding branch OPAC info notice' );
198
        'GetItemsInfo returns the correct holding branch OPAC info notice' );
202
    is( exists( $results[0]->{ onsite_checkout } ), 1,
199
    is( exists( $results[0]->{ onsite_checkout } ), 1,
203
        'GetItemsInfo returns a onsite_checkout key' );
200
        'GetItemsInfo returns a onsite_checkout key' );
204
205
    $dbh->rollback;
206
};
201
};
207
202
208
subtest q{Test Koha::Database->schema()->resultset('Item')->itemtype()} => sub {
203
subtest q{Test Koha::Database->schema()->resultset('Item')->itemtype()} => sub {
209
204
210
    plan tests => 4;
205
    plan tests => 4;
211
206
212
    # Start transaction
207
    my $builder = t::lib::TestBuilder->new;
213
    $dbh->{AutoCommit} = 0;
214
    $dbh->{RaiseError} = 1;
215
208
216
    my $schema = Koha::Database->new()->schema();
209
    my $schema = Koha::Database->new()->schema();
217
210
Lines 249-288 subtest q{Test Koha::Database->schema()->resultset('Item')->itemtype()} => sub { Link Here
249
    ok( defined $effective_itemtype &&
242
    ok( defined $effective_itemtype &&
250
                $effective_itemtype eq 'BIB_LEVEL',
243
                $effective_itemtype eq 'BIB_LEVEL',
251
        '$item->effective_itemtype() falls back to biblioitems.itemtype when item-level_itypes is enabled but undef' );
244
        '$item->effective_itemtype() falls back to biblioitems.itemtype when item-level_itypes is enabled but undef' );
252
253
    $dbh->rollback;
254
};
245
};
255
246
256
subtest 'SearchItems test' => sub {
247
subtest 'SearchItems test' => sub {
257
    plan tests => 14;
248
    plan tests => 14;
258
249
259
    # Start transaction
250
    my $builder = t::lib::TestBuilder->new;
260
    $dbh->{AutoCommit} = 0;
251
    my $dbh = C4::Context->dbh;
261
    $dbh->{RaiseError} = 1;
252
253
    my $library1 = $builder->build({
254
        source => 'Branch',
255
    });
256
    my $library2 = $builder->build({
257
        source => 'Branch',
258
    });
262
259
263
    C4::Context->set_preference('marcflavour', 'MARC21');
260
    C4::Context->set_preference('marcflavour', 'MARC21');
264
    my $cpl_items_before = SearchItemsByField( 'homebranch', 'CPL');
261
    my $cpl_items_before = SearchItemsByField( 'homebranch', $library1->{branchcode});
265
262
266
    my ($biblionumber) = get_biblio();
263
    my ($biblionumber) = get_biblio();
267
264
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});
265
    my (undef, $initial_items_count) = SearchItems(undef, {rows => 1});
277
266
278
    # Add two items
267
    # Add two items
279
    my (undef, undef, $item1_itemnumber) = AddItem({
268
    my (undef, undef, $item1_itemnumber) = AddItem({
280
        homebranch => 'CPL',
269
        homebranch => $library1->{branchcode},
281
        holdingbranch => 'CPL',
270
        holdingbranch => $library1->{branchcode},
282
    }, $biblionumber);
271
    }, $biblionumber);
283
    my (undef, undef, $item2_itemnumber) = AddItem({
272
    my (undef, undef, $item2_itemnumber) = AddItem({
284
        homebranch => 'MPL',
273
        homebranch => $library2->{branchcode},
285
        holdingbranch => 'MPL',
274
        holdingbranch => $library2->{branchcode},
286
    }, $biblionumber);
275
    }, $biblionumber);
287
276
288
    my ($items, $total_results);
277
    my ($items, $total_results);
Lines 298-311 subtest 'SearchItems test' => sub { Link Here
298
    # Search all items where homebranch = 'CPL'
287
    # Search all items where homebranch = 'CPL'
299
    my $filter = {
288
    my $filter = {
300
        field => 'homebranch',
289
        field => 'homebranch',
301
        query => 'CPL',
290
        query => $library1->{branchcode},
302
        operator => '=',
291
        operator => '=',
303
    };
292
    };
304
    ($items, $total_results) = SearchItems($filter);
293
    ($items, $total_results) = SearchItems($filter);
305
    ok($total_results > 0, "There is at least one CPL item");
294
    ok($total_results > 0, "There is at least one CPL item");
306
    my $all_items_are_CPL = 1;
295
    my $all_items_are_CPL = 1;
307
    foreach my $item (@$items) {
296
    foreach my $item (@$items) {
308
        if ($item->{homebranch} ne 'CPL') {
297
        if ($item->{homebranch} ne $library1->{branchcode}) {
309
            $all_items_are_CPL = 0;
298
            $all_items_are_CPL = 0;
310
            last;
299
            last;
311
        }
300
        }
Lines 315-328 subtest 'SearchItems test' => sub { Link Here
315
    # Search all items where homebranch != 'CPL'
304
    # Search all items where homebranch != 'CPL'
316
    $filter = {
305
    $filter = {
317
        field => 'homebranch',
306
        field => 'homebranch',
318
        query => 'CPL',
307
        query => $library1->{branchcode},
319
        operator => '!=',
308
        operator => '!=',
320
    };
309
    };
321
    ($items, $total_results) = SearchItems($filter);
310
    ($items, $total_results) = SearchItems($filter);
322
    ok($total_results > 0, "There is at least one non-CPL item");
311
    ok($total_results > 0, "There is at least one non-CPL item");
323
    my $all_items_are_not_CPL = 1;
312
    my $all_items_are_not_CPL = 1;
324
    foreach my $item (@$items) {
313
    foreach my $item (@$items) {
325
        if ($item->{homebranch} eq 'CPL') {
314
        if ($item->{homebranch} eq $library1->{branchcode}) {
326
            $all_items_are_not_CPL = 0;
315
            $all_items_are_not_CPL = 0;
327
            last;
316
            last;
328
        }
317
        }
Lines 350-356 subtest 'SearchItems test' => sub { Link Here
350
            },
339
            },
351
            {
340
            {
352
                field => 'homebranch',
341
                field => 'homebranch',
353
                query => 'CPL',
342
                query => $library1->{branchcode},
354
                operator => '=',
343
                operator => '=',
355
            },
344
            },
356
        ],
345
        ],
Lines 411-435 subtest 'SearchItems test' => sub { Link Here
411
    ($items, $total_results) = SearchItems($filter);
400
    ($items, $total_results) = SearchItems($filter);
412
    ok(scalar @$items == 1, 'found 1 item with itemnotes = "foobar"');
401
    ok(scalar @$items == 1, 'found 1 item with itemnotes = "foobar"');
413
402
414
    my $cpl_items_after = SearchItemsByField( 'homebranch', 'CPL');
403
    my $cpl_items_after = SearchItemsByField( 'homebranch', $library1->{branchcode});
415
    is( ( scalar( @$cpl_items_after ) - scalar ( @$cpl_items_before ) ), 1, 'SearchItemsByField should return something' );
404
    is( ( scalar( @$cpl_items_after ) - scalar ( @$cpl_items_before ) ), 1, 'SearchItemsByField should return something' );
416
417
    $dbh->rollback;
418
};
405
};
419
406
420
subtest 'Koha::Item(s) tests' => sub {
407
subtest 'Koha::Item(s) tests' => sub {
421
408
422
    plan tests => 5;
409
    plan tests => 5;
423
410
424
    # Start transaction
411
    my $builder = t::lib::TestBuilder->new;
425
    my $schema = Koha::Database->new()->schema();
412
    my $library1 = $builder->build({
426
    $schema->storage->txn_begin();
413
        source => 'Branch',
427
    $dbh->{RaiseError} = 1;
414
    });
415
    my $library2 = $builder->build({
416
        source => 'Branch',
417
    });
428
418
429
    # Create a biblio and item for testing
419
    # Create a biblio and item for testing
430
    C4::Context->set_preference('marcflavour', 'MARC21');
420
    C4::Context->set_preference('marcflavour', 'MARC21');
431
    my ($bibnum, $bibitemnum) = get_biblio();
421
    my ($bibnum, $bibitemnum) = get_biblio();
432
    my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch1, holdingbranch => $branch2 } , $bibnum);
422
    my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library1->{branchcode}, holdingbranch => $library2->{branchcode} } , $bibnum);
433
423
434
    # Get item.
424
    # Get item.
435
    my $item = Koha::Items->find( $itemnumber );
425
    my $item = Koha::Items->find( $itemnumber );
Lines 437-469 subtest 'Koha::Item(s) tests' => sub { Link Here
437
427
438
    my $homebranch = $item->home_branch();
428
    my $homebranch = $item->home_branch();
439
    is( ref($homebranch), 'Koha::Branch', "Got Koha::Branch from home_branch method" );
429
    is( ref($homebranch), 'Koha::Branch', "Got Koha::Branch from home_branch method" );
440
    is( $homebranch->branchcode(), $branch1, "Home branch code matches homebranch" );
430
    is( $homebranch->branchcode(), $library1->{branchcode}, "Home branch code matches homebranch" );
441
431
442
    my $holdingbranch = $item->holding_branch();
432
    my $holdingbranch = $item->holding_branch();
443
    is( ref($holdingbranch), 'Koha::Branch', "Got Koha::Branch from holding_branch method" );
433
    is( ref($holdingbranch), 'Koha::Branch', "Got Koha::Branch from holding_branch method" );
444
    is( $holdingbranch->branchcode(), $branch2, "Home branch code matches holdingbranch" );
434
    is( $holdingbranch->branchcode(), $library2->{branchcode}, "Home branch code matches holdingbranch" );
445
};
435
};
446
436
447
subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub {
437
subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub {
448
    plan tests => 7;
438
    plan tests => 7;
449
439
450
    $dbh->{AutoCommit} = 0;
440
    my $builder = t::lib::TestBuilder->new;
451
    $dbh->{RaiseError} = 1;
441
    my $library1 = $builder->build({
442
        source => 'Branch',
443
    });
444
    my $library2 = $builder->build({
445
        source => 'Branch',
446
    });
452
447
453
    my ( $biblionumber, $biblioitemnumber ) = get_biblio();
448
    my ( $biblionumber, $biblioitemnumber ) = get_biblio();
454
    my $item_infos = [
449
    my $item_infos = [
455
        { homebranch => 'CPL', holdingbranch => 'CPL' },
450
        { homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} },
456
        { homebranch => 'CPL', holdingbranch => 'CPL' },
451
        { homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} },
457
        { homebranch => 'CPL', holdingbranch => 'CPL' },
452
        { homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} },
458
        { homebranch => 'MPL', holdingbranch => 'MPL' },
453
        { homebranch => $library2->{branchcode}, holdingbranch => $library2->{branchcode} },
459
        { homebranch => 'MPL', holdingbranch => 'MPL' },
454
        { homebranch => $library2->{branchcode}, holdingbranch => $library2->{branchcode} },
460
        { homebranch => 'CPL', holdingbranch => 'MPL' },
455
        { homebranch => $library1->{branchcode}, holdingbranch => $library2->{branchcode} },
461
        { homebranch => 'CPL', holdingbranch => 'MPL' },
456
        { homebranch => $library1->{branchcode}, holdingbranch => $library2->{branchcode} },
462
        { homebranch => 'CPL', holdingbranch => 'MPL' },
457
        { homebranch => $library1->{branchcode}, holdingbranch => $library2->{branchcode} },
463
    ];
458
    ];
464
    my $number_of_items = scalar @$item_infos;
459
    my $number_of_items = scalar @$item_infos;
465
    my $number_of_items_with_homebranch_is_CPL =
460
    my $number_of_items_with_homebranch_is_CPL =
466
      grep { $_->{homebranch} eq 'CPL' } @$item_infos;
461
      grep { $_->{homebranch} eq $library1->{branchcode} } @$item_infos;
467
462
468
    my @itemnumbers;
463
    my @itemnumbers;
469
    for my $item_info (@$item_infos) {
464
    for my $item_info (@$item_infos) {
Lines 501-507 subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { Link Here
501
    is( scalar @items, $number_of_items, 'Should return all items for opac' );
496
    is( scalar @items, $number_of_items, 'Should return all items for opac' );
502
497
503
    my $opachiddenitems = "
498
    my $opachiddenitems = "
504
        homebranch: ['CPL']";
499
        homebranch: ['$library1->{branchcode}']";
505
    t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems );
500
    t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems );
506
501
507
    C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber );
502
    C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber );
Lines 519-525 subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { Link Here
519
    );
514
    );
520
515
521
    $opachiddenitems = "
516
    $opachiddenitems = "
522
        homebranch: ['CPL', 'MPL']";
517
        homebranch: ['$library1->{branchcode}', '$library2->{branchcode}']";
523
    t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems );
518
    t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems );
524
    C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, undef, 1 );
519
    C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, undef, 1 );
525
    @items = $record->field($itemfield);
520
    @items = $record->field($itemfield);
(-)a/t/db_dependent/Items_DelItem.t (-3 / +9 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
14
my $builder = t::lib::TestBuilder->new;
12
my $dbh = C4::Context->dbh;
15
my $dbh = C4::Context->dbh;
13
$dbh->{AutoCommit} = 0;
14
$dbh->{RaiseError} = 1;
16
$dbh->{RaiseError} = 1;
15
17
18
my $library = $builder->build({
19
    source => 'Branch',
20
});
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 / +11 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
25
use t::lib::TestBuilder;
26
24
BEGIN {
27
BEGIN {
25
    use_ok('Koha::Template::Plugin::Branches');
28
    use_ok('Koha::Template::Plugin::Branches');
26
}
29
}
27
30
31
my $builder = t::lib::TestBuilder->new;
32
my $library = $builder->build({
33
    source => 'Branch',
34
});
35
28
my $plugin = Koha::Template::Plugin::Branches->new();
36
my $plugin = Koha::Template::Plugin::Branches->new();
29
ok($plugin, "initialized Branches plugin");
37
ok($plugin, "initialized Branches plugin");
30
38
31
my $name = $plugin->GetName('CPL');
39
my $name = $plugin->GetName($library->{branchcode});
32
is($name, 'Centerville', 'retrieved expected name for CPL');
40
is($name, $library->{branchname}, 'retrieved expected name for library');
33
41
34
$name = $plugin->GetName('__ANY__');
42
$name = $plugin->GetName('__ANY__');
35
is($name, '', 'received empty string as name of the "__ANY__" placeholder library code');
43
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);
45
$name = $plugin->GetName(undef);
38
is($name, '', 'received empty string as name of NULL/undefined library code');
46
is($name, '', 'received empty string as name of NULL/undefined library code');
39
47
40
my $library = $plugin->GetLoggedInBranchcode();
48
$library = $plugin->GetLoggedInBranchcode();
41
is($library, '', 'no active library if there is no active user session');
49
is($library, '', 'no active library if there is no active user session');
42
50
43
C4::Context->_new_userenv('DUMMY_SESSION_ID');
51
C4::Context->_new_userenv('DUMMY_SESSION_ID');
(-)a/t/db_dependent/Languages.t (+1 lines)
Lines 30-35 ok(C4::Languages::getAllLanguages(), 'test get all languages'); Link Here
30
C4::Context->set_preference('AdvancedSearchLanguages', '');
30
C4::Context->set_preference('AdvancedSearchLanguages', '');
31
my $all_languages = C4::Languages::getAllLanguages('eng');
31
my $all_languages = C4::Languages::getAllLanguages('eng');
32
ok(@$all_languages > 10, 'retrieved a bunch of languges');
32
ok(@$all_languages > 10, 'retrieved a bunch of languges');
33
warn Data::Dumper::Dumper $all_languages;
33
34
34
my $languages = C4::Languages::getLanguages('eng');
35
my $languages = C4::Languages::getLanguages('eng');
35
is_deeply($languages, $all_languages, 'getLanguages() and getAllLanguages() return the same list');
36
is_deeply($languages, $all_languages, 'getLanguages() and getAllLanguages() return the same list');
(-)a/t/db_dependent/Letters.t (-21 / +16 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;
45
use Koha::DateUtils qw( dt_from_string output_pref );
46
use Koha::DateUtils qw( dt_from_string output_pref );
46
use Koha::Acquisition::Order;
47
use Koha::Acquisition::Order;
47
use Koha::Acquisition::Bookseller;
48
use Koha::Acquisition::Bookseller;
48
use Koha::Database;
49
49
50
my $builder = t::lib::TestBuilder->new;
50
my $dbh = C4::Context->dbh;
51
my $dbh = C4::Context->dbh;
51
52
my $database = Koha::Database->new();
53
my $schema = $database->schema();
54
$schema->storage->txn_begin();
55
56
# Start transaction
57
$dbh->{RaiseError} = 1;
52
$dbh->{RaiseError} = 1;
58
53
59
$dbh->do(q|DELETE FROM letter|);
54
$dbh->do(q|DELETE FROM letter|);
60
$dbh->do(q|DELETE FROM message_queue|);
55
$dbh->do(q|DELETE FROM message_queue|);
61
$dbh->do(q|DELETE FROM message_transport_types|);
56
$dbh->do(q|DELETE FROM message_transport_types|);
62
57
58
my $library = $builder->build({
59
    source => 'Branch',
60
});
63
my $date = dt_from_string;
61
my $date = dt_from_string;
64
my $borrowernumber = AddMember(
62
my $borrowernumber = AddMember(
65
    firstname    => 'Jane',
63
    firstname    => 'Jane',
66
    surname      => 'Smith',
64
    surname      => 'Smith',
67
    categorycode => 'PT',
65
    categorycode => 'PT',
68
    branchcode   => 'CPL',
66
    branchcode   => $library->{branchcode},
69
    dateofbirth  => $date,
67
    dateofbirth  => $date,
70
);
68
);
71
69
Lines 157-174 Don't forget your date of birth: <<borrowers.dateofbirth>>. Link Here
157
Look at this wonderful biblio timestamp: <<biblio.timestamp>>.
155
Look at this wonderful biblio timestamp: <<biblio.timestamp>>.
158
};
156
};
159
157
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 );
158
$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();
159
$letters = C4::Letters::GetLetters();
162
is( @$letters, 1, 'GetLetters returns the correct number of letters' );
160
is( @$letters, 1, 'GetLetters returns the correct number of letters' );
163
is( $letters->[0]->{branchcode}, 'CPL', 'GetLetters gets the branch code correctly' );
161
is( $letters->[0]->{branchcode}, $library->{branchcode}, 'GetLetters gets the branch code correctly' );
164
is( $letters->[0]->{module}, 'my module', 'GetLetters gets the module correctly' );
162
is( $letters->[0]->{module}, 'my module', 'GetLetters gets the module correctly' );
165
is( $letters->[0]->{code}, 'my code', 'GetLetters gets the code correctly' );
163
is( $letters->[0]->{code}, 'my code', 'GetLetters gets the code correctly' );
166
is( $letters->[0]->{name}, 'my name', 'GetLetters gets the name correctly' );
164
is( $letters->[0]->{name}, 'my name', 'GetLetters gets the name correctly' );
167
165
168
166
169
# getletter
167
# getletter
170
my $letter = C4::Letters::getletter('my module', 'my code', 'CPL', 'email');
168
my $letter = C4::Letters::getletter('my module', 'my code', $library->{branchcode}, 'email');
171
is( $letter->{branchcode}, 'CPL', 'GetLetters gets the branch code correctly' );
169
is( $letter->{branchcode}, $library->{branchcode}, 'GetLetters gets the branch code correctly' );
172
is( $letter->{module}, 'my module', 'GetLetters gets the module correctly' );
170
is( $letter->{module}, 'my module', 'GetLetters gets the module correctly' );
173
is( $letter->{code}, 'my code', 'GetLetters gets the code correctly' );
171
is( $letter->{code}, 'my code', 'GetLetters gets the code correctly' );
174
is( $letter->{name}, 'my name', 'GetLetters gets the name correctly' );
172
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');
232
t::lib::Mocks::mock_preference('OPACBaseURL', 'http://thisisatest.com');
235
233
236
my $sms_content = 'This is a SMS for an <<status>>';
234
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 );
235
$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
236
239
my $tables = {
237
my $tables = {
240
    borrowers => $borrowernumber,
238
    borrowers => $borrowernumber,
241
    branches => 'CPL',
239
    branches => $library->{branchcode},
242
    biblio => $biblionumber,
240
    biblio => $biblionumber,
243
};
241
};
244
my $substitute = {
242
my $substitute = {
Lines 256-268 my $repeat = [ Link Here
256
];
254
];
257
my $prepared_letter = GetPreparedLetter((
255
my $prepared_letter = GetPreparedLetter((
258
    module      => 'my module',
256
    module      => 'my module',
259
    branchcode  => 'CPL',
257
    branchcode  => $library->{branchcode},
260
    letter_code => 'my code',
258
    letter_code => 'my code',
261
    tables      => $tables,
259
    tables      => $tables,
262
    substitute  => $substitute,
260
    substitute  => $substitute,
263
    repeat      => $repeat,
261
    repeat      => $repeat,
264
));
262
));
265
my $branch = GetBranchDetail('CPL');
263
my $branch = GetBranchDetail($library->{branchcode});
266
my $my_title_letter = qq|$branch->{branchname} - $substitute->{status}|;
264
my $my_title_letter = qq|$branch->{branchname} - $substitute->{status}|;
267
my $my_content_letter = qq|Dear Jane Smith,
265
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.
266
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
283
286
$prepared_letter = GetPreparedLetter((
284
$prepared_letter = GetPreparedLetter((
287
    module                 => 'my module',
285
    module                 => 'my module',
288
    branchcode             => 'CPL',
286
    branchcode             => $library->{branchcode},
289
    letter_code            => 'my code',
287
    letter_code            => 'my code',
290
    tables                 => $tables,
288
    tables                 => $tables,
291
    substitute             => $substitute,
289
    substitute             => $substitute,
Lines 417-423 my $borrowernumber = AddMember( Link Here
417
    firstname    => 'John',
415
    firstname    => 'John',
418
    surname      => 'Smith',
416
    surname      => 'Smith',
419
    categorycode => 'PT',
417
    categorycode => 'PT',
420
    branchcode   => 'CPL',
418
    branchcode   => $library->{branchcode},
421
    dateofbirth  => $date,
419
    dateofbirth  => $date,
422
    email        => 'john.smith@test.de',
420
    email        => 'john.smith@test.de',
423
);
421
);
Lines 433-438 is($err2, "", "Successfully sent serial notification"); Link Here
433
is($mail{'To'}, 'john.smith@test.de', "mailto correct in sent serial notification");
431
is($mail{'To'}, 'john.smith@test.de', "mailto correct in sent serial notification");
434
is($mail{'Message'}, 'Silence in the library,'.$subscriptionid.',No. 0', 'Serial notification text constructed successfully');
432
is($mail{'Message'}, 'Silence in the library,'.$subscriptionid.',No. 0', 'Serial notification text constructed successfully');
435
}
433
}
436
437
438
$schema->storage->txn_rollback();
(-)a/t/db_dependent/Members.t (-13 / +14 lines)
Lines 22-42 use Test::MockModule; Link Here
22
use Data::Dumper;
22
use Data::Dumper;
23
use C4::Context;
23
use C4::Context;
24
24
25
use t::lib::TestBuilder;
26
25
BEGIN {
27
BEGIN {
26
        use_ok('C4::Members');
28
        use_ok('C4::Members');
27
}
29
}
28
30
31
my $builder = t::lib::TestBuilder->new;
29
my $dbh = C4::Context->dbh;
32
my $dbh = C4::Context->dbh;
30
31
# Start transaction
32
$dbh->{AutoCommit} = 0;
33
$dbh->{RaiseError} = 1;
33
$dbh->{RaiseError} = 1;
34
34
35
my $library1 = $builder->build({
36
    source => 'Branch',
37
});
38
my $library2 = $builder->build({
39
    source => 'Branch',
40
});
35
my $CARDNUMBER   = 'TESTCARD01';
41
my $CARDNUMBER   = 'TESTCARD01';
36
my $FIRSTNAME    = 'Marie';
42
my $FIRSTNAME    = 'Marie';
37
my $SURNAME      = 'Mcknight';
43
my $SURNAME      = 'Mcknight';
38
my $CATEGORYCODE = 'S';
44
my $CATEGORYCODE = 'S';
39
my $BRANCHCODE   = 'CPL';
45
my $BRANCHCODE   = $library1->{branchcode};
40
46
41
my $CHANGED_FIRSTNAME = "Marry Ann";
47
my $CHANGED_FIRSTNAME = "Marry Ann";
42
my $EMAIL             = "Marie\@email.com";
48
my $EMAIL             = "Marie\@email.com";
Lines 47-54 my $PHONE = "555-12123"; Link Here
47
# XXX should be randomised and checked against the database
53
# XXX should be randomised and checked against the database
48
my $IMPOSSIBLE_CARDNUMBER = "XYZZZ999";
54
my $IMPOSSIBLE_CARDNUMBER = "XYZZZ999";
49
55
50
# XXX make a non-commit transaction and rollback rather than insert/delete
51
52
#my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, $emailaddress, $branchprinter)= @_;
56
#my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, $emailaddress, $branchprinter)= @_;
53
my @USERENV = (
57
my @USERENV = (
54
    1,
58
    1,
Lines 215-221 is( $borrower, undef, 'DelMember should remove the patron' ); Link Here
215
    firstname    => "Tomasito",
219
    firstname    => "Tomasito",
216
    surname      => "None",
220
    surname      => "None",
217
    categorycode => "S",
221
    categorycode => "S",
218
    branchcode   => "MPL",
222
    branchcode   => $library2->{branchcode},
219
    dateofbirth  => '',
223
    dateofbirth  => '',
220
    debarred     => '',
224
    debarred     => '',
221
    dateexpiry   => '',
225
    dateexpiry   => '',
Lines 272-281 is( $borrower->{userid}, $data{userid}, 'AddMember should insert the given useri Link Here
272
## Remove all entries with userid='' (should be only 1 max)
276
## Remove all entries with userid='' (should be only 1 max)
273
$dbh->do(q|DELETE FROM borrowers WHERE userid = ''|);
277
$dbh->do(q|DELETE FROM borrowers WHERE userid = ''|);
274
## And create a patron with a userid=''
278
## And create a patron with a userid=''
275
$borrowernumber = AddMember( categorycode => 'S', branchcode => 'MPL' );
279
$borrowernumber = AddMember( categorycode => 'S', branchcode => $library2->{branchcode} );
276
$dbh->do(q|UPDATE borrowers SET userid = '' WHERE borrowernumber = ?|, undef, $borrowernumber);
280
$dbh->do(q|UPDATE borrowers SET userid = '' WHERE borrowernumber = ?|, undef, $borrowernumber);
277
# Create another patron and verify the userid has been generated
281
# Create another patron and verify the userid has been generated
278
$borrowernumber = AddMember( categorycode => 'S', branchcode => 'MPL' );
282
$borrowernumber = AddMember( categorycode => 'S', branchcode => $library2->{branchcode} );
279
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' );
280
$borrower = GetMember( borrowernumber => $borrowernumber );
284
$borrower = GetMember( borrowernumber => $borrowernumber );
281
ok( $borrower->{userid},  'A userid should have been generated correctly' );
285
ok( $borrower->{userid},  'A userid should have been generated correctly' );
Lines 332-339 subtest 'GetMemberAccountBalance' => sub { Link Here
332
    is( $total, 15 , "Total calculated correctly");
336
    is( $total, 15 , "Total calculated correctly");
333
    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");
334
    is( $other_charges, 5, "Holds charges are considered if HoldsInNoissuesCharge=1");
338
    is( $other_charges, 5, "Holds charges are considered if HoldsInNoissuesCharge=1");
335
336
    $dbh->rollback();
337
};
339
};
338
340
339
subtest 'purgeSelfRegistration' => sub {
341
subtest 'purgeSelfRegistration' => sub {
Lines 353-361 subtest 'purgeSelfRegistration' => sub { Link Here
353
    C4::Context->set_preference('PatronSelfRegistrationDefaultCategory', $c );
355
    C4::Context->set_preference('PatronSelfRegistrationDefaultCategory', $c );
354
    C4::Context->set_preference('PatronSelfRegistrationExpireTemporaryAccountsDelay', 360);
356
    C4::Context->set_preference('PatronSelfRegistrationExpireTemporaryAccountsDelay', 360);
355
    C4::Members::DeleteExpiredOpacRegistrations();
357
    C4::Members::DeleteExpiredOpacRegistrations();
356
    $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});
357
    is( C4::Members::DeleteExpiredOpacRegistrations(), 1, 'Test for DeleteExpiredOpacRegistrations');
359
    is( C4::Members::DeleteExpiredOpacRegistrations(), 1, 'Test for DeleteExpiredOpacRegistrations');
358
    $dbh->rollback();
359
};
360
};
360
361
361
sub _find_member {
362
sub _find_member {
(-)a/t/db_dependent/Members/AddEnrolmentFeeIfNeeded.t (-4 / +8 lines)
Lines 4-13 use Test::More tests => 4; Link Here
4
use C4::Context;
4
use C4::Context;
5
use C4::Members;
5
use C4::Members;
6
6
7
use t::lib::TestBuilder;
8
9
my $builder = t::lib::TestBuilder->new;
7
my $dbh = C4::Context->dbh;
10
my $dbh = C4::Context->dbh;
8
$dbh->{AutoCommit} = 0;
9
$dbh->{RaiseError} = 1;
11
$dbh->{RaiseError} = 1;
10
12
13
my $library = $builder->build({
14
    source => 'Branch',
15
});
16
11
my $enrolmentfee_K = 5;
17
my $enrolmentfee_K = 5;
12
my $enrolmentfee_J = 10;
18
my $enrolmentfee_J = 10;
13
my $enrolmentfee_YA = 20;
19
my $enrolmentfee_YA = 20;
Lines 34-40 my %borrower_data = ( Link Here
34
    firstname =>  'my firstname',
40
    firstname =>  'my firstname',
35
    surname => 'my surname',
41
    surname => 'my surname',
36
    categorycode => 'K',
42
    categorycode => 'K',
37
    branchcode => 'CPL',
43
    branchcode => $library->{branchcode},
38
);
44
);
39
45
40
my $borrowernumber = C4::Members::AddMember( %borrower_data );
46
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 );
68
C4::Members::AddEnrolmentFeeIfNeeded( 'YA', $borrowernumber );
63
( $total ) = C4::Members::GetMemberAccountRecords( $borrowernumber );
69
( $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 ) );
70
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 / +7 lines)
Lines 25-34 use C4::Members::AttributeTypes; Link Here
25
25
26
use Test::More tests => 60;
26
use Test::More tests => 60;
27
27
28
use t::lib::TestBuilder;
29
28
use_ok('C4::Members::Attributes');
30
use_ok('C4::Members::Attributes');
29
31
32
my $builder = t::lib::TestBuilder->new;
30
my $dbh = C4::Context->dbh;
33
my $dbh = C4::Context->dbh;
31
$dbh->{AutoCommit} = 0;
32
$dbh->{RaiseError} = 1;
34
$dbh->{RaiseError} = 1;
33
35
34
$dbh->do(q|DELETE FROM issues|);
36
$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|);
38
$dbh->do(q|DELETE FROM borrower_attributes|);
37
$dbh->do(q|DELETE FROM borrower_attribute_types|);
39
$dbh->do(q|DELETE FROM borrower_attribute_types|);
38
40
41
my $library = $builder->build({
42
    source => 'Branch',
43
});
39
my $borrowernumber = AddMember(
44
my $borrowernumber = AddMember(
40
    firstname =>  'my firstname',
45
    firstname =>  'my firstname',
41
    surname => 'my surname',
46
    surname => 'my surname',
42
    categorycode => 'S',
47
    categorycode => 'S',
43
    branchcode => 'CPL',
48
    branchcode => $library->{branchcode},
44
);
49
);
45
50
46
51
Lines 196-200 is( $borrower_attributes->[0]->{password}, $attributes->[1]->{password}, 'Delete Link Here
196
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber, $attributes->[1]);
201
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber, $attributes->[1]);
197
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
202
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
198
is( @$borrower_attributes, 0, 'DeleteBorrowerAttribute deletes a borrower attribute' );
203
is( @$borrower_attributes, 0, 'DeleteBorrowerAttribute deletes a borrower attribute' );
199
200
$dbh->rollback;
(-)a/t/db_dependent/Ratings.t (-3 / +9 lines)
Lines 24-40 use C4::Members; Link Here
24
use C4::Context;
24
use C4::Context;
25
use C4::Category;
25
use C4::Category;
26
26
27
use t::lib::TestBuilder;
28
27
use_ok('C4::Ratings');
29
use_ok('C4::Ratings');
28
30
31
my $builder = t::lib::TestBuilder->new;
29
my $dbh = C4::Context->dbh;
32
my $dbh = C4::Context->dbh;
30
$dbh->{RaiseError} = 1;
33
$dbh->{RaiseError} = 1;
31
$dbh->{AutoCommit} = 0;
34
35
my $library = $builder->build({
36
    source => 'Branch',
37
});
32
38
33
my ($biblionumber) = AddBiblio( MARC::Record->new, '' );
39
my ($biblionumber) = AddBiblio( MARC::Record->new, '' );
34
40
35
my @categories   = C4::Category->all;
41
my @categories   = C4::Category->all;
36
my $categorycode = $categories[0]->categorycode;
42
my $categorycode = $categories[0]->categorycode;
37
my $branchcode   = 'CPL';
43
my $branchcode   = $library->{branchcode};
38
44
39
my %john_doe = (
45
my %john_doe = (
40
    cardnumber   => '123456',
46
    cardnumber   => '123456',
Lines 109-112 ok( defined $rating7, 'delete another rating' ); Link Here
109
is( GetRating( $biblionumber, $borrowernumber1 ),
115
is( GetRating( $biblionumber, $borrowernumber1 ),
110
    undef, 'GetRating should return undef if no rating exist' );
116
    undef, 'GetRating should return undef if no rating exist' );
111
117
112
1;
118
1;
(-)a/t/db_dependent/Reserves/GetReserveFee.t (-3 / +6 lines)
Lines 27-38 use C4::Circulation; Link Here
27
use C4::Reserves qw|AddReserve|;
27
use C4::Reserves qw|AddReserve|;
28
use t::lib::TestBuilder;
28
use t::lib::TestBuilder;
29
29
30
my $builder = t::lib::TestBuilder->new();
31
my $library = $builder->build({
32
    source => 'Branch',
33
});
30
my $mContext = new Test::MockModule('C4::Context');
34
my $mContext = new Test::MockModule('C4::Context');
31
$mContext->mock( 'userenv', sub {
35
$mContext->mock( 'userenv', sub {
32
    return { branch => 'CPL' };
36
    return { branch => $library->{branchcode} };
33
});
37
});
34
38
35
my $builder = t::lib::TestBuilder->new();
36
my $dbh = C4::Context->dbh; # after start transaction of testbuilder
39
my $dbh = C4::Context->dbh; # after start transaction of testbuilder
37
40
38
# Category with hold fee, two patrons
41
# Category with hold fee, two patrons
Lines 112-118 sub acctlines { #calculate number of accountlines for a patron Link Here
112
115
113
sub addreserve {
116
sub addreserve {
114
    return AddReserve(
117
    return AddReserve(
115
        'CPL',
118
        $library->{branchcode},
116
        $_[0],
119
        $_[0],
117
        $biblio->{biblionumber},
120
        $biblio->{biblionumber},
118
        undef,
121
        undef,
(-)a/t/db_dependent/Serials_2.t (-4 / +11 lines)
Lines 8-13 use MARC::Record; Link Here
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 t::lib::Mocks;
10
use t::lib::Mocks;
11
use t::lib::TestBuilder;
11
use_ok('C4::Serials');
12
use_ok('C4::Serials');
12
use_ok('C4::Budgets');
13
use_ok('C4::Budgets');
13
14
Lines 16-33 local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /redefined/ }; Link Here
16
my $userenv;
17
my $userenv;
17
*C4::Context::userenv = \&Mock_userenv;
18
*C4::Context::userenv = \&Mock_userenv;
18
19
20
my $builder = t::lib::TestBuilder->new;
21
my $library1 = $builder->build({
22
    source => 'Branch',
23
});
24
my $library2 = $builder->build({
25
    source => 'Branch',
26
});
19
my $dbh = C4::Context->dbh;
27
my $dbh = C4::Context->dbh;
20
$dbh->{AutoCommit} = 0;
21
$dbh->{RaiseError} = 1;
28
$dbh->{RaiseError} = 1;
22
29
23
my $record = MARC::Record->new();
30
my $record = MARC::Record->new();
24
$record->append_fields(
31
$record->append_fields(
25
    MARC::Field->new( '952', '0', '0', a => 'CPL', b => 'CPL' )
32
    MARC::Field->new( '952', '0', '0', a => $library1->{branchcode}, b => $library1->{branchcode} )
26
);
33
);
27
my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio($record, '');
34
my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio($record, '');
28
35
29
my $my_branch = 'CPL';
36
my $my_branch = $library1->{branchcode};
30
my $another_branch = 'MPL';
37
my $another_branch = $library2->{branchcode};
31
my $budgetid;
38
my $budgetid;
32
my $bpid = AddBudgetPeriod({
39
my $bpid = AddBudgetPeriod({
33
    budget_period_startdate   => '2015-01-01',
40
    budget_period_startdate   => '2015-01-01',
(-)a/t/db_dependent/ShelfBrowser.t (-6 / +9 lines)
Lines 10-25 use C4::Biblio; Link Here
10
use C4::Context;
10
use C4::Context;
11
use C4::Items;
11
use C4::Items;
12
12
13
use t::lib::TestBuilder;
14
13
use_ok('C4::ShelfBrowser');
15
use_ok('C4::ShelfBrowser');
14
16
17
my $builder = t::lib::TestBuilder->new;
15
my $dbh = C4::Context->dbh;
18
my $dbh = C4::Context->dbh;
16
$dbh->{AutoCommit} = 0;
17
$dbh->{RaiseError} = 1;
19
$dbh->{RaiseError} = 1;
18
20
19
$dbh->do(q|DELETE FROM reserves|);
21
$dbh->do(q|DELETE FROM reserves|);
20
$dbh->do(q|DELETE FROM issues|);
22
$dbh->do(q|DELETE FROM issues|);
21
$dbh->do(q|DELETE FROM items|);
23
$dbh->do(q|DELETE FROM items|);
22
24
25
my $library = $builder->build({
26
    source => 'Branch',
27
});
28
23
my $cn;
29
my $cn;
24
30
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
31
# 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
60
55
for my $callnumber ( shuffle @callnumbers ) {
61
for my $callnumber ( shuffle @callnumbers ) {
56
    my ( $biblionumber, undef, $itemnumber ) = C4::Items::AddItem({
62
    my ( $biblionumber, undef, $itemnumber ) = C4::Items::AddItem({
57
        homebranch => 'CPL',
63
        homebranch => $library->{branchcode},
58
        holdingbranch => 'CPL',
64
        holdingbranch => $library->{branchcode},
59
        itemcallnumber => $callnumber,
65
        itemcallnumber => $callnumber,
60
    }, $biblionumber);
66
    }, $biblionumber);
61
    $cn->{$callnumber} = {
67
    $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" );
214
is( $nearby->{next_item}, undef, "Test end of the shelf: no next link" );
209
215
210
is( scalar( @{$nearby->{items}} ), 4, "Test last item of the shelf: got 4 items" );
216
is( scalar( @{$nearby->{items}} ), 4, "Test last item of the shelf: got 4 items" );
211
212
$dbh->rollback;
213
- 

Return to bug 14878