Koha/t/db_dependent/Acquisition/StandingOrders.t
Marcel de Rooy 2ba4a661d3 Bug 18448: Fix a few db_dependent tests
Tests in db_dependent may expect a Koha database, but should not rely on
hardcoded categories, currencies, branch codes, etc.

This patch fixes a bunch of those. But this is a continuous project. We also
need QA to closely watch new edits.

Accounts.t: hardcoded category PT replaced
Acquisition/OrderFromSubscription.t: hardcoded USD
Acquisition/StandingOrders.t: same
ArticleRequests.t: create itemtype, branch and category for testing
AuthorisedValues.t: remove $dbh, add two test branches
AuthoritiesMarc.t: add hardcoded GEOGR_NAME authtype
Bookseller.t: add test currency
Koha.t: add test itemtype instead of hardcoded BK
UsageStats.t: add test branch and category

Test plan:
Run the adjusted tests.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

All tests successful (see comment #9)
Signed-off-by: Marc Véron <veron@veron.ch>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
2017-04-21 00:09:43 +00:00

135 lines
4.1 KiB
Perl

#!/usr/bin/perl
use Modern::Perl;
use Test::More tests => 13;
use C4::Context;
use C4::Acquisition;
use C4::Biblio;
use C4::Items;
use C4::Budgets;
use Koha::Acquisition::Order;
use t::lib::Mocks;
use t::lib::TestBuilder;
my $schema = Koha::Database->schema;
$schema->storage->txn_begin;
my $builder = t::lib::TestBuilder->new;
# Set up configuration data
my $branch = $builder->build( { source => 'Branch' } );
my $bookseller = $builder->build( { source => 'Aqbookseller' } );
my $budget = $builder->build( { source => 'Aqbudget' } );
my $staffmember = $builder->build( { source => 'Borrower' } );
my $curcode = $builder->build( { source => 'Currency' })->{currencycode};
# Create baskets and orders
my $basketno = NewBasket(
$bookseller->{id},
$staffmember->{borrowernumber},
'Standing order basket', # basketname
'', # basketnote
'', # basketbooksellernote
undef, # basketcontractnumber
$branch->{branchcode}, # deliveryplace
$branch->{branchcode}, # billingplace
1 # is_standing
);
my $nonstandingbasketno = NewBasket(
$bookseller->{id},
$staffmember->{borrowernumber},
'Non-standing order basket', # basketname
'', # basketnote
'', # basketbooksellernote
undef, # basketcontractnumber
$branch->{branchcode}, # deliveryplace
$branch->{branchcode}, # billingplace
0 # is_standing
);
my $basket = GetBasket($basketno);
is( $basket->{is_standing}, 1, 'basket correctly created as standing order basket' );
my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( MARC::Record->new, '' );
my $ordernumber = Koha::Acquisition::Order->new(
{
basketno => $basketno,
biblionumber => $biblionumber,
budget_id => $budget->{budget_id},
currency => $curcode,
quantity => 0,
rrp => 42,
rrp_tax_included => 42,
rrp_tax_excluded => 42,
ecost => 22,
ecost_tax_included => 22,
ecost_tax_excluded => 22,
unitprice => 12,
unitprice_tax_included => 12,
unitprice_tax_excluded => 12,
tax_rate => 0,
tax_rate_on_ordering => 0,
tax_rate_on_receiving => 0,
}
)->insert->{ordernumber};
isnt( $ordernumber, undef, 'standing order successfully created' );
my $search_orders = SearchOrders( {
basketno => $basketno,
pending => 1,
ordered => 1,
} );
ok(
scalar @$search_orders == 1 && $search_orders->[0]->{ordernumber} == $ordernumber,
'standing order counts as a pending/ordered order'
);
my $invoiceid = AddInvoice(
invoicenumber => 'invoice',
booksellerid => $bookseller->{id},
unknown => "unknown"
);
my $order = Koha::Acquisition::Order->fetch( { ordernumber => $ordernumber } );
my ( $datereceived, $new_ordernumber ) = ModReceiveOrder(
{
biblionumber => $biblionumber,
order => $order,
quantityreceived => 2,
invoiceid => $invoiceid,
}
);
isnt( $ordernumber, $new_ordernumber, "standing order split on receive" );
#order has been updated, refetch
$order = Koha::Acquisition::Order->fetch( { ordernumber => $ordernumber } );
my $neworder = Koha::Acquisition::Order->fetch( { ordernumber => $new_ordernumber } );
is( $order->{orderstatus}, 'partial', 'original order set to partially received' );
is( $order->{quantity}, 1, 'original order quantity unchanged' );
is( $order->{quantityreceived}, 0, 'original order has no received items' );
isnt( $order->{unitprice}, 12, 'original order does not get cost' );
is( $neworder->{orderstatus}, 'complete', 'new order set to complete' );
is( $neworder->{quantityreceived}, 2, 'new order has received items' );
cmp_ok( $neworder->{unitprice}, '==', 12, 'new order does get cost' );
$search_orders = SearchOrders( {
basketno => $basketno,
pending => 1,
ordered => 1,
} );
is( scalar @$search_orders, 1, 'only one pending order after receive' );
is( $search_orders->[0]->{ordernumber}, $ordernumber, 'original order is only pending order' );
$schema->storage->txn_rollback();