Bugzilla – Attachment 29218 Details for
Bug 11023
Automatic item modification by age (Was "Toggle new status for items")
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 11023: Add UT for C4::Items::ToggleNewStatus
Bug-11023-Add-UT-for-C4ItemsToggleNewStatus.patch (text/plain), 8.57 KB, created by
Jonathan Druart
on 2014-06-25 13:17:36 UTC
(
hide
)
Description:
Bug 11023: Add UT for C4::Items::ToggleNewStatus
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2014-06-25 13:17:36 UTC
Size:
8.57 KB
patch
obsolete
>From b0fbace12b4a3534aec0c50adf1aff7ec1becfd7 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@biblibre.com> >Date: Tue, 5 Nov 2013 17:22:26 +0100 >Subject: [PATCH] Bug 11023: Add UT for C4::Items::ToggleNewStatus >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >Test plan: >prove t/db_dependent/Items/ToggleNewStatus.t > >Signed-off-by: juliette et rémy <juliette.levast@iepg.fr> >--- > t/db_dependent/Items/ToggleNewStatus.t | 260 +++++++++++++++++++++++++++++++++ > 1 file changed, 260 insertions(+) > create mode 100644 t/db_dependent/Items/ToggleNewStatus.t > >diff --git a/t/db_dependent/Items/ToggleNewStatus.t b/t/db_dependent/Items/ToggleNewStatus.t >new file mode 100644 >index 0000000..8ea14f7 >--- /dev/null >+++ b/t/db_dependent/Items/ToggleNewStatus.t >@@ -0,0 +1,260 @@ >+#!/usr/bin/perl >+ >+use Modern::Perl; >+use Test::More tests => 15; >+use MARC::Record; >+use MARC::Field; >+use DateTime; >+use DateTime::Duration; >+ >+use C4::Biblio; >+use C4::Context; >+use C4::Items; >+use Koha::DateUtils; >+ >+my $dbh = C4::Context->dbh; >+$dbh->{AutoCommit} = 0; >+$dbh->{RaiseError} = 1; >+ >+$dbh->do(q| >+ DELETE FROM marc_subfield_structure >+ WHERE kohafield = 'items.new' OR kohafield = 'items.stocknumber' >+|); >+ >+my $new_tagfield = 'i'; >+$dbh->do(qq| >+ INSERT INTO marc_subfield_structure(tagfield, tagsubfield, kohafield, frameworkcode) >+ VALUES ( 952, '$new_tagfield', 'items.new', '' ) >+|); >+ >+my $record = MARC::Record->new(); >+$record->append_fields( >+ MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'), >+ MARC::Field->new('245', ' ', ' ', a => 'Silence in the library'), >+); >+my ($biblionumber, undef) = C4::Biblio::AddBiblio($record, ''); >+ >+my ($item_bibnum, $item_bibitemnum, $itemnumber) = C4::Items::AddItem( >+ { >+ homebranch => 'CPL', >+ holdingbranch => 'CPL', >+ new => 'new_value', >+ ccode => 'FIC', >+ }, >+ $biblionumber >+); >+ >+my $item = C4::Items::GetItem( $itemnumber ); >+is ( $item->{new}, 'new_value', q|AddItem insert the 'new' field| ); >+ >+my ( $tagfield, undef ) = GetMarcFromKohaField('items.itemnumber', ''); >+my $marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber ); >+is( $marc_item->subfield($tagfield, $new_tagfield), 'new_value', q|Koha mapping is correct|); >+ >+# Update the items.new field if items.ccode eq 'FIC' => should be updated >+my @rules = ( >+ { >+ conditions => [ >+ { >+ field => 'items.ccode', >+ value => 'FIC', >+ }, >+ ], >+ substitutions => [ >+ { >+ field => 'items.new', >+ value => 'updated_value', >+ }, >+ ], >+ duration => '0', >+ }, >+); >+ >+C4::Items::ToggleNewStatus( { rules => \@rules } ); >+ >+my $modified_item = C4::Items::GetItem( $itemnumber ); >+is( $modified_item->{new}, 'updated_value', q|ToggleNewStatus: The new value is updated|); >+$marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber ); >+is( $marc_item->subfield($tagfield, $new_tagfield), 'updated_value', q|ToggleNewStatus: The new value is updated| ); >+ >+# Update the items.new field if items.ccode eq 'DONT_EXIST' => should not be updated >+@rules = ( >+ { >+ conditions => [ >+ { >+ field => 'items.ccode', >+ value => 'DONT_EXIST', >+ }, >+ ], >+ substitutions => [ >+ { >+ field => 'items.new', >+ value => 'new_updated_value', >+ }, >+ ], >+ duration => '0', >+ }, >+); >+ >+C4::Items::ToggleNewStatus( { rules => \@rules } ); >+ >+$modified_item = C4::Items::GetItem( $itemnumber ); >+is( $modified_item->{new}, 'updated_value', q|ToggleNewStatus: The new value is not updated|); >+$marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber ); >+is( $marc_item->subfield($tagfield, $new_tagfield), 'updated_value', q|ToggleNewStatus: The new value is not updated| ); >+ >+# Play with duration >+$item = C4::Items::GetItem( $itemnumber ); >+my $dt_today = dt_from_string; >+my $days5ago = $dt_today->add_duration( DateTime::Duration->new( days => -5 ) ); >+ >+C4::Items::ModItem( { dateaccessioned => $days5ago }, $biblionumber, $itemnumber ); >+$item = C4::Items::GetItem( $itemnumber ); >+ >+@rules = ( >+ { >+ conditions => [ >+ { >+ field => 'items.ccode', >+ value => 'FIC', >+ }, >+ ], >+ substitutions => [ >+ { >+ field => 'items.new', >+ value => 'new_updated_value', >+ }, >+ ], >+ duration => '10', >+ }, >+); >+C4::Items::ToggleNewStatus( { rules => \@rules } ); >+$modified_item = C4::Items::GetItem( $itemnumber ); >+is( $modified_item->{new}, 'updated_value', q|ToggleNewStatus: Duration = 10 : The new value is not updated|); >+ >+$rules[0]->{duration} = 5; >+$rules[0]->{substitutions}[0]{value} = 'new_updated_value5'; >+C4::Items::ToggleNewStatus( { rules => \@rules } ); >+$modified_item = C4::Items::GetItem( $itemnumber ); >+is( $modified_item->{new}, 'new_updated_value5', q|ToggleNewStatus: Duration = 5 : The new value is updated|); >+ >+$rules[0]->{duration} = ''; >+$rules[0]->{substitutions}[0]{value} = 'new_updated_value_empty_string'; >+C4::Items::ToggleNewStatus( { rules => \@rules } ); >+$modified_item = C4::Items::GetItem( $itemnumber ); >+is( $modified_item->{new}, 'new_updated_value_empty_string', q|ToggleNewStatus: Duration = '' : The new value is updated|); >+ >+$rules[0]->{duration} = undef; >+$rules[0]->{substitutions}[0]{value} = 'new_updated_value_undef'; >+C4::Items::ToggleNewStatus( { rules => \@rules } ); >+$modified_item = C4::Items::GetItem( $itemnumber ); >+is( $modified_item->{new}, 'new_updated_value_undef', q|ToggleNewStatus: Duration = undef : The new value is updated|); >+ >+# Field deletion >+@rules = ( >+ { >+ conditions => [ >+ { >+ field => 'items.ccode', >+ value => 'FIC', >+ }, >+ ], >+ substitutions => [ >+ { >+ field => 'items.new', >+ value => '', >+ }, >+ ], >+ duration => '0', >+ }, >+); >+ >+C4::Items::ToggleNewStatus( { rules => \@rules } ); >+ >+$modified_item = C4::Items::GetItem( $itemnumber ); >+is( $modified_item->{new}, '', q|ToggleNewStatus: The new value is empty|); >+$marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber ); >+is( $marc_item->subfield($tagfield, $new_tagfield), undef, q|ToggleNewStatus: The new field is removed from the item marc| ); >+ >+# conditions multiple >+@rules = ( >+ { >+ conditions => [ >+ { >+ field => 'items.ccode', >+ value => 'FIC', >+ }, >+ { >+ field => 'items.homebranch', >+ value => 'CPL', >+ }, >+ ], >+ substitutions => [ >+ { >+ field => 'items.new', >+ value => 'new_value', >+ }, >+ ], >+ duration => '0', >+ }, >+); >+ >+C4::Items::ToggleNewStatus( { rules => \@rules } ); >+ >+$modified_item = C4::Items::GetItem( $itemnumber ); >+is( $modified_item->{new}, 'new_value', q|ToggleNewStatus: conditions multiple: all match, the new value is updated|); >+ >+@rules = ( >+ { >+ conditions => [ >+ { >+ field => 'items.ccode', >+ value => 'FIC', >+ }, >+ { >+ field => 'items.homebranch', >+ value => 'DONT_EXIST', >+ }, >+ ], >+ substitutions => [ >+ { >+ field => 'items.new', >+ value => 'new_updated_value', >+ }, >+ ], >+ duration => '0', >+ }, >+); >+ >+C4::Items::ToggleNewStatus( { rules => \@rules } ); >+ >+$modified_item = C4::Items::GetItem( $itemnumber ); >+is( $modified_item->{new}, 'new_value', q|ToggleNewStatus: conditions multiple: at least 1 condition does not match, the new value is not updated|); >+ >+@rules = ( >+ { >+ conditions => [ >+ { >+ field => 'items.ccode', >+ value => 'FIC|NFIC', >+ }, >+ { >+ field => 'items.homebranch', >+ value => 'MPL|CPL', >+ }, >+ ], >+ substitutions => [ >+ { >+ field => 'items.new', >+ value => 'new_updated_value', >+ }, >+ ], >+ duration => '0', >+ }, >+); >+ >+C4::Items::ToggleNewStatus( { rules => \@rules } ); >+ >+$modified_item = C4::Items::GetItem( $itemnumber ); >+is( $modified_item->{new}, 'new_updated_value', q|ToggleNewStatus: conditions multiple: the 2 conditions match, the new value is updated|); >+ >-- >2.0.0.rc2
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 11023
:
21926
|
21932
|
21982
|
21983
|
22004
|
22386
|
22734
|
22735
|
24068
|
24069
|
24070
|
24146
|
24147
|
24148
|
25767
|
25833
|
26817
|
26818
|
26819
|
26820
|
26821
|
26822
|
26855
|
27810
|
29216
|
29217
|
29218
|
29219
|
29220
|
29221
|
29222
|
31820
|
31821
|
31822
|
33226
|
33227
|
33228
|
33229
|
33230
|
33231
|
33232
|
33233
|
33234
|
33235
|
34782
|
34783
|
34784
|
34785
|
34786
|
34787
|
34788
|
34789
|
34790
|
34791
|
34870
|
34871
|
34872
|
34873
|
34874
|
34875
|
34876
|
34877
|
34878
|
34879
|
34880
|
34881
|
34882
|
34883
|
35375
|
35376
|
41147
|
41148