Bugzilla – Attachment 161611 Details for
Bug 35248
Bookings needs unit tests
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35248: Add unit tests for Koha::Item->check_booking
Bug-35248-Add-unit-tests-for-KohaItem-checkbooking.patch (text/plain), 4.21 KB, created by
Martin Renvoize (ashimema)
on 2024-01-29 18:35:24 UTC
(
hide
)
Description:
Bug 35248: Add unit tests for Koha::Item->check_booking
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2024-01-29 18:35:24 UTC
Size:
4.21 KB
patch
obsolete
>From a184df4bf6dad1544014e9373137b8aef092dda7 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Mon, 29 Jan 2024 18:34:46 +0000 >Subject: [PATCH] Bug 35248: Add unit tests for Koha::Item->check_booking > >This patch adds basic unit tests for the Koha::Item->check_booking >method. > >Test plan >1) Run t/db_dependant/Koha/Item.t >--- > t/db_dependent/Koha/Item.t | 123 ++++++++++++++++++++++++++++++++++++- > 1 file changed, 122 insertions(+), 1 deletion(-) > >diff --git a/t/db_dependent/Koha/Item.t b/t/db_dependent/Koha/Item.t >index 8c8e6326763..9098379ffd2 100755 >--- a/t/db_dependent/Koha/Item.t >+++ b/t/db_dependent/Koha/Item.t >@@ -20,7 +20,7 @@ > use Modern::Perl; > use utf8; > >-use Test::More tests => 33; >+use Test::More tests => 34; > use Test::Exception; > use Test::MockModule; > >@@ -2519,3 +2519,124 @@ subtest 'find_booking' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'check_booking tests' => sub { >+ plan tests => 5; >+ >+ $schema->storage->txn_begin; >+ >+ my $biblio = $builder->build_sample_biblio(); >+ my $item = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, bookable => 1 } ); >+ my $can_book = $item->check_booking( >+ { >+ start_date => dt_from_string(), >+ end_date => dt_from_string()->add( days => 7 ) >+ } >+ ); >+ >+ is( >+ $can_book, 1, >+ "True returned from Koha::Item->check_booking if there are no bookings that would clash" >+ ); >+ >+ my $start_1 = dt_from_string()->subtract( days => 7 ); >+ my $end_1 = dt_from_string()->subtract( days => 1 ); >+ my $start_2 = dt_from_string(); >+ my $end_2 = dt_from_string()->add( days => 7 ); >+ my $start_3 = dt_from_string()->add( days => 8 ); >+ my $end_3 = dt_from_string()->add( days => 16 ); >+ >+ # Past booking >+ my $booking1 = $builder->build_object( >+ { >+ class => 'Koha::Bookings', >+ value => { >+ biblio_id => $biblio->biblionumber, >+ item_id => $item->itemnumber, >+ start_date => $start_1, >+ end_date => $end_1 >+ } >+ } >+ ); >+ >+ $can_book = $item->check_booking( >+ { >+ start_date => dt_from_string(), >+ end_date => dt_from_string()->add( days => 7 ), >+ } >+ ); >+ >+ is( >+ $can_book, >+ 1, >+ "Koha::Item->check_booking returns true when we don't conflict with a past booking" >+ ); >+ >+ # Current booking >+ my $booking2 = $builder->build_object( >+ { >+ class => 'Koha::Bookings', >+ value => { >+ biblio_id => $biblio->biblionumber, >+ item_id => $item->itemnumber, >+ start_date => $start_2, >+ end_date => $end_2 >+ } >+ } >+ ); >+ >+ $can_book = $item->check_booking( >+ { >+ start_date => dt_from_string(), >+ end_date => dt_from_string()->add( days => 7 ), >+ } >+ ); >+ is( >+ $can_book, >+ 0, >+ "Koha::Item->check_booking returns false if the booking would conflict" >+ ); >+ >+ $can_book = $item->check_booking( >+ { >+ start_date => dt_from_string(), >+ end_date => dt_from_string()->add( days => 7 ), >+ booking_id => $booking2->booking_id >+ } >+ ); >+ is( >+ $can_book, >+ 1, >+ "Koha::Item->check_booking returns true if we pass the booking_id that would conflict" >+ ); >+ >+ $booking2->delete(); >+ >+ # Future booking >+ my $booking3 = $builder->build_object( >+ { >+ class => 'Koha::Bookings', >+ value => { >+ biblio_id => $biblio->biblionumber, >+ item_id => $item->itemnumber, >+ start_date => $start_3, >+ end_date => $end_3 >+ } >+ } >+ ); >+ >+ $can_book = $item->check_booking( >+ { >+ start_date => dt_from_string(), >+ end_date => dt_from_string()->add( days => 7 ), >+ } >+ ); >+ >+ is( >+ $can_book, >+ 1, >+ "Koha::Item->check_booking returns true when we don't conflict with a future booking" >+ ); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.43.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 35248
:
161061
|
161062
|
161608
|
161611
|
161620
|
161621
|
161632
|
161636
|
161651
|
161652
|
161653
|
161654
|
161655
|
161656
|
161657
|
161658
|
161659
|
161660
|
161821
|
161822
|
161823
|
161824
|
161825
|
161826
|
161827
|
161828
|
161829
|
161830
|
161831
|
161861
|
161862
|
161863
|
161864
|
161865
|
161866
|
161867
|
161868
|
161869
|
161870
|
161871
|
161890
|
161891
|
161893
|
161894
|
161895
|
161896
|
161897
|
161898
|
161899
|
161900
|
161901
|
161902
|
161903
|
161904
|
161905
|
161906
|
161907
|
161908
|
161909
|
161910
|
161911
|
161912