Bugzilla – Attachment 108610 Details for
Bug 18501
Automatic refunds need protection from failure
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18501: (QA follow-up) Add test of *_on functionality
Bug-18501-QA-follow-up-Add-test-of-on-functionalit.patch (text/plain), 4.61 KB, created by
Jonathan Druart
on 2020-08-19 12:42:04 UTC
(
hide
)
Description:
Bug 18501: (QA follow-up) Add test of *_on functionality
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2020-08-19 12:42:04 UTC
Size:
4.61 KB
patch
obsolete
>From f0418e0ee8ddbbb6fd6679b576816769ac9ee31a Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Tue, 18 Aug 2020 13:26:29 +0100 >Subject: [PATCH] Bug 18501: (QA follow-up) Add test of *_on functionality > >This patch adds a test for the *_on trigger functionality to ensure >matching behaviour before and after the triggers change. > >Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >--- > t/db_dependent/Koha/Items.t | 57 ++++++++++++++++++++++++++++++++++--- > 1 file changed, 53 insertions(+), 4 deletions(-) > >diff --git a/t/db_dependent/Koha/Items.t b/t/db_dependent/Koha/Items.t >index acc57a0361..975060b50a 100644 >--- a/t/db_dependent/Koha/Items.t >+++ b/t/db_dependent/Koha/Items.t >@@ -21,6 +21,7 @@ use Modern::Perl; > > use Test::More tests => 11; > use Test::Exception; >+use Time::Fake; > > use C4::Circulation; > use C4::Context; >@@ -64,7 +65,8 @@ my $retrieved_item_1 = Koha::Items->find( $new_item_1->itemnumber ); > is( $retrieved_item_1->barcode, $new_item_1->barcode, 'Find a item by id should return the correct item' ); > > subtest 'store' => sub { >- plan tests => 4; >+ plan tests => 5; >+ > my $biblio = $builder->build_sample_biblio; > my $today = dt_from_string->set( hour => 0, minute => 0, second => 0 ); > my $item = Koha::Item->new( >@@ -82,6 +84,51 @@ subtest 'store' => sub { > is( $item->itype, $biblio->biblioitem->itemtype, 'items.itype must have been set to biblioitem.itemtype is not given'); > is( $item->permanent_location, $item->location, 'permanent_location must have been set to location if not given' ); > $item->delete; >+ >+ subtest '*_on updates' => sub { >+ plan tests => 9; >+ >+ # Once the '_on' value is set (triggered by the related field turning from false to true) >+ # it should not be re-set for any changes outside of the related field being 'unset'. >+ >+ my @fields = qw( itemlost withdrawn damaged ); >+ my $today = dt_from_string(); >+ my $yesterday = $today->clone()->subtract( days => 1 ); >+ >+ for my $field ( @fields ) { >+ my $item = $builder->build_sample_item( >+ { >+ itemlost => 0, >+ itemlost_on => undef, >+ withdrawn => 0, >+ withdrawn_on => undef, >+ damaged => 0, >+ damaged_on => undef >+ } >+ ); >+ my $field_on = $field . '_on'; >+ >+ # Set field for the first time >+ Time::Fake->offset( $yesterday->epoch ); >+ $item->$field(1)->store; >+ $item->get_from_storage; >+ is($item->$field_on, DateTime::Format::MySQL->format_datetime($yesterday), $field_on . " was set upon first truthy setting"); >+ >+ # Update the field to a new 'true' value >+ Time::Fake->offset( $today->epoch ); >+ $item->$field(2)->store; >+ $item->get_from_storage; >+ is($item->$field_on, DateTime::Format::MySQL->format_datetime($yesterday), $field_on . " was not updated upon second truthy setting"); >+ >+ # Update the field to a new 'false' value >+ $item->$field(0)->store; >+ $item->get_from_storage; >+ is($item->$field_on, undef, $field_on . " was unset upon untruthy setting"); >+ >+ Time::Fake->reset; >+ } >+ }; >+ > }; > > subtest 'get_transfer' => sub { >@@ -111,7 +158,6 @@ subtest 'holds' => sub { > my $item = $builder->build_sample_item({ > biblionumber => $biblio->biblionumber, > }); >- $nb_of_items++; > is($item->holds->count, 0, "Nothing returned if no holds"); > my $hold1 = $builder->build({ source => 'Reserve', value => { itemnumber=>$item->itemnumber, found => 'T' }}); > my $hold2 = $builder->build({ source => 'Reserve', value => { itemnumber=>$item->itemnumber, found => 'W' }}); >@@ -176,7 +222,6 @@ subtest 'can_be_transferred' => sub { > homebranch => $library1->branchcode, > holdingbranch => $library1->branchcode, > }); >- $nb_of_items++; > > is(Koha::Item::Transfer::Limits->search({ > fromBranch => $library1->branchcode, >@@ -200,7 +245,11 @@ subtest 'can_be_transferred' => sub { > 'We get the same result also if we pass the from-library parameter.'); > }; > >+# Reset nb_of_items prior to testing delete >+$nb_of_items = Koha::Items->search->count; >+ >+# Test delete > $retrieved_item_1->delete; >-is( Koha::Items->search->count, $nb_of_items + 1, 'Delete should have deleted the item' ); >+is( Koha::Items->search->count, $nb_of_items - 1, 'Delete should have deleted the item' ); > > $schema->storage->txn_rollback; >-- >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 18501
:
108004
|
108005
|
108006
|
108121
|
108122
|
108123
|
108167
|
108168
|
108169
|
108170
|
108193
|
108194
|
108195
|
108243
|
108248
|
108249
|
108291
|
108292
|
108293
|
108294
|
108295
|
108296
|
108297
|
108298
|
108299
|
108300
|
108301
|
108482
|
108483
|
108484
|
108485
|
108486
|
108487
|
108488
|
108489
|
108490
|
108491
|
108492
|
108493
|
108494
|
108575
|
108576
|
108577
|
108578
|
108579
|
108580
|
108581
|
108582
|
108583
|
108584
|
108585
|
108586
|
108596
|
108597
|
108598
|
108599
|
108600
|
108601
|
108602
|
108603
|
108604
|
108605
|
108606
|
108607
|
108608
| 108610 |
108611
|
108612
|
108613
|
108614
|
108615
|
108616
|
108617
|
108618
|
108619
|
108620
|
108621
|
108717
|
108732
|
108738
|
108739
|
108740
|
108741
|
108784
|
108785
|
108786
|
108787
|
108788
|
108795
|
111295