Bugzilla – Attachment 41383 Details for
Bug 14598
itemtype is not set on statistics by C4::Circulation::AddReturn
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 14598: (regression tests) AddReturn should store itemtype on 'statistics' table
Bug-14598-regression-tests-AddReturn-should-store-.patch (text/plain), 11.25 KB, created by
Tomás Cohen Arazi (tcohen)
on 2015-08-05 18:28:48 UTC
(
hide
)
Description:
Bug 14598: (regression tests) AddReturn should store itemtype on 'statistics' table
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2015-08-05 18:28:48 UTC
Size:
11.25 KB
patch
obsolete
>From 32d1727917d8f3c195a13ad20e6f135ce0017822 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Sun, 26 Jul 2015 02:05:16 -0300 >Subject: [PATCH] Bug 14598: (regression tests) AddReturn should store itemtype > on 'statistics' table > >This patch adds tests for C4::Circulation::AddReturn(). Both tests are wrapped >inside a subtest, and look for AddReturn storing the right itemtype on the >'statistics' table. > >Note: It also refactors the file a bit, to avoid side effects. And uses TestBuilder >to make it independent on already-present db data. It also removes warnings by mocking >C4::Context::userenv > >To test: >- Apply the patch >- Run the tests: > $ prove t/db_dependent/Circulation/Returns.t >=> FAIL: Tests fail bacause AddReturn is not storing the itemtype >- Sign off :-D > >Sponsored-by: Universidad Empresarial Siglo 21 >--- > t/db_dependent/Circulation/Returns.t | 276 ++++++++++++++++++++++++++++++----- > 1 file changed, 241 insertions(+), 35 deletions(-) > >diff --git a/t/db_dependent/Circulation/Returns.t b/t/db_dependent/Circulation/Returns.t >index e8545d1..ece53dc 100644 >--- a/t/db_dependent/Circulation/Returns.t >+++ b/t/db_dependent/Circulation/Returns.t >@@ -1,50 +1,256 @@ >+#!/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 Test::More tests => 3; >+use Test::MockModule; > > use C4::Biblio; > use C4::Circulation; > use C4::Items; >+use C4::ItemType; > use C4::Members; >+use Koha::Database; > use Koha::DateUtils; >+use Koha::Items; > > use MARC::Record; >+use MARC::Field; > >-*C4::Context::userenv = \&Mock_userenv; >+use t::lib::TestBuilder; >+my $builder = t::lib::TestBuilder->new(); > >+#Â Mock userenv, used by AddIssue >+my $branch; >+my $context = Test::MockModule->new('C4::Context'); >+$context->mock( 'userenv', sub { >+ return { branch => $branch } >+}); >+ >+my $schema = Koha::Database->new()->schema(); > my $dbh = C4::Context->dbh; > $dbh->{AutoCommit} = 0; > $dbh->{RaiseError} = 1; > >-my $record = MARC::Record->new(); >-my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, '' ); >- >-my ( undef, undef, $itemnumber ) = AddItem( >- { >- homebranch => 'CPL', >- holdingbranch => 'CPL', >- barcode => 'i_dont_exist', >- location => 'PROC', >- permanent_location => 'TEST' >- }, >- $biblionumber >-); >- >-my $item; >- >-C4::Context->set_preference( "InProcessingToShelvingCart", 1 ); >-AddReturn( 'i_dont_exist', 'CPL' ); >-$item = GetItem($itemnumber); >-is( $item->{location}, 'CART', "InProcessingToShelvingCart functions as intended" ); >- >-$item->{location} = 'PROC'; >-ModItem( $item, undef, $itemnumber ); >- >-C4::Context->set_preference( "InProcessingToShelvingCart", 0 ); >-AddReturn( 'i_dont_exist', 'CPL' ); >-$item = GetItem($itemnumber); >-is( $item->{location}, 'TEST', "InProcessingToShelvingCart functions as intended" ); >- >-# C4::Context->userenv >-sub Mock_userenv { >- return { branch => 'CPL' }; >-} >+subtest "InProcessingToShelvingCart tests" => sub { >+ >+ plan tests => 2; >+ >+ $branch = $builder->build({ source => 'Branch' })->{ branchcode }; >+ my $permanent_location = 'TEST'; >+ my $location = 'PROC'; >+ >+ # Create a biblio record with biblio-level itemtype >+ my $record = MARC::Record->new(); >+ my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, '' ); >+ my $built_item = $builder->build({ >+ source => 'Item', >+ value => { >+ biblionumber => $biblionumber, >+ homebranch => $branch, >+ holdingbranch => $branch, >+ location => $location, >+ permanent_location => $permanent_location >+ } >+ }); >+ my $barcode = $built_item->{ barcode }; >+ my $itemnumber = $built_item->{ itemnumber }; >+ my $item; >+ >+ C4::Context->set_preference( "InProcessingToShelvingCart", 1 ); >+ AddReturn( $barcode, $branch ); >+ $item = GetItem( $itemnumber ); >+ is( $item->{location}, 'CART', >+ "InProcessingToShelvingCart functions as intended" ); >+ >+ $item->{location} = $location; >+ ModItem( $item, undef, $itemnumber ); >+ >+ C4::Context->set_preference( "InProcessingToShelvingCart", 0 ); >+ AddReturn( $barcode, $branch ); >+ $item = GetItem( $itemnumber ); >+ is( $item->{location}, $permanent_location, >+ "InProcessingToShelvingCart functions as intended" ); >+}; >+ >+ >+subtest "AddReturn logging on statistics table (item-level_itypes=1)" => sub { >+ >+ plan tests => 2; >+ >+ # Set item-level item types >+ C4::Context->set_preference( "item-level_itypes", 1 ); >+ >+ # Make sure logging is enabled >+ C4::Context->set_preference( "IssueLog", 1 ); >+ C4::Context->set_preference( "ReturnLog", 1 ); >+ >+ # Create an itemtype for biblio-level item type >+ my $blevel_itemtype = $builder->build({ source => 'Itemtype' })->{ itemtype }; >+ # Create an itemtype for item-level item type >+ my $ilevel_itemtype = $builder->build({ source => 'Itemtype' })->{ itemtype }; >+ #Â Create a branch >+ $branch = $builder->build({ source => 'Branch' })->{ branchcode }; >+ #Â Create a borrower >+ my $borrowernumber = $builder->build({ >+ source => 'Borrower', >+ value => { branchcode => $branch } >+ })->{ borrowernumber }; >+ #Â Look for the defined MARC field for biblio-level itemtype >+ my $rs = $schema->resultset('MarcSubfieldStructure')->search({ >+ frameworkcode => '', >+ kohafield => 'biblioitems.itemtype' >+ }); >+ my $tagfield = $rs->first->tagfield; >+ my $tagsubfield = $rs->first->tagsubfield; >+ >+ # Create a biblio record with biblio-level itemtype >+ my $record = MARC::Record->new(); >+ $record->append_fields( >+ MARC::Field->new($tagfield,'','', $tagsubfield => $blevel_itemtype ) >+ ); >+ my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, '' ); >+ my $item_with_itemtype = $builder->build({ >+ source => 'Item', >+ value => { >+ biblionumber => $biblionumber, >+ homebranch => $branch, >+ holdingbranch => $branch, >+ itype => $ilevel_itemtype >+ } >+ }); >+ my $item_without_itemtype = $builder->build({ >+ source => 'Item', >+ value => { >+ biblionumber => $biblionumber, >+ homebranch => $branch, >+ holdingbranch => $branch, >+ itype => undef >+ } >+ }); >+ >+ my $borrower = GetMember( borrowernumber => $borrowernumber ); >+ AddIssue( $borrower, $item_with_itemtype->{ barcode } ); >+ AddReturn( $item_with_itemtype->{ barcode }, $branch ); >+ #Â Test item-level itemtype was recorded on the 'statistics' table >+ my $stat = $schema->resultset('Statistic')->search({ >+ branch => $branch, >+ type => 'return', >+ itemnumber => $item_with_itemtype->{ itemnumber } >+ }, { order_by => { -asc => 'datetime' } })->next(); >+ >+ is( $stat->itemtype, $ilevel_itemtype, >+ "item-level itype recorded on statistics for return"); >+ >+ AddIssue( $borrower, $item_without_itemtype->{ barcode } ); >+ AddReturn( $item_without_itemtype->{ barcode }, $branch ); >+ #Â Test biblio-level itemtype was recorded on the 'statistics' table >+ $stat = $schema->resultset('Statistic')->search({ >+ branch => $branch, >+ type => 'return', >+ itemnumber => $item_without_itemtype->{ itemnumber } >+ }, { order_by => { -asc => 'datetime' } })->next(); >+ >+ is( $stat->itemtype, $blevel_itemtype, >+ "biblio-level itype recorded on statistics for return as a fallback for null item-level itype"); >+ >+}; >+ >+subtest "AddReturn logging on statistics table (item-level_itypes=0)" => sub { >+ >+ plan tests => 2; >+ >+ # Make sure logging is enabled >+ C4::Context->set_preference( "IssueLog", 1 ); >+ C4::Context->set_preference( "ReturnLog", 1 ); >+ >+ # Set item-level item types >+ C4::Context->set_preference( "item-level_itypes", 0 ); >+ >+ # Create an itemtype for biblio-level item type >+ my $blevel_itemtype = $builder->build({ source => 'Itemtype' })->{ itemtype }; >+ # Create an itemtype for item-level item type >+ my $ilevel_itemtype = $builder->build({ source => 'Itemtype' })->{ itemtype }; >+ #Â Create a branch >+ $branch = $builder->build({ source => 'Branch' })->{ branchcode }; >+ #Â Create a borrower >+ my $borrowernumber = $builder->build({ >+ source => 'Borrower', >+ value => { branchcode => $branch } >+ })->{ borrowernumber }; >+ #Â Look for the defined MARC field for biblio-level itemtype >+ my $rs = $schema->resultset('MarcSubfieldStructure')->search({ >+ frameworkcode => '', >+ kohafield => 'biblioitems.itemtype' >+ }); >+ my $tagfield = $rs->first->tagfield; >+ my $tagsubfield = $rs->first->tagsubfield; >+ >+ # Create a biblio record with biblio-level itemtype >+ my $record = MARC::Record->new(); >+ $record->append_fields( >+ MARC::Field->new($tagfield,'','', $tagsubfield => $blevel_itemtype ) >+ ); >+ my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, '' ); >+ my $item_with_itemtype = $builder->build({ >+ source => 'Item', >+ value => { >+ biblionumber => $biblionumber, >+ homebranch => $branch, >+ holdingbranch => $branch, >+ itype => $ilevel_itemtype >+ } >+ }); >+ my $item_without_itemtype = $builder->build({ >+ source => 'Item', >+ value => { >+ biblionumber => $biblionumber, >+ homebranch => $branch, >+ holdingbranch => $branch, >+ itype => undef >+ } >+ }); >+ >+ my $borrower = GetMember( borrowernumber => $borrowernumber ); >+ >+ AddIssue( $borrower, $item_with_itemtype->{ barcode } ); >+ AddReturn( $item_with_itemtype->{ barcode }, $branch ); >+ #Â Test item-level itemtype was recorded on the 'statistics' table >+ my $stat = $schema->resultset('Statistic')->search({ >+ branch => $branch, >+ type => 'return', >+ itemnumber => $item_with_itemtype->{ itemnumber } >+ }, { order_by => { -asc => 'datetime' } })->next(); >+ >+ is( $stat->itemtype, $blevel_itemtype, >+ "biblio-level itype recorded on statistics for return"); >+ >+ AddIssue( $borrower, $item_without_itemtype->{ barcode } ); >+ AddReturn( $item_without_itemtype->{ barcode }, $branch ); >+ #Â Test biblio-level itemtype was recorded on the 'statistics' table >+ $stat = $schema->resultset('Statistic')->search({ >+ branch => $branch, >+ type => 'return', >+ itemnumber => $item_without_itemtype->{ itemnumber } >+ }, { order_by => { -asc => 'datetime' } })->next(); >+ >+ is( $stat->itemtype, $blevel_itemtype, >+ "biblio-level itype recorded on statistics for return"); >+}; >+ >+1; >-- >2.5.0
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 14598
:
41198
|
41199
|
41200
|
41201
|
41202
|
41203
|
41204
|
41205
|
41383
|
41384
|
41385
|
41627
|
41628
|
41629
|
41637
|
42171
|
42177
|
44665
|
44666
|
44667
|
44668
|
45030
|
45047
|
45838
|
45843
|
45844
|
46546
|
46877
|
47108
|
47109
|
47110
|
47111
|
47112
|
47113
|
47114
|
47115
|
47116
|
49797
|
49798
|
49799
|
49800
|
49801
|
49802
|
49803
|
49804
|
49805
|
49807
|
49963
|
49964
|
49965
|
49966
|
49967
|
49968
|
49969
|
49970
|
49971
|
49972
|
49978
|
49979
|
49980
|
49981
|
49982
|
49983
|
49984
|
49985
|
49986
|
49987
|
49988
|
50018
|
56941
|
56942
|
56943
|
56944
|
56945
|
56946
|
56947
|
56948
|
56949
|
56950
|
56951
|
56952
|
56953
|
62539
|
62555
|
62682