Bugzilla – Attachment 94659 Details for
Bug 22569
Add a 'Transfers to send' report
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 22569: Add Unit Tests
Bug-22569-Add-Unit-Tests.patch (text/plain), 6.75 KB, created by
Martin Renvoize (ashimema)
on 2019-10-24 12:18:26 UTC
(
hide
)
Description:
Bug 22569: Add Unit Tests
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2019-10-24 12:18:26 UTC
Size:
6.75 KB
patch
obsolete
>From d2d944a2d93fa7a8b6b55fed697ec4d99e6825df Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Thu, 24 Oct 2019 13:17:07 +0100 >Subject: [PATCH] Bug 22569: Add Unit Tests > >--- > t/db_dependent/Koha/Item/Transfers.t | 42 +++++++++++++++++++- > t/db_dependent/Koha/Libraries.t | 37 +++++++++++++++++- > t/db_dependent/StockRotationItems.t | 58 +++++++++++++++++++++++++++- > 3 files changed, 134 insertions(+), 3 deletions(-) > >diff --git a/t/db_dependent/Koha/Item/Transfers.t b/t/db_dependent/Koha/Item/Transfers.t >index b49f78091a..6e501ab84c 100644 >--- a/t/db_dependent/Koha/Item/Transfers.t >+++ b/t/db_dependent/Koha/Item/Transfers.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 2; >+use Test::More tests => 3; > > use Koha::Item::Transfer; > use Koha::Item::Transfers; >@@ -66,3 +66,43 @@ is( $retrieved_transfer_1->itemnumber, $new_transfer_1->itemnumber, 'Find a tran > > $schema->storage->txn_rollback; > >+subtest 'item() tests' => sub { >+ >+ plan tests => 2; >+ >+ $schema->storage->txn_begin; >+ >+ my $library_from = $builder->build( { source => 'Branch' } ); >+ my $library_to = $builder->build( { source => 'Branch' } ); >+ my $item = $builder->build( >+ { >+ source => 'Item', >+ value => { >+ holding_branch => $library_from->{branchcode}, >+ homebranch => $library_to->{branchcode} >+ } >+ } >+ ); >+ >+ my $transfer = Koha::Item::Transfer->new( >+ { >+ itemnumber => $item->{itemnumber}, >+ frombranch => $library_from->{branchcode}, >+ tobranch => $library_to->{branchcode}, >+ datearrived => dt_from_string, >+ datesent => dt_from_string, >+ } >+ )->store; >+ >+ my $transfer_item = $transfer->item; >+ is( ref($transfer_item), 'Koha::Item', >+ 'Koha::Item::Transfer->item should return a Koha::Item' ); >+ is( >+ $transfer->itemnumber, >+ $transfer_item->itemnumber, >+ 'Koha::Item::Transfer->item should return the correct item' >+ ); >+ >+ $schema->storage->txn_rollback; >+}; >+ >diff --git a/t/db_dependent/Koha/Libraries.t b/t/db_dependent/Koha/Libraries.t >index 987d6bc710..f3112e004a 100644 >--- a/t/db_dependent/Koha/Libraries.t >+++ b/t/db_dependent/Koha/Libraries.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 8; >+use Test::More tests => 9; > > use C4::Biblio; > use C4::Context; >@@ -468,3 +468,38 @@ subtest 'cash_registers' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'outgoing_transfers' => sub { >+ plan tests => 3; >+ >+ $schema->storage->txn_begin; >+ >+ my $library = $builder->build_object( { class => 'Koha::Libraries' } ); >+ my $transfer1 = $builder->build_object( >+ { >+ class => 'Koha::Item::Transfers', >+ value => { frombranch => $library->branchcode }, >+ } >+ ); >+ my $transfer2 = $builder->build_object( >+ { >+ class => 'Koha::Item::Transfers', >+ value => { frombranch => $library->branchcode }, >+ } >+ ); >+ >+ my $outgoing_transfers = $library->outgoing_transfers; >+ is( ref($outgoing_transfers), 'Koha::Item::Transfers', >+'Koha::Library->outgoing_transfers should return a set of Koha::Item::Transfers' >+ ); >+ is( $outgoing_transfers->count, 2, >+ 'Koha::Library->outgoing_transfers should return the correct transfers' >+ ); >+ >+ $transfer1->delete; >+ is( $library->outgoing_transfers->next->id, $transfer2->id, >+ 'Koha::Library->outgoing_transfers should return the correct cash registers' >+ ); >+ >+ $schema->storage->txn_rollback; >+}; >diff --git a/t/db_dependent/StockRotationItems.t b/t/db_dependent/StockRotationItems.t >index 2d9bf89a39..64697dbfaa 100644 >--- a/t/db_dependent/StockRotationItems.t >+++ b/t/db_dependent/StockRotationItems.t >@@ -25,7 +25,7 @@ use Koha::Database; > use Koha::Item::Transfer; > use t::lib::TestBuilder; > >-use Test::More tests => 8; >+use Test::More tests => 9; > > my $schema = Koha::Database->new->schema; > >@@ -390,4 +390,60 @@ subtest "Tests for investigate (singular)." => sub { > $schema->storage->txn_rollback; > }; > >+subtest "Tests for toggle_indemand" => sub { >+ plan tests => 15; >+ $schema->storage->txn_begin; >+ >+ my $sritem = $builder->build({ >+ source => 'Stockrotationitem', >+ value => { 'fresh' => 0, 'indemand' => 0 } >+ }); >+ my $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); >+ my $firstbranch = $dbitem->stage->branchcode_id; >+ $dbitem->itemnumber->holdingbranch($firstbranch)->store; >+ my $dbstage = $dbitem->stage; >+ $dbstage->position(1)->duration(50)->store; # Configure stage. >+ # Configure item >+ $dbitem->itemnumber->holdingbranch($firstbranch)->store; >+ $dbitem->itemnumber->homebranch($firstbranch)->store; >+ # Sanity check >+ is($dbitem->stage->stage_id, $dbstage->stage_id, "Stage sanity check."); >+ >+ # Test if an item is not in transfer, toggle always acts. >+ is($dbitem->indemand, 0, "Item not in transfer starts with indemand disabled."); >+ $dbitem->toggle_indemand; >+ is($dbitem->indemand, 1, "Item not in transfer toggled correctly first time."); >+ $dbitem->toggle_indemand; >+ is($dbitem->indemand, 0, "Item not in transfer toggled correctly second time."); >+ >+ # Add stages >+ my $srstage = $builder->build({ >+ source => 'Stockrotationstage', >+ value => { duration => 50 } >+ }); >+ my $dbstage2 = Koha::StockRotationStages->find($srstage->{stage_id}); >+ $dbstage2->move_to_group($dbitem->stage->rota_id); >+ $dbstage2->position(2)->store; >+ my $secondbranch = $dbstage2->branchcode_id; >+ >+ # Test an item in transfer, toggle cancels transfer and resets indemand. >+ ok($dbitem->advance, "Advancement done."); >+ $dbitem->get_from_storage; >+ my $transfer = $dbitem->itemnumber->get_transfer; >+ is(ref($transfer), 'Koha::Item::Transfer', 'Item set to in transfer as expected'); >+ is($transfer->frombranch, $firstbranch, 'Transfer from set correctly'); >+ is($transfer->tobranch, $secondbranch, 'Transfer to set correctly'); >+ is($transfer->datearrived, undef, 'Transfer datearrived not set'); >+ $dbitem->toggle_indemand; >+ my $updated_transfer = $transfer->get_from_storage; >+ is($updated_transfer->frombranch, $firstbranch, 'Transfer from retained correctly'); >+ is($updated_transfer->tobranch, $firstbranch, 'Transfer to updated correctly'); >+ isnt($updated_transfer->datearrived, undef, 'Transfer datearrived set as expected'); >+ is($dbitem->indemand, 0, "Item retains indemand as expected."); >+ is($dbitem->stage_id, $dbstage->id, 'Item stage reset as expected.'); >+ is($dbitem->itemnumber->homebranch, $firstbranch, 'Item homebranch reset as expected.'); >+ >+ $schema->storage->txn_rollback; >+}; >+ > 1; >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 22569
:
90458
|
90477
|
90486
|
90487
|
94650
|
94651
|
94658
|
94659
|
96471
|
96472
|
96473
|
96474
|
96475
|
96478
|
96479
|
96516
|
96517
|
97392
|
97393
|
107258
|
107259
|
107260
|
107306
|
107307
|
107308
|
110284
|
110285
|
110286
|
110543
|
110544
|
110545
|
116572
|
116573
|
117612
|
117613
|
117840
|
117841
|
117842
|
117843
|
117847
|
117848
|
117878
|
117879
|
117880
|
117881