Bugzilla – Attachment 81376 Details for
Bug 21413
Inventory - Allow skipping items with waiting holds
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 21413: Unit tests
Bug-21413-Unit-tests.patch (text/plain), 5.15 KB, created by
Katrin Fischer
on 2018-10-27 21:42:49 UTC
(
hide
)
Description:
Bug 21413: Unit tests
Filename:
MIME Type:
Creator:
Katrin Fischer
Created:
2018-10-27 21:42:49 UTC
Size:
5.15 KB
patch
obsolete
>From f9549c91d47829d2f9f8156f1ec1275a4760b163 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Wed, 26 Sep 2018 11:08:59 -0300 >Subject: [PATCH] Bug 21413: Unit tests > >To test: >- Apply this patch >- Run: > $ kshell > k$ prove t/db_dependent/Items/GetItemsForInventory.t >=> FAIL: Tests fail! >- Apply the next patches on the bug >- Run: > k$ prove t/db_dependent/Items/GetItemsForInventory.t >=> SUCCESS: Tests pass! > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> > >Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> >--- > t/db_dependent/Items/GetItemsForInventory.t | 113 ++++++++++++++++++-- > 1 file changed, 103 insertions(+), 10 deletions(-) > >diff --git a/t/db_dependent/Items/GetItemsForInventory.t b/t/db_dependent/Items/GetItemsForInventory.t >index 17ab8c1615..d2bd9f7002 100755 >--- a/t/db_dependent/Items/GetItemsForInventory.t >+++ b/t/db_dependent/Items/GetItemsForInventory.t >@@ -18,11 +18,16 @@ > # along with Koha; if not, see <http://www.gnu.org/licenses>. > > use Modern::Perl; >-use Test::More tests => 6; > >-use Koha::AuthorisedValues; >+use Test::More tests => 7; >+use t::lib::TestBuilder; > >-$| = 1; >+use C4::Biblio qw(AddBiblio); >+use C4::Reserves; >+use Koha::AuthorisedValues; >+use Koha::Biblios; >+use Koha::Database; >+use MARC::Record; > > BEGIN { > use_ok('C4::Context'); >@@ -33,16 +38,88 @@ BEGIN { > > can_ok('C4::Items','GetItemsForInventory'); > >-my $dbh = C4::Context->dbh; >-$dbh->{AutoCommit} = 0; >-$dbh->{RaiseError} = 1; >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+ >+subtest 'Old version is unchanged' => sub { >+ >+ plan tests => 1; >+ >+ $schema->storage->txn_begin; >+ >+ my $dbh = $schema->storage->dbh; >+ >+ my ($oldResults, $oldCount) = OldWay($dbh); >+ my ($newResults, $newCount) = GetItemsForInventory; >+ >+ is_deeply($newResults,$oldResults,"Inventory results unchanged."); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'Skip items with waiting holds' => sub { >+ >+ plan tests => 5; >+ >+ $schema->storage->txn_begin; >+ >+ my $library = $builder->build_object( { class => 'Koha::Libraries' } ); >+ my $itemtype >+ = $builder->build_object( { class => 'Koha::ItemTypes', value => { rentalcharge => 0 } } ); >+ my $patron = $builder->build_object( >+ { class => 'Koha::Patrons', value => { branchcode => $library->id } } ); >+ >+ my $title_1 = 'Title 1'; >+ my $title_2 = 'Title 2'; > >-my ($oldResults, $oldCount) = OldWay($dbh); >-my ($newResults, $newCount) = GetItemsForInventory; >+ my $biblio_1 = create_helper_biblio( $itemtype->itemtype, $title_1 ); >+ my $biblio_2 = create_helper_biblio( $itemtype->itemtype, $title_2 ); > >-is_deeply($newResults,$oldResults,"Inventory results unchanged."); >+ my ( $items_1, $first_items_count ) = GetItemsForInventory(); >+ is( scalar @{$items_1}, $first_items_count, 'Results and count match' ); > >-$dbh->rollback; >+ # Add two items, so we don't depend on existing data >+ my $item_1 = $builder->build_object( >+ { class => 'Koha::Items', >+ value => { >+ biblionumber => $biblio_1->biblionumber, >+ biblioitemnumber => $biblio_1->biblioitem->biblioitemnumber, >+ homebranch => $library->id, >+ holdingbranch => $library->id, >+ itype => $itemtype->itemtype, >+ } >+ } >+ ); >+ >+ my $item_2 = $builder->build_object( >+ { class => 'Koha::Items', >+ value => { >+ biblionumber => $biblio_2->biblionumber, >+ biblioitemnumber => $biblio_2->biblioitem->biblioitemnumber, >+ homebranch => $library->id, >+ holdingbranch => $library->id, >+ itype => $itemtype->itemtype, >+ } >+ } >+ ); >+ >+ my ( $items_2, $second_items_count ) = GetItemsForInventory(); >+ is( scalar @{$items_2}, $second_items_count, 'Results and count match' ); >+ is( $first_items_count + 2, $second_items_count, 'Two items added, count makes sense' ); >+ >+ # Add a waiting hold >+ my $reserve_id >+ = C4::Reserves::AddReserve( $library->branchcode, $patron->borrowernumber, >+ $item_1->biblionumber, '', 1, undef, undef, '', "title for fee", >+ $item_1->itemnumber, 'W' ); >+ >+ my ( $new_items, $new_items_count ) = GetItemsForInventory( { ignore_waiting_holds => 1 } ); >+ is( $new_items_count, $first_items_count + 1, 'Item on hold skipped, count makes sense' ); >+ is( $new_items->[ scalar @{$new_items} - 1 ]->{title}, >+ $title_2, 'Item on hold skipped, last item is the correct one' ); >+ >+ $schema->storage->txn_rollback; >+}; > > sub OldWay { > my ($tdbh) = @_; >@@ -161,3 +238,19 @@ sub OldWay { > > return (\@results, $iTotalRecords); > } >+ >+# Helper method to set up a Biblio. >+sub create_helper_biblio { >+ my $itemtype = shift; >+ my $title = shift; >+ my $record = MARC::Record->new(); >+ >+ $record->append_fields( >+ MARC::Field->new( '245', ' ', ' ', a => $title ), >+ MARC::Field->new( '942', ' ', ' ', c => $itemtype ), >+ ); >+ >+ my $biblio_id = AddBiblio( $record, '' ); >+ >+ return Koha::Biblios->find($biblio_id); >+} >-- >2.17.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 21413
:
79432
|
79433
|
81376
|
81377
|
81378
|
81379
|
82040
|
82111
|
82168