From f0084490ed2df0865167ae9af9912381b759cf2e Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 5 Nov 2020 14:40:29 +0100 Subject: [PATCH] Bug 24603: Simplify tests using TestBuilder --- t/db_dependent/Koha/Account/Line.t | 50 +++++++----------------------- 1 file changed, 11 insertions(+), 39 deletions(-) diff --git a/t/db_dependent/Koha/Account/Line.t b/t/db_dependent/Koha/Account/Line.t index c000a7439d..3110933196 100755 --- a/t/db_dependent/Koha/Account/Line.t +++ b/t/db_dependent/Koha/Account/Line.t @@ -1084,45 +1084,17 @@ subtest "cancel() tests" => sub { $schema->storage->txn_begin; - # Create a borrower - my $categorycode = - $builder->build( { source => 'Category' } )->{categorycode}; - my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode}; - - my $borrower = Koha::Patron->new( - { - cardnumber => 'dariahall', - surname => 'Hall', - firstname => 'Daria', - } - ); - $borrower->categorycode($categorycode); - $borrower->branchcode($branchcode); - $borrower->store; - - my $staff = Koha::Patron->new( - { - cardnumber => 'bobby', - surname => 'Bloggs', - firstname => 'Bobby', - } - ); - $staff->categorycode($categorycode); - $staff->branchcode($branchcode); - $staff->store; + my $library = $builder->build_object( { class => 'Koha::Libraries' }); + my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { branchcode => $library->branchcode } }); + my $staff = $builder->build_object({ class => 'Koha::Patrons', value => { branchcode => $library->branchcode } }); - t::lib::Mocks::mock_userenv( - { - branchcode => $branchcode, - borrowernumber => $borrower->borrowernumber - } - ); + t::lib::Mocks::mock_userenv({ patron => $patron }); - my $account = Koha::Account->new( { patron_id => $borrower->id } ); + my $account = Koha::Account->new( { patron_id => $patron->borrowernumber } ); my $debit1 = Koha::Account::Line->new( { - borrowernumber => $borrower->borrowernumber, + borrowernumber => $patron->borrowernumber, amount => 10, amountoutstanding => 10, interface => 'commandline', @@ -1131,7 +1103,7 @@ subtest "cancel() tests" => sub { )->store(); my $debit2 = Koha::Account::Line->new( { - borrowernumber => $borrower->borrowernumber, + borrowernumber => $patron->borrowernumber, amount => 20, amountoutstanding => 20, interface => 'commandline', @@ -1154,7 +1126,7 @@ subtest "cancel() tests" => sub { 15, 'Second fee has amount outstanding of 15' ); throws_ok { $credit->cancel( - { staff_id => $staff->borrowernumber, branch => $branchcode } ); + { staff_id => $staff->borrowernumber, branch => $library->branchcode } ); } 'Koha::Exceptions::Account::IsNotDebit', '->cancel() can only be used with debits'; @@ -1165,20 +1137,20 @@ subtest "cancel() tests" => sub { 'Koha::Exceptions::MissingParameter', "->cancel() requires the `branch` parameter is passed"; throws_ok { - $debit1->reduce( { branch => $branchcode } ); + $debit1->reduce( { branch => $library->branchcode } ); } 'Koha::Exceptions::MissingParameter', "->cancel() requires the `staff_id` parameter is passed"; throws_ok { $debit2->cancel( - { staff_id => $staff->borrowernumber, branch => $branchcode } ); + { staff_id => $staff->borrowernumber, branch => $library->branchcode } ); } 'Koha::Exceptions::Account', '->cancel() can only be used with debits that have not been offset'; my $cancellation = $debit1->cancel( - { staff_id => $staff->borrowernumber, branch => $branchcode } ); + { staff_id => $staff->borrowernumber, branch => $library->branchcode } ); is( ref($cancellation), 'Koha::Account::Line', 'Cancel returns an account line' ); is( -- 2.20.1