Bug 24683: whole test formatted by 'perltidy'
authorAndrew Nugged <nugged@gmail.com>
Sun, 19 Jul 2020 21:15:37 +0000 (00:15 +0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 24 Aug 2020 08:12:46 +0000 (10:12 +0200)
This is complementary patch using styling from
bundled /xt/perltidyrc file

Almost no code change except a few long constant strings
broken to parts by concatenation.

Signed-off-by: Agustin Moyano <agustinmoyano@theke.io>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t

index c10d2c5..a815713 100755 (executable)
@@ -23,68 +23,68 @@ my $dbh = C4::Context->dbh;
 
 my $builder = t::lib::TestBuilder->new;
 
-my $library1 = $builder->build({
-    source => 'Branch',
-});
-my $library2 = $builder->build({
-    source => 'Branch',
-});
-my $itemtype = $builder->build({
-    source => 'Itemtype',
-    value  => { notforloan => 0 }
-})->{itemtype};
-
-t::lib::Mocks::mock_userenv({ branchcode => $library1->{branchcode} });
-
-
-my $patron1 = $builder->build_object({
-    class => 'Koha::Patrons',
-    value => {
-        branchcode => $library1->{branchcode},
-        dateexpiry => '3000-01-01',
+my $library1 = $builder->build( { source => 'Branch', } );
+my $library2 = $builder->build( { source => 'Branch', } );
+my $itemtype = $builder->build(
+    {   source => 'Itemtype',
+        value  => { notforloan => 0 }
     }
-});
+)->{itemtype};
+
+t::lib::Mocks::mock_userenv( { branchcode => $library1->{branchcode} } );
+
+my $patron1 = $builder->build_object(
+    {   class => 'Koha::Patrons',
+        value => {
+            branchcode => $library1->{branchcode},
+            dateexpiry => '3000-01-01',
+        }
+    }
+);
 my $borrower1 = $patron1->unblessed;
 
-my $patron2 = $builder->build_object({
-    class => 'Koha::Patrons',
-    value => {
-        branchcode => $library1->{branchcode},
-        dateexpiry => '3000-01-01',
+my $patron2 = $builder->build_object(
+    {   class => 'Koha::Patrons',
+        value => {
+            branchcode => $library1->{branchcode},
+            dateexpiry => '3000-01-01',
+        }
     }
-});
+);
 
-my $patron3 = $builder->build_object({
-    class => 'Koha::Patrons',
-    value => {
-        branchcode => $library2->{branchcode},
-        dateexpiry => '3000-01-01',
+my $patron3 = $builder->build_object(
+    {   class => 'Koha::Patrons',
+        value => {
+            branchcode => $library2->{branchcode},
+            dateexpiry => '3000-01-01',
+        }
     }
-});
+);
 
 my $library_A = $library1->{branchcode};
 my $library_B = $library2->{branchcode};
 
-my $biblio = $builder->build_sample_biblio({itemtype=>$itemtype});
+my $biblio       = $builder->build_sample_biblio( { itemtype => $itemtype } );
 my $biblionumber = $biblio->biblionumber;
-my $item1  = $builder->build_sample_item({
-    biblionumber=>$biblionumber,
-    itype=>$itemtype,
-    homebranch => $library_A,
-    holdingbranch => $library_A
-});
-my $item2  = $builder->build_sample_item({
-    biblionumber=>$biblionumber,
-    itype=>$itemtype,
-    homebranch => $library_A,
-    holdingbranch => $library_A
-});
+my $item1        = $builder->build_sample_item(
+    {   biblionumber  => $biblionumber,
+        itype         => $itemtype,
+        homebranch    => $library_A,
+        holdingbranch => $library_A
+    }
+);
+my $item2 = $builder->build_sample_item(
+    {   biblionumber  => $biblionumber,
+        itype         => $itemtype,
+        homebranch    => $library_A,
+        holdingbranch => $library_A
+    }
+);
 
 # Test hold_fulfillment_policy
 $dbh->do("DELETE FROM circulation_rules");
 Koha::CirculationRules->set_rules(
-    {
-        categorycode => undef,
+    {   categorycode => undef,
         itemtype     => $itemtype,
         branchcode   => undef,
         rules        => {
@@ -98,41 +98,42 @@ Koha::CirculationRules->set_rules(
 
 my $is;
 
-$is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 });
+$is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );
 is( $is, 1, "Items availability: both of 2 items are available" );
 
-$is = IsAvailableForItemLevelRequest( $item1, $patron1);
+$is = IsAvailableForItemLevelRequest( $item1, $patron1 );
 is( $is, 0, "Item cannot be held, 2 items available" );
 
 my $issue1 = AddIssue( $patron2->unblessed, $item1->barcode );
 
-$is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 });
+$is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );
 is( $is, 1, "Items availability: one item is available" );
 
-$is = IsAvailableForItemLevelRequest( $item1, $patron1);
+$is = IsAvailableForItemLevelRequest( $item1, $patron1 );
 is( $is, 0, "Item cannot be held, 1 item available" );
 
 AddIssue( $patron2->unblessed, $item2->barcode );
 
-$is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 });
+$is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );
 is( $is, 0, "Items availability: none of items are available" );
 
-$is = IsAvailableForItemLevelRequest( $item1, $patron1);
+$is = IsAvailableForItemLevelRequest( $item1, $patron1 );
 is( $is, 1, "Item can be held, no items available" );
 
 AddReturn( $item1->barcode );
 
-{ # Remove the issue for the first patron, and modify the branch for item1
+{    # Remove the issue for the first patron, and modify the branch for item1
     subtest 'IsAvailableForItemLevelRequest behaviours depending on ReservesControlBranch + holdallowed' => sub {
         plan tests => 2;
 
-        my $hold_allowed_from_home_library = 1;
+        my $hold_allowed_from_home_library  = 1;
         my $hold_allowed_from_any_libraries = 2;
 
         subtest 'Item is available at a different library' => sub {
             plan tests => 13;
 
-            $item1->set({homebranch => $library_B, holdingbranch => $library_B })->store;
+            $item1->set( { homebranch => $library_B, holdingbranch => $library_B } )->store;
+
             #Scenario is:
             #One shelf holds is 'If all unavailable'/2
             #Item 1 homebranch library B is available
@@ -140,68 +141,88 @@ AddReturn( $item1->barcode );
             #Borrower1 is from library A
 
             {
-                set_holdallowed_rule( $hold_allowed_from_home_library );
+                set_holdallowed_rule($hold_allowed_from_home_library);
 
-                t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary');
+                t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' );
 
-                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 }); # patron1 in library A, library A 0 items, library B 1 item
+                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );    # patron1 in library A, library A 0 items, library B 1 item
                 is( $is, 0, "Items availability: hold allowed from home + ReservesControlBranch=ItemHomeLibrary + one item is available at different library" );
 
-                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
-                is( $is, 1, "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, One item is available at different library, not holdable = none available => the hold is allowed at item level" );
-                $is = IsAvailableForItemLevelRequest( $item1, $patron2);
-                is( $is, 1, "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, One item is available at home library, holdable = one available => the hold is not allowed at item level" );
+                $is = IsAvailableForItemLevelRequest( $item1, $patron1 );
+                is( $is, 1,
+                        "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, "
+                      . "One item is available at different library, not holdable = none available => the hold is allowed at item level" );
+                $is = IsAvailableForItemLevelRequest( $item1, $patron2 );
+                is( $is, 1,
+                        "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, "
+                      . "One item is available at home library, holdable = one available => the hold is not allowed at item level" );
                 set_holdallowed_rule( $hold_allowed_from_any_libraries, $library_B );
+
                 #Adding a rule for the item's home library affects the availability for a borrower from another library because ReservesControlBranch is set to ItemHomeLibrary
 
-                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 }); # patron1 in library A, library A 0 items, library B 1 item
-                is( $is, 1, "Items availability: hold allowed from any library for library B + ReservesControlBranch=ItemHomeLibrary + one item is available at different library" );
+                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );    # patron1 in library A, library A 0 items, library B 1 item
+                is( $is, 1,
+                    "Items availability: hold allowed from any library for library B + ReservesControlBranch=ItemHomeLibrary + one item is available at different library" );
+
+                $is = IsAvailableForItemLevelRequest( $item1, $patron1 );
+                is( $is, 0,
+                        "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, "
+                      . "One item is available at different library, holdable = one available => the hold is not allowed at item level" );
 
-                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
-                is( $is, 0, "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, One item is available at different library, holdable = one available => the hold is not allowed at item level" );
+                t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
 
-                t::lib::Mocks::mock_preference('ReservesControlBranch', 'PatronLibrary');
+                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );    # patron1 in library A, library A 0 items, library B 1 item
+                is( $is, 0,
+                    "Items availability: hold allowed from any library for library B + ReservesControlBranch=PatronLibrary + one item is available at different library" );
 
-                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 }); # patron1 in library A, library A 0 items, library B 1 item
-                is( $is, 0, "Items availability: hold allowed from any library for library B + ReservesControlBranch=PatronLibrary + one item is available at different library" );
+                $is = IsAvailableForItemLevelRequest( $item1, $patron1 );
+                is( $is, 1,
+                        "Hold allowed from home library + ReservesControlBranch=PatronLibrary, "
+                      . "One item is available at different library, not holdable = none available => the hold is allowed at item level" );
 
-                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
-                is( $is, 1, "Hold allowed from home library + ReservesControlBranch=PatronLibrary, One item is available at different library, not holdable = none available => the hold is allowed at item level" );
                 #Adding a rule for the patron's home library affects the availability for an item from another library because ReservesControlBranch is set to PatronLibrary
                 set_holdallowed_rule( $hold_allowed_from_any_libraries, $library_A );
 
-                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 }); # patron1 in library A, library A 0 items, library B 1 item
-                is( $is, 1, "Items availability: hold allowed from any library for library A + ReservesControlBranch=PatronLibrary + one item is available at different library" );
+                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );    # patron1 in library A, library A 0 items, library B 1 item
+                is( $is, 1,
+                    "Items availability: hold allowed from any library for library A + ReservesControlBranch=PatronLibrary + one item is available at different library" );
 
-                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
-                is( $is, 0, "Hold allowed from home library + ReservesControlBranch=PatronLibrary, One item is available at different library, holdable = one available => the hold is not allowed at item level" );
+                $is = IsAvailableForItemLevelRequest( $item1, $patron1 );
+                is( $is, 0,
+                        "Hold allowed from home library + ReservesControlBranch=PatronLibrary, "
+                      . "One item is available at different library, holdable = one available => the hold is not allowed at item level" );
             }
 
             {
-                set_holdallowed_rule( $hold_allowed_from_any_libraries );
+                set_holdallowed_rule($hold_allowed_from_any_libraries);
 
-                t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary');
+                t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' );
 
-                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 }); # patron1 in library A, library A 0 items, library B 1 item
+                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );    # patron1 in library A, library A 0 items, library B 1 item
                 is( $is, 1, "Items availability: hold allowed from any library + ReservesControlBranch=ItemHomeLibrary + one item is available at different library" );
 
-                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
-                is( $is, 0, "Hold allowed from any library + ReservesControlBranch=ItemHomeLibrary, One item is available at the diff library, holdable = 1 available => the hold is not allowed at item level" );
+                $is = IsAvailableForItemLevelRequest( $item1, $patron1 );
+                is( $is, 0,
+                        "Hold allowed from any library + ReservesControlBranch=ItemHomeLibrary, "
+                      . "One item is available at the diff library, holdable = 1 available => the hold is not allowed at item level" );
 
-                t::lib::Mocks::mock_preference('ReservesControlBranch', 'PatronLibrary');
+                t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
 
-                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 }); # patron1 in library A, library A 0 items, library B 1 item
+                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );    # patron1 in library A, library A 0 items, library B 1 item
                 is( $is, 1, "Items availability: hold allowed from any library + ReservesControlBranch=PatronLibrary + one item is available at different library" );
 
-                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
-                is( $is, 0, "Hold allowed from any library + ReservesControlBranch=PatronLibrary, One item is available at the diff library, holdable = 1 available => the hold is not allowed at item level" );
+                $is = IsAvailableForItemLevelRequest( $item1, $patron1 );
+                is( $is, 0,
+                        "Hold allowed from any library + ReservesControlBranch=PatronLibrary, "
+                      . "One item is available at the diff library, holdable = 1 available => the hold is not allowed at item level" );
             }
         };
 
         subtest 'Item is available at the same library' => sub {
             plan tests => 8;
 
-            $item1->set({homebranch => $library_A, holdingbranch => $library_A })->store;
+            $item1->set( { homebranch => $library_A, holdingbranch => $library_A } )->store;
+
             #Scenario is:
             #One shelf holds is 'If all unavailable'/2
             #Item 1 homebranch library A is available
@@ -211,78 +232,87 @@ AddReturn( $item1->barcode );
             #ReservesControlBranch is not checked in these subs we are testing?
 
             {
-                set_holdallowed_rule( $hold_allowed_from_home_library );
+                set_holdallowed_rule($hold_allowed_from_home_library);
 
-                t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary');
+                t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' );
 
-                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 }); # patron1 in library A, library A 1 item
+                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );    # patron1 in library A, library A 1 item
                 is( $is, 1, "Items availability: hold allowed from home library + ReservesControlBranch=ItemHomeLibrary + one item is available at home library" );
 
-                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
-                is( $is, 0, "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, One item is available at the same library, holdable = 1 available  => the hold is not allowed at item level" );
+                $is = IsAvailableForItemLevelRequest( $item1, $patron1 );
+                is( $is, 0,
+                        "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, "
+                      . "One item is available at the same library, holdable = 1 available  => the hold is not allowed at item level" );
 
-                t::lib::Mocks::mock_preference('ReservesControlBranch', 'PatronLibrary');
+                t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
 
-                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 }); # patron1 in library A, library A 1 item
+                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );    # patron1 in library A, library A 1 item
                 is( $is, 1, "Items availability: hold allowed from home library + ReservesControlBranch=PatronLibrary + one item is available at home library" );
 
-                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
-                is( $is, 0, "Hold allowed from home library + ReservesControlBranch=PatronLibrary, One item is available at the same library, holdable = 1 available  => the hold is not allowed at item level" );
+                $is = IsAvailableForItemLevelRequest( $item1, $patron1 );
+                is( $is, 0,
+                        "Hold allowed from home library + ReservesControlBranch=PatronLibrary, "
+                      . "One item is available at the same library, holdable = 1 available  => the hold is not allowed at item level" );
             }
 
             {
-                set_holdallowed_rule( $hold_allowed_from_any_libraries );
+                set_holdallowed_rule($hold_allowed_from_any_libraries);
 
-                t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary');
+                t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' );
 
-                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 }); # patron1 in library A, library A 1 item
+                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );    # patron1 in library A, library A 1 item
                 is( $is, 1, "Items availability: hold allowed from any library + ReservesControlBranch=ItemHomeLibrary + one item is available at home library" );
 
-                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
-                is( $is, 0, "Hold allowed from any library + ReservesControlBranch=ItemHomeLibrary, One item is available at the same library, holdable = 1 available => the hold is not allowed at item level" );
+                $is = IsAvailableForItemLevelRequest( $item1, $patron1 );
+                is( $is, 0,
+                        "Hold allowed from any library + ReservesControlBranch=ItemHomeLibrary, "
+                      . "One item is available at the same library, holdable = 1 available => the hold is not allowed at item level" );
 
-                t::lib::Mocks::mock_preference('ReservesControlBranch', 'PatronLibrary');
+                t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
 
-                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 }); # patron1 in library A, library A 1 item
+                $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );    # patron1 in library A, library A 1 item
                 is( $is, 1, "Items availability: hold allowed from any library + ReservesControlBranch=PatronLibrary + one item is available at home library" );
 
-                $is = IsAvailableForItemLevelRequest( $item1, $patron1);
-                is( $is, 0, "Hold allowed from any library + ReservesControlBranch=PatronLibrary, One item is available at the same library, holdable = 1 available  => the hold is not allowed at item level" );
+                $is = IsAvailableForItemLevelRequest( $item1, $patron1 );
+                is( $is, 0,
+                        "Hold allowed from any library + ReservesControlBranch=PatronLibrary, "
+                      . "One item is available at the same library, holdable = 1 available  => the hold is not allowed at item level" );
             }
         };
     };
 }
 
-my $itemtype2 = $builder->build({
-    source => 'Itemtype',
-    value  => { notforloan => 0 }
-})->{itemtype};
-my $item3 = $builder->build_sample_item({ itype => $itemtype2 });
-
-my $hold = $builder->build({
-    source => 'Reserve',
-    value =>{
-        itemnumber => $item3->itemnumber,
-        found => 'T'
+my $itemtype2 = $builder->build(
+    {   source => 'Itemtype',
+        value  => { notforloan => 0 }
     }
-});
+)->{itemtype};
+my $item3 = $builder->build_sample_item( { itype => $itemtype2 } );
+
+my $hold = $builder->build(
+    {   source => 'Reserve',
+        value  => {
+            itemnumber => $item3->itemnumber,
+            found      => 'T'
+        }
+    }
+);
 
 Koha::CirculationRules->set_rules(
-    {
-        categorycode => undef,
+    {   categorycode => undef,
         itemtype     => $itemtype2,
         branchcode   => undef,
         rules        => {
-            maxissueqty     => 99,
-            onshelfholds    => 0,
+            maxissueqty  => 99,
+            onshelfholds => 0,
         }
     }
 );
 
-$is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 }); # patron1 in library A, library A 1 item
+$is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );    # patron1 in library A, library A 1 item
 is( $is, 1, "Items availability: 1 item is available, 1 item held in T" );
 
-$is = IsAvailableForItemLevelRequest( $item3, $patron1);
+$is = IsAvailableForItemLevelRequest( $item3, $patron1 );
 is( $is, 1, "Item can be held, items in transit are not available" );
 
 subtest 'Check holds availability with different item types' => sub {
@@ -363,20 +393,18 @@ subtest 'Check holds availability with different item types' => sub {
     is( $is, 1, "Item5 can be requested to hold, 2 items, Item4 checked out, Item5 restricted" );
 };
 
-
 # Cleanup
 $schema->storage->txn_rollback;
 
 sub set_holdallowed_rule {
     my ( $holdallowed, $branchcode ) = @_;
     Koha::CirculationRules->set_rules(
-        {
-            branchcode   => $branchcode || undef,
-            itemtype     => undef,
-            rules        => {
-                holdallowed              => $holdallowed,
-                hold_fulfillment_policy  => 'any',
-                returnbranch             => 'homebranch',
+        {   branchcode => $branchcode || undef,
+            itemtype   => undef,
+            rules      => {
+                holdallowed             => $holdallowed,
+                hold_fulfillment_policy => 'any',
+                returnbranch            => 'homebranch',
             }
         }
     );