Bugzilla – Attachment 79153 Details for
Bug 18606
Move rotating collections code to Koha::Object
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18606: Rework tests for rotating collections
Bug-18606-Rework-tests-for-rotating-collections.patch (text/plain), 16.84 KB, created by
Josef Moravec
on 2018-09-20 11:18:51 UTC
(
hide
)
Description:
Bug 18606: Rework tests for rotating collections
Filename:
MIME Type:
Creator:
Josef Moravec
Created:
2018-09-20 11:18:51 UTC
Size:
16.84 KB
patch
obsolete
>From f965fa62f1b962941e4f027b57a3014ead077297 Mon Sep 17 00:00:00 2001 >From: Josef Moravec <josef.moravec@gmail.com> >Date: Mon, 15 May 2017 10:39:39 +0000 >Subject: [PATCH] Bug 18606: Rework tests for rotating collections > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > t/db_dependent/Koha/RotatingCollections.t | 142 +++++++++++++ > t/db_dependent/RotatingCollections.t | 336 ------------------------------ > 2 files changed, 142 insertions(+), 336 deletions(-) > create mode 100644 t/db_dependent/Koha/RotatingCollections.t > delete mode 100644 t/db_dependent/RotatingCollections.t > >diff --git a/t/db_dependent/Koha/RotatingCollections.t b/t/db_dependent/Koha/RotatingCollections.t >new file mode 100644 >index 0000000..57f16ff >--- /dev/null >+++ b/t/db_dependent/Koha/RotatingCollections.t >@@ -0,0 +1,142 @@ >+#!/usr/bin/perl >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::More tests => 2; >+use C4::Context; >+use Koha::Biblios; >+use Koha::Database; >+use Koha::Library; >+use Koha::RotatingCollections; >+use Koha::Items; >+use Koha::Item::Transfers; >+use Koha::Libraries; >+ >+use t::lib::TestBuilder; >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+ >+subtest 'remove_and_add_items' => sub { >+ plan tests => 8; >+ >+ $schema->storage->txn_begin; >+ >+ my $collection = Koha::RotatingCollection->new( { >+ colTitle => 'Test title 1', >+ colDesc => 'Test description 1', >+ } )->store; >+ >+ my $biblioitem = $builder->build( { source => 'Biblioitem' } ); >+ >+ my $library = $builder->build( { source => 'Branch' } ); >+ >+ my $item1 = Koha::Item->new( { >+ biblionumber => $biblioitem->{biblionumber}, >+ biblioitemnumber => $biblioitem->{biblioitemnumber}, >+ homebranch => $library->{branchcode}, >+ holdingbranch => $library->{branchcode}, >+ barcode => 'barcode1', >+ } )->store; >+ >+ my $item2 = Koha::Item->new( { >+ biblionumber => $biblioitem->{biblionumber}, >+ biblioitemnumber => $biblioitem->{biblioitemnumber}, >+ homebranch => $library->{branchcode}, >+ holdingbranch => $library->{branchcode}, >+ barcode => 'barode2', >+ } )->store; >+ >+ is( $collection->items->count, 0, 'In newly created collection there should not be any item'); >+ >+ $collection->add_item( $item1 ); >+ $collection->add_item( $item2 ); >+ >+ is( $collection->items->count, 2, 'Added two items, there should be two'); >+ >+ eval { $collection->add_item }; >+ is( ref($@), 'Koha::Exceptions::MissingParameter', 'Missing paramater exception'); >+ >+ eval { $collection->add_item( $item1 ) }; >+ is( ref($@), 'Koha::Exceptions::DuplicateObject', 'Duplicate Object Exception - you should not add the same item twice'); >+ >+ eval { $collection->add_item('bad_itemnumber') }; >+ is( ref($@), 'Koha::Exceptions::ObjectNotFound', 'Object Not Found Exception - you cannot add non existent item'); >+ >+ $collection->remove_item( $item1 ); >+ >+ is( $collection->items->count, 1, 'We removed first item, there should be one remaining'); >+ >+ eval { $collection->remove_item }; >+ is( ref($@), 'Koha::Exceptions::MissingParameter', 'Missing paramater exception'); >+ >+ eval { $collection->remove_item( $item1 ) }; >+ is( ref($@), 'Koha::Exceptions::ObjectNotFound', 'Object Not Found Exception - cannot remove the same item twice'); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'transfer' => sub { >+ plan tests => 4; >+ >+ $schema->storage->txn_begin; >+ >+ my $collection = Koha::RotatingCollection->new( { >+ colTitle => 'Test title 1', >+ colDesc => 'Test description 1', >+ } )->store; >+ my $biblioitem = $builder->build( { source => 'Biblioitem' } ); >+ >+ my $library1 = Koha::Library->new( { >+ branchcode => 'CODE1', >+ } )->store; >+ >+ my $library2 = Koha::Library->new( { >+ branchcode => 'CODE2', >+ } )->store; >+ >+ my $item = Koha::Item->new( { >+ biblionumber => $biblioitem->{biblionumber}, >+ biblioitemnumber => $biblioitem->{biblioitemnumber}, >+ homebranch => $library1->branchcode, >+ holdingbranch => $library1->branchcode, >+ itype => 'BK', >+ barcode => 'some_barcode', >+ } )->store; >+ >+ $collection->add_item( $item ); >+ >+ eval { $collection->transfer }; >+ is( ref($@), 'Koha::Exceptions::MissingParameter', 'Missing paramater exception'); >+ >+ $collection->transfer( $library2 ); >+ my $retrieved_item = Koha::Items->find( $item->itemnumber ); >+ >+ is( $collection->colBranchcode, $library2->branchcode, 'Collection should be transferred' ); >+ is( $retrieved_item->holdingbranch, $library2->branchcode, 'Items in collection should be transferred too' ); >+ >+ my $transfer = Koha::Item::Transfers->search( { >+ itemnumber => $item->itemnumber, >+ frombranch => $library1->branchcode, >+ tobranch => $library2->branchcode, >+ datearrived => undef, >+ } ); >+ is( $transfer->count, 1, 'There should be transfer started for item in collection'); >+ >+ $schema->storage->txn_rollback; >+}; >diff --git a/t/db_dependent/RotatingCollections.t b/t/db_dependent/RotatingCollections.t >deleted file mode 100644 >index e00410c..0000000 >--- a/t/db_dependent/RotatingCollections.t >+++ /dev/null >@@ -1,336 +0,0 @@ >-#!/usr/bin/perl >- >-# This file is part of Koha. >-# >-# Koha is free software; you can redistribute it and/or modify it >-# under the terms of the GNU General Public License as published by >-# the Free Software Foundation; either version 3 of the License, or >-# (at your option) any later version. >-# >-# Koha is distributed in the hope that it will be useful, but >-# WITHOUT ANY WARRANTY; without even the implied warranty of >-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >-# GNU General Public License for more details. >-# >-# You should have received a copy of the GNU General Public License >-# along with Koha; if not, see <http://www.gnu.org/licenses>. >- >-use Modern::Perl; >- >-use Test::More tests => 51; >-use C4::Context; >-use C4::RotatingCollections; >-use C4::Biblio; >-use Koha::Library; >- >-BEGIN { >-} >- >-can_ok( >- 'C4::RotatingCollections', >- qw( >- AddItemToCollection >- CreateCollection >- DeleteCollection >- GetCollection >- GetCollectionItemBranches >- GetCollections >- GetItemsInCollection >- RemoveItemFromCollection >- TransferCollection >- UpdateCollection >- isItemInAnyCollection >- isItemInThisCollection >- ) >-); >- >-#Start transaction >-my $dbh = C4::Context->dbh; >-$dbh->{RaiseError} = 1; >-$dbh->{AutoCommit} = 0; >- >-#Start Tests >-$dbh->do(q|DELETE FROM issues |); >-$dbh->do(q|DELETE FROM borrowers |); >-$dbh->do(q|DELETE FROM items |); >-$dbh->do(q|DELETE FROM collections_tracking |); >-$dbh->do(q|DELETE FROM collections |); >-$dbh->do(q|DELETE FROM branches |); >-$dbh->do(q|DELETE FROM categories|); >- >-#Test CreateCollection >-my $collections = GetCollections(); >-my $countcollection = scalar(@$collections); >- >-my ($success,$errorCode,$errorMessage); >- >-($success,$errorCode,$errorMessage) = CreateCollection( 'Collection1', 'Description1' ); >-is( $success, 1, "All parameters have been given - Collection 1 added" ); >-ok( !defined $errorCode && !defined $errorMessage, >- "Collection added, no error code or message"); >-my $collection_id1 = $dbh->last_insert_id( undef, undef, 'collections', undef ); >- >-($success,$errorCode,$errorMessage) = CreateCollection( 'Collection2', 'Description2' ); >-is( $success, 1, "All parameters have been given - Collection 2 added" ); >-ok( !defined $errorCode && !defined $errorMessage, >- "Collection added, no error code or message"); >-my $collection_id2 = $dbh->last_insert_id( undef, undef, 'collections', undef ); >- >-$collections = GetCollections(); >-is( scalar(@$collections), $countcollection + 2, >- "Collection1 and Collection2 have been added" ); >- >-($success,$errorCode,$errorMessage) = CreateCollection('Collection3'); >-is( $success, 1, "Collections can be created without description" ); >-ok( !defined $errorCode && !defined $errorMessage, >- "Collection added, no error code or message"); >-my $collection_id3 = $dbh->last_insert_id( undef, undef, 'collections', undef ); >- >-($success,$errorCode,$errorMessage) = CreateCollection(); >-is( $success, 0, "Title missing, fails to create collection" ); >-is( $errorCode, 1, "Title missing, error code is 1" ); >-is( $errorMessage, 'NO_TITLE', "Title missing, error message is NO_TITLE" ); >- >-$collections = GetCollections(); >-is( scalar(@$collections), $countcollection + 3, "Only one collection added" ); >- >-#FIXME, as the id is auto incremented, two similar Collections (same title /same description) can be created >-#$collection1 = CreateCollection('Collection1','Description1'); >- >-#Test GetCollections >-my $collection = GetCollections(); >-is_deeply( >- $collections, >- [ >- { >- colId => $collection_id1, >- colTitle => 'Collection1', >- colDesc => 'Description1', >- colBranchcode => undef >- }, >- { >- colId => $collection_id2, >- colTitle => 'Collection2', >- colDesc => 'Description2', >- colBranchcode => undef >- }, >- { >- colId => $collection_id3, >- colTitle => 'Collection3', >- colDesc => '', >- colBranchcode => undef >- } >- >- ], >- 'All Collections' >-); >- >-#Test UpdateCollection >-($success,$errorCode,$errorMessage) = >- UpdateCollection( $collection_id2, 'Collection2bis', undef ); >-is( $success, 1, "UpdateCollection succeeds without description"); >- >-($success,$errorCode,$errorMessage) = >- UpdateCollection( $collection_id2, 'Collection2 modified', 'Description2 modified' ); >-is( $success, 1, "Collection2 has been modified" ); >-ok( !defined $errorCode && !defined $errorMessage, >- "Collection2 modified, no error code or message"); >- >-($success,$errorCode,$errorMessage) = >- UpdateCollection( $collection_id2, undef, 'Description' ), >-ok( !$success, "UpdateCollection fails without title" ); >-is( $errorCode, 2, "Title missing, error code is 2"); >-is( $errorMessage, 'NO_TITLE', "Title missing, error message is NO_TITLE"); >- >-is( UpdateCollection(), 'NO_ID', "UpdateCollection without params" ); >- >-#Test GetCollection >-my @collection1 = GetCollection($collection_id1); >-is_deeply( >- \@collection1, >- [ $collection_id1, 'Collection1', 'Description1', undef ], >- "Collection1's informations" >-); >-my @collection2 = GetCollection($collection_id2); >-is_deeply( >- \@collection2, >- [ $collection_id2, 'Collection2 modified', 'Description2 modified', undef ], >- "Collection2's informations" >-); >-my @undef_collection = GetCollection(); >-is_deeply( >- \@undef_collection, >- [ undef, undef, undef, undef ], >- "GetCollection without id given" >-); >-@undef_collection = GetCollection(-1); >-is_deeply( >- \@undef_collection, >- [ undef, undef, undef, undef ], >- "GetCollection with a wrong id" >-); >- >-#Test TransferCollection >-my $samplebranch = { >- branchcode => 'SAB', >- branchname => 'Sample Branch', >- branchaddress1 => 'sample adr1', >- branchaddress2 => 'sample adr2', >- branchaddress3 => 'sample adr3', >- branchzip => 'sample zip', >- branchcity => 'sample city', >- branchstate => 'sample state', >- branchcountry => 'sample country', >- branchphone => 'sample phone', >- branchfax => 'sample fax', >- branchemail => 'sample email', >- branchurl => 'sample url', >- branchip => 'sample ip', >- branchprinter => undef, >- branchnotes => 'sample note', >- opac_info => 'sample opac', >-}; >-Koha::Library->new($samplebranch)->store; >-is( TransferCollection( $collection_id1, $samplebranch->{branchcode} ), >- 1, "Collection1 has been transfered in the branch SAB" ); >-@collection1 = GetCollection($collection_id1); >-is_deeply( >- \@collection1, >- [ >- $collection_id1, 'Collection1', >- 'Description1', $samplebranch->{branchcode} >- ], >- "Collection1 belongs to the sample branch (SAB)" >-); >-is( TransferCollection, "NO_ID", "TransferCollection without ID" ); >-is( >- TransferCollection($collection_id1), >- 'NO_BRANCHCODE', >- "TransferCollection without branchcode" >-); >- >-#Test AddItemToCollection >-my $record = MARC::Record->new(); >-$record->append_fields( >- MARC::Field->new( >- '952', '0', '0', >- a => $samplebranch->{branchcode}, >- b => $samplebranch->{branchcode} >- ) >-); >-my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( $record, '', ); >-my @sampleitem1 = C4::Items::AddItem( >- { >- barcode => 1, >- itemcallnumber => 'callnumber1', >- homebranch => $samplebranch->{branchcode}, >- holdingbranch => $samplebranch->{branchcode} >- }, >- $biblionumber >-); >-my $item_id1 = $sampleitem1[2]; >-my @sampleitem2 = C4::Items::AddItem( >- { >- barcode => 2, >- itemcallnumber => 'callnumber2', >- homebranch => $samplebranch->{branchcode}, >- holdingbranch => $samplebranch->{branchcode} >- }, >- $biblionumber >-); >-my $item_id2 = $sampleitem2[2]; >-is( AddItemToCollection( $collection_id1, $item_id1 ), >- 1, "Sampleitem1 has been added to Collection1" ); >-is( AddItemToCollection( $collection_id1, $item_id2 ), >- 1, "Sampleitem2 has been added to Collection1" ); >- >-#Test GetItemsInCollection >-my $itemsincollection1; >-($itemsincollection1,$success,$errorCode,$errorMessage) = GetItemsInCollection($collection_id1); >-is( scalar @$itemsincollection1, 2, "Collection1 has 2 items" ); >-is_deeply( >- $itemsincollection1, >- [ >- { >- title => undef, >- itemcallnumber => 'callnumber1', >- biblionumber => $biblionumber, >- barcode => 1 >- }, >- { >- title => undef, >- itemcallnumber => 'callnumber2', >- biblionumber => $biblionumber, >- barcode => 2 >- } >- ], >- "Collection1 has Item1 and Item2" >-); >-($itemsincollection1,$success,$errorCode,$errorMessage) = GetItemsInCollection(); >-ok( !$success, "GetItemsInCollection fails without a collection ID" ); >-is( $errorCode, 1, "Title missing, error code is 2"); >-is( $errorMessage, 'NO_ID', "Collection ID missing, error message is NO_ID"); >- >-#Test RemoveItemFromCollection >-is( RemoveItemFromCollection( $collection_id1, $item_id2 ), >- 1, "Item2 has been removed from collection 1" ); >-$itemsincollection1 = GetItemsInCollection($collection_id1); >-is( scalar @$itemsincollection1, 1, "Collection1 has 1 items" ); >- >-#Test isItemInAnyCollection >-is( C4::RotatingCollections::isItemInAnyCollection($item_id1), >- 1, "Item1 is in a collection" ); >-is( C4::RotatingCollections::isItemInAnyCollection($item_id2), >- 0, "Item2 is not in a collection" ); >-is( C4::RotatingCollections::isItemInAnyCollection(), >- 0, "isItemInAnyCollection returns 0 if no itemid given " ); >-is( C4::RotatingCollections::isItemInAnyCollection(-1), >- 0, "isItemInAnyCollection returns 0 if a wrong id is given" ); >- >-#Test isItemInThisCollection >-is( >- C4::RotatingCollections::isItemInThisCollection( >- $item_id1, $collection_id1 >- ), >- 1, >- "Item1 is in the Collection1" >-); >-is( >- C4::RotatingCollections::isItemInThisCollection( >- $item_id1, $collection_id2 >- ), >- 0, >- "Item1 is not in the Collection2" >-); >-is( >- C4::RotatingCollections::isItemInThisCollection( >- $item_id2, $collection_id2 >- ), >- 0, >- "Item2 is not in the Collection2" >-); >-is( C4::RotatingCollections::isItemInThisCollection($collection_id1), >- 0, "isItemInThisCollection returns 0 is ItemId is missing" ); >-is( C4::RotatingCollections::isItemInThisCollection($item_id1), >- 0, "isItemInThisCollection returns 0 is Collectionid if missing" ); >-is( C4::RotatingCollections::isItemInThisCollection(), >- 0, "isItemInThisCollection returns 0 if no params given" ); >- >-#Test DeleteCollection >-is( DeleteCollection($collection_id2), 1, "Collection2 deleted" ); >-is( DeleteCollection($collection_id1), 1, "Collection1 deleted" ); >-is( >- DeleteCollection(), >- 'NO_ID', >- "DeleteCollection without id" >-); >-$collections = GetCollections(); >-is( >- scalar(@$collections), >- $countcollection + 1, >- "Two Collections have been deleted" >-); >- >-#End transaction >-$dbh->rollback; >- >-- >2.1.4
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 18606
:
63508
|
63509
|
63510
|
63511
|
63512
|
63513
|
63514
|
63515
|
63516
|
63517
|
63518
|
63519
|
63520
|
63521
|
63522
|
63523
|
63524
|
63525
|
63526
|
63527
|
63528
|
66227
|
66228
|
66229
|
66230
|
66231
|
66232
|
66233
|
66234
|
66235
|
66236
|
66237
|
66238
|
66239
|
66240
|
66241
|
66286
|
66287
|
66288
|
66289
|
66290
|
66291
|
66292
|
66293
|
66294
|
66295
|
66296
|
66297
|
66298
|
66299
|
66300
|
67734
|
67735
|
67736
|
67737
|
67738
|
67739
|
67740
|
67741
|
67742
|
67743
|
67744
|
67745
|
67746
|
67747
|
67748
|
67749
|
68428
|
68429
|
68430
|
68431
|
68432
|
68433
|
68434
|
68435
|
68436
|
68437
|
68438
|
68439
|
68440
|
68441
|
68442
|
68443
|
69709
|
69710
|
69711
|
69712
|
69713
|
69714
|
69715
|
69716
|
69717
|
69718
|
69719
|
69720
|
69721
|
69722
|
69723
|
69759
|
72416
|
72417
|
72418
|
72419
|
72420
|
72421
|
72422
|
72423
|
72424
|
72425
|
72426
|
72427
|
72428
|
72429
|
72430
|
72431
|
72572
|
72573
|
72574
|
72575
|
72576
|
72577
|
72578
|
72579
|
72580
|
72581
|
72582
|
72583
|
72584
|
72585
|
72586
|
72587
|
72816
|
79141
|
79142
|
79143
|
79144
|
79145
|
79146
|
79147
|
79148
|
79149
|
79150
|
79151
|
79152
| 79153 |
79154
|
79155
|
79156
|
79157
|
79158
|
79161