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

(-)a/t/db_dependent/Circulation/Chargelostitem.t (-44 / +31 lines)
Lines 2-40 Link Here
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
4
5
use Test::More tests => 4;
5
use Test::MockModule;
6
use Test::MockModule;
7
use t::lib::Mocks;
8
use t::lib::TestBuilder;
9
6
use C4::Biblio;
10
use C4::Biblio;
7
use C4::Items;
11
use C4::Items;
8
use C4::Members;
12
use C4::Members;
9
use C4::Branch;
10
use C4::Category;
11
use C4::Circulation;
13
use C4::Circulation;
12
use MARC::Record;
14
use MARC::Record;
13
use Test::More tests => 7;
14
15
15
BEGIN {
16
BEGIN {
16
    use_ok('C4::Accounts');
17
    use_ok('C4::Accounts');
17
}
18
}
18
19
20
my $schema = Koha::Database->schema;
21
$schema->storage->txn_begin;
22
my $builder = t::lib::TestBuilder->new;
19
my $dbh = C4::Context->dbh;
23
my $dbh = C4::Context->dbh;
20
$dbh->{AutoCommit} = 0;
24
21
$dbh->{RaiseError} = 1;
22
$dbh->do(q|DELETE FROM accountlines|);
25
$dbh->do(q|DELETE FROM accountlines|);
23
26
24
my $branchcode;
27
t::lib::Mocks::mock_preference('ProcessingFeeNote', 'Test Note');
25
my $branch_created;
28
26
my @branches = keys %{ GetBranches() };
29
my $library = $builder->build({
27
if (@branches) {
30
    source => 'Branch',
28
    $branchcode = $branches[0];
31
});
29
} else {
32
my $branchcode = $library->{branchcode};
30
    $branchcode = 'B';
33
31
    ModBranch({ add => 1, branchcode => $branchcode, branchname => 'Branch' });
34
my $itemtype = $builder->build({
32
    $branch_created = 1;
35
    source => 'Itemtype'
33
}
36
});
34
37
35
my %item_branch_infos = (
38
my %item_branch_infos = (
36
    homebranch => $branchcode,
39
    homebranch => $branchcode,
37
    holdingbranch => $branchcode,
40
    holdingbranch => $branchcode,
41
    itype => $itemtype->{itemtype},
38
);
42
);
39
43
40
my ($biblionumber1) = AddBiblio(MARC::Record->new, '');
44
my ($biblionumber1) = AddBiblio(MARC::Record->new, '');
Lines 44-63 my $itemnumber2 = AddItem({ barcode => '0102', %item_branch_infos }, $biblionumb Link Here
44
my ($biblionumber2) = AddBiblio(MARC::Record->new, '');
48
my ($biblionumber2) = AddBiblio(MARC::Record->new, '');
45
my $itemnumber3 = AddItem({ barcode => '0203', %item_branch_infos }, $biblionumber2);
49
my $itemnumber3 = AddItem({ barcode => '0203', %item_branch_infos }, $biblionumber2);
46
50
47
my $categorycode;
51
my $categorycode = $builder->build({
48
my $category_created;
52
    source => 'Category'
49
my @categories = C4::Category->all;
53
})->{categorycode};
50
if (@categories) {
51
    $categorycode = $categories[0]->{categorycode}
52
} else {
53
    $categorycode = 'C';
54
    $dbh->do(
55
        "INSERT INTO categories(categorycode) VALUES(?)", undef, $categorycode);
56
    $category_created = 1;
57
}
58
54
59
my $borrowernumber = AddMember(categorycode => $categorycode, branchcode => $branchcode);
55
my $borrowernumber = AddMember(categorycode => $categorycode, branchcode => $branchcode);
60
my $borrower = GetMember(borrowernumber => $borrowernumber);
56
my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed();
61
57
62
# Need to mock userenv for AddIssue
58
# Need to mock userenv for AddIssue
63
my $module = new Test::MockModule('C4::Context');
59
my $module = new Test::MockModule('C4::Context');
Lines 66-84 AddIssue($borrower, '0101'); Link Here
66
AddIssue($borrower, '0203');
62
AddIssue($borrower, '0203');
67
63
68
# Begin tests...
64
# Begin tests...
69
my $processfee = 10;
65
my $issue = Koha::Checkouts->search( { borrowernumber => $borrowernumber } )->next()->unblessed();
70
my $issues;
66
C4::Accounts::chargelostitem( $borrowernumber, $issue->{itemnumber}, '1.00');
71
$issues = C4::Circulation::GetIssues({biblionumber => $biblionumber1});
67
72
my $issue=$issues->[0];
68
my $accountline = Koha::Account::Lines->search( { borrowernumber => $borrowernumber, accounttype => 'PF' } )->next();
73
$issue->{'processfee'} = $processfee;
69
74
C4::Accounts::chargelostitem($issue, 'test');
70
is( int($accountline->amount), $itemtype->{processfee}, "The accountline amount should be precessfee value " );
75
71
is( $accountline->itemnumber, $itemnumber1, "The accountline itemnumber should the linked with barcode '0101'" );
76
my @accountline = C4::Accounts::getcharges($borrowernumber);
72
is( $accountline->note, C4::Context->preference("ProcessingFeeNote"), "The accountline description should be 'test'" );
77
78
is( scalar(@accountline), 1, 'accountline should have 1 row' );
79
is( int($accountline[0]->{amount}), $processfee, "The accountline amount should be precessfee value " );
80
is( $accountline[0]->{accounttype}, 'PF', "The accountline accounttype should be PF " );
81
is( $accountline[0]->{borrowernumber}, $borrowernumber, "The accountline borrowernumber should be the example borrowernumber" );
82
my $itemnumber = C4::Items::GetItemnumberFromBarcode('0101');
83
is( $accountline[0]->{itemnumber}, $itemnumber, "The accountline itemnumber should the linked with barcode '0101'" );
84
is( $accountline[0]->{description}, 'test ' . $issue->{itemnumber}, "The accountline description should be 'test'" );
85
- 

Return to bug 12768