Koha/t/db_dependent/Acquisition/OrderUsers.t
Emmi Takkinen 96c8a0dbf6
Bug 32132: Fix failing tests
Some tests failed due changes made to aqbudgets.budget_period_id.
Tests failed with error:

DBIx::Class::Storage::DBI::_dbh_execute(): DBI Exception:
DBD::mysql::st execute failed: Field 'budget_period_id' doesn't
have a default value at...

This patch fixes those tests.

To test run following lines:
prove t/db_dependent/Acquisition/CancelReceipt.t
prove t/db_dependent/Acquisition/GetBasketAsCSV.t
prove t/db_dependent/Acquisition/GetBasketGroupAsCSV.t
prove t/db_dependent/Acquisition/GetBasketsInfosByBookseller.t
prove t/db_dependent/Acquisition/GetOrdersByBiblionumber.t
prove t/db_dependent/Acquisition/Invoices.t
prove t/db_dependent/Acquisition/NewOrder.t
prove t/db_dependent/Acquisition/OrderUsers.t
prove t/db_dependent/Acquisition/TransferOrder.t
prove t/db_dependent/Acquisition/close_reopen_basket.t
prove t/db_dependent/Koha/Acquisition/Funds.t
prove t/db_dependent/Letters.t

Sponsored-by: Koha-Suomi Oy
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
2024-04-23 16:47:05 +01:00

126 lines
3.8 KiB
Perl
Executable file

use Modern::Perl;
use Test::More tests => 3;
use C4::Acquisition qw( NewBasket AddInvoice ModOrder ModOrderUsers GetOrder GetOrderUsers ModReceiveOrder );
use C4::Biblio qw( AddBiblio );
use C4::Letters qw( GetQueuedMessages );
use Koha::Database;
use Koha::Acquisition::Booksellers;
use Koha::Acquisition::Orders;
use Koha::Patrons;
use t::lib::TestBuilder;
my $schema = Koha::Database->schema;
$schema->storage->txn_begin;
my $builder = t::lib::TestBuilder->new;
my $library = $builder->build({
source => "Branch",
});
my $patron_category = $builder->build({ source => 'Category' });
my $currency = $builder->build({ source => 'Currency' });
# Creating some orders
my $bookseller = Koha::Acquisition::Bookseller->new(
{
name => "my vendor",
address1 => "bookseller's address",
phone => "0123456",
active => 1,
}
)->store;
my $basketno = NewBasket( $bookseller->id, 1 );
my $budget_period_id = C4::Budgets::AddBudgetPeriod(
{
budget_period_startdate => '2024-01-01',
budget_period_enddate => '2049-01-01',
budget_period_active => 1,
budget_period_description => "TEST PERIOD"
}
);
my $budgetid = C4::Budgets::AddBudget(
{
budget_code => "budget_code_test",
budget_name => "budget_name_test",
budget_period_id => $budget_period_id,
}
);
my $budget = C4::Budgets::GetBudget($budgetid);
my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( MARC::Record->new, '' );
my $order = Koha::Acquisition::Order->new(
{
basketno => $basketno,
quantity => 2,
biblionumber => $biblionumber,
budget_id => $budgetid,
entrydate => '2014-01-01',
currency => $currency->{currency},
orderstatus => 1,
quantityreceived => 0,
rrp => 10,
ecost => 10,
}
)->store;
my $ordernumber = $order->ordernumber;
my $invoiceid = AddInvoice(
invoicenumber => 'invoice',
booksellerid => $bookseller->id,
unknown => "unknown"
);
my $borrowernumber = Koha::Patron->new({
cardnumber => 'TESTCARD',
firstname => 'TESTFN',
surname => 'TESTSN',
categorycode => $patron_category->{categorycode},
branchcode => $library->{branchcode},
dateofbirth => '',
dateexpiry => '9999-12-31',
userid => 'TESTUSERID'
})->store->borrowernumber;
C4::Acquisition::ModOrderUsers( $ordernumber, $borrowernumber );
my $is_added = grep { /^$borrowernumber$/ } C4::Acquisition::GetOrderUsers( $ordernumber );
is( $is_added, 1, 'ModOrderUsers should link patrons to an order' );
$order = Koha::Acquisition::Orders->find( $ordernumber );
ModReceiveOrder(
{
biblionumber => $biblionumber,
order => $order->unblessed,
quantityreceived => 1,
cost => 10,
ecost => 10,
invoiceid => $invoiceid,
rrp => 10,
budget_id => $budgetid,
}
);
my $messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber });
is( scalar( @$messages ), 0, 'The letter has not been sent to message queue on receiving the order, the order is not entire received');
$order = Koha::Acquisition::Orders->find( $ordernumber );
ModReceiveOrder(
{
biblionumber => $biblionumber,
order => $order->unblessed,
quantityreceived => 1,
cost => 10,
ecost => 10,
invoiceid => $invoiceid,
rrp => 10,
budget_id => $budgetid,
}
);
$messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber });
is( scalar( @$messages ), 1, 'The letter has been sent to message queue on receiving the order');