| Lines 17-23
          
      
      
        Link Here | 
        
          | 17 |  | 17 |  | 
        
          | 18 | use Modern::Perl; | 18 | use Modern::Perl; | 
        
          | 19 |  | 19 |  | 
          
            
              | 20 | use Test::More tests => 69; | 20 | use Test::More tests => 70; | 
        
          | 21 | use Test::MockModule; | 21 | use Test::MockModule; | 
        
          | 22 | use Test::Warn; | 22 | use Test::Warn; | 
        
          | 23 |  | 23 |  | 
  
    | Lines 2091-2093
          subtest 'HOLDDGST tests' => sub {
      
      
        Link Here | 
        
          | 2091 |  | 2091 |  | 
        
          | 2092 |     $schema->txn_rollback; | 2092 |     $schema->txn_rollback; | 
        
          | 2093 | }; | 2093 | }; | 
          
            
              | 2094 | -  | 2094 |  | 
            
              |  |  | 2095 | subtest 'Hold priority tests' => sub { | 
            
              | 2096 |  | 
            
              | 2097 |     plan tests => 2; | 
            
              | 2098 |  | 
            
              | 2099 |     subtest 'Using priority=1' => sub { | 
            
              | 2100 |  | 
            
              | 2101 |         plan tests => 5; | 
            
              | 2102 |  | 
            
              | 2103 |         $schema->storage->txn_begin; | 
            
              | 2104 |  | 
            
              | 2105 |         # Create the items and patrons we need | 
            
              | 2106 |         my $library = $builder->build_object( { class => 'Koha::Libraries' } ); | 
            
              | 2107 |         my $itype   = $builder->build_object( { class => "Koha::ItemTypes", value => { notforloan => 0 } } ); | 
            
              | 2108 |         my $item    = $builder->build_sample_item( | 
            
              | 2109 |             { | 
            
              | 2110 |                 itype   => $itype->itemtype, | 
            
              | 2111 |                 library => $library->branchcode | 
            
              | 2112 |             } | 
            
              | 2113 |         ); | 
            
              | 2114 |         my $patron_1 = $builder->build_object( { class => "Koha::Patrons" } ); | 
            
              | 2115 |         my $patron_2 = $builder->build_object( { class => "Koha::Patrons" } ); | 
            
              | 2116 |         my $patron_3 = $builder->build_object( { class => "Koha::Patrons" } ); | 
            
              | 2117 |         my $patron_4 = $builder->build_object( { class => "Koha::Patrons" } ); | 
            
              | 2118 |  | 
            
              | 2119 |         # Place a hold on the title for both patrons | 
            
              | 2120 |         my $hold_1 = Koha::Holds->find( | 
            
              | 2121 |             C4::Reserves::AddReserve( | 
            
              | 2122 |                 { | 
            
              | 2123 |                     branchcode     => $library->branchcode, | 
            
              | 2124 |                     borrowernumber => $patron_1->borrowernumber, | 
            
              | 2125 |                     biblionumber   => $item->biblionumber, | 
            
              | 2126 |                     priority       => 1, | 
            
              | 2127 |                     itemnumber     => $item->itemnumber, | 
            
              | 2128 |                 } | 
            
              | 2129 |             ) | 
            
              | 2130 |         ); | 
            
              | 2131 |         my $hold_2 = Koha::Holds->find( | 
            
              | 2132 |             C4::Reserves::AddReserve( | 
            
              | 2133 |                 { | 
            
              | 2134 |                     branchcode     => $library->branchcode, | 
            
              | 2135 |                     borrowernumber => $patron_2->borrowernumber, | 
            
              | 2136 |                     biblionumber   => $item->biblionumber, | 
            
              | 2137 |                     priority       => 1, | 
            
              | 2138 |                     itemnumber     => $item->itemnumber, | 
            
              | 2139 |                 } | 
            
              | 2140 |             ) | 
            
              | 2141 |         ); | 
            
              | 2142 |         my $hold_3 = Koha::Holds->find( | 
            
              | 2143 |             C4::Reserves::AddReserve( | 
            
              | 2144 |                 { | 
            
              | 2145 |                     branchcode     => $library->branchcode, | 
            
              | 2146 |                     borrowernumber => $patron_3->borrowernumber, | 
            
              | 2147 |                     biblionumber   => $item->biblionumber, | 
            
              | 2148 |                     priority       => 1, | 
            
              | 2149 |                     itemnumber     => $item->itemnumber, | 
            
              | 2150 |                 } | 
            
              | 2151 |             ) | 
            
              | 2152 |         ); | 
            
              | 2153 |         my $hold_4 = Koha::Holds->find( | 
            
              | 2154 |             C4::Reserves::AddReserve( | 
            
              | 2155 |                 { | 
            
              | 2156 |                     branchcode     => $library->branchcode, | 
            
              | 2157 |                     borrowernumber => $patron_4->borrowernumber, | 
            
              | 2158 |                     biblionumber   => $item->biblionumber, | 
            
              | 2159 |                     priority       => 1, | 
            
              | 2160 |                     itemnumber     => $item->itemnumber, | 
            
              | 2161 |                 } | 
            
              | 2162 |             ) | 
            
              | 2163 |         ); | 
            
              | 2164 |  | 
            
              | 2165 |         # Each AddReserve call has an impact on the other hold's priorities | 
            
              | 2166 |         # Refresh just in case | 
            
              | 2167 |         $hold_1->discard_changes; | 
            
              | 2168 |         $hold_2->discard_changes; | 
            
              | 2169 |         $hold_3->discard_changes; | 
            
              | 2170 |         $hold_4->discard_changes; | 
            
              | 2171 |  | 
            
              | 2172 |         is( $item->biblio->holds->count, 4, '4 holds on the biblio' ); | 
            
              | 2173 |  | 
            
              | 2174 |         use DDP; | 
            
              | 2175 |         p( $hold_1->priority ); | 
            
              | 2176 |         p( $hold_2->priority ); | 
            
              | 2177 |         p( $hold_3->priority ); | 
            
              | 2178 |         p( $hold_4->priority ); | 
            
              | 2179 |  | 
            
              | 2180 |         is( $hold_1->priority, 1, 'Priority is correct (1)' ); | 
            
              | 2181 |         is( $hold_2->priority, 2, 'Priority is correct (2)' ); | 
            
              | 2182 |         is( $hold_3->priority, 3, 'Priority is correct (3)' ); | 
            
              | 2183 |         is( $hold_4->priority, 4, 'Priority is correct (4)' ); | 
            
              | 2184 |  | 
            
              | 2185 |         $schema->storage->txn_rollback; | 
            
              | 2186 |     }; | 
            
              | 2187 |  | 
            
              | 2188 |     subtest 'Using priority=undef' => sub { | 
            
              | 2189 |  | 
            
              | 2190 |         plan tests => 5; | 
            
              | 2191 |  | 
            
              | 2192 |         $schema->storage->txn_begin; | 
            
              | 2193 |  | 
            
              | 2194 |         # Create the items and patrons we need | 
            
              | 2195 |         my $library = $builder->build_object( { class => 'Koha::Libraries' } ); | 
            
              | 2196 |         my $itype   = $builder->build_object( { class => "Koha::ItemTypes", value => { notforloan => 0 } } ); | 
            
              | 2197 |         my $item    = $builder->build_sample_item( | 
            
              | 2198 |             { | 
            
              | 2199 |                 itype   => $itype->itemtype, | 
            
              | 2200 |                 library => $library->branchcode | 
            
              | 2201 |             } | 
            
              | 2202 |         ); | 
            
              | 2203 |         my $patron_1 = $builder->build_object( { class => "Koha::Patrons" } ); | 
            
              | 2204 |         my $patron_2 = $builder->build_object( { class => "Koha::Patrons" } ); | 
            
              | 2205 |         my $patron_3 = $builder->build_object( { class => "Koha::Patrons" } ); | 
            
              | 2206 |         my $patron_4 = $builder->build_object( { class => "Koha::Patrons" } ); | 
            
              | 2207 |  | 
            
              | 2208 |         # Place a hold on the title for both patrons | 
            
              | 2209 |         my $hold_1 = Koha::Holds->find( | 
            
              | 2210 |             C4::Reserves::AddReserve( | 
            
              | 2211 |                 { | 
            
              | 2212 |                     branchcode     => $library->branchcode, | 
            
              | 2213 |                     borrowernumber => $patron_1->borrowernumber, | 
            
              | 2214 |                     biblionumber   => $item->biblionumber, | 
            
              | 2215 |  | 
            
              | 2216 |                     # priority       => 1, | 
            
              | 2217 |                     itemnumber => $item->itemnumber, | 
            
              | 2218 |                 } | 
            
              | 2219 |             ) | 
            
              | 2220 |         ); | 
            
              | 2221 |         my $hold_2 = Koha::Holds->find( | 
            
              | 2222 |             C4::Reserves::AddReserve( | 
            
              | 2223 |                 { | 
            
              | 2224 |                     branchcode     => $library->branchcode, | 
            
              | 2225 |                     borrowernumber => $patron_2->borrowernumber, | 
            
              | 2226 |                     biblionumber   => $item->biblionumber, | 
            
              | 2227 |  | 
            
              | 2228 |                     # priority       => 1, | 
            
              | 2229 |                     itemnumber => $item->itemnumber, | 
            
              | 2230 |                 } | 
            
              | 2231 |             ) | 
            
              | 2232 |         ); | 
            
              | 2233 |         my $hold_3 = Koha::Holds->find( | 
            
              | 2234 |             C4::Reserves::AddReserve( | 
            
              | 2235 |                 { | 
            
              | 2236 |                     branchcode     => $library->branchcode, | 
            
              | 2237 |                     borrowernumber => $patron_3->borrowernumber, | 
            
              | 2238 |                     biblionumber   => $item->biblionumber, | 
            
              | 2239 |  | 
            
              | 2240 |                     # priority       => 1, | 
            
              | 2241 |                     itemnumber => $item->itemnumber, | 
            
              | 2242 |                 } | 
            
              | 2243 |             ) | 
            
              | 2244 |         ); | 
            
              | 2245 |         my $hold_4 = Koha::Holds->find( | 
            
              | 2246 |             C4::Reserves::AddReserve( | 
            
              | 2247 |                 { | 
            
              | 2248 |                     branchcode     => $library->branchcode, | 
            
              | 2249 |                     borrowernumber => $patron_4->borrowernumber, | 
            
              | 2250 |                     biblionumber   => $item->biblionumber, | 
            
              | 2251 |  | 
            
              | 2252 |                     # priority       => 1, | 
            
              | 2253 |                     itemnumber => $item->itemnumber, | 
            
              | 2254 |                 } | 
            
              | 2255 |             ) | 
            
              | 2256 |         ); | 
            
              | 2257 |  | 
            
              | 2258 |         # Each AddReserve call has an impact on the other hold's priorities | 
            
              | 2259 |         # Refresh just in case | 
            
              | 2260 |         $hold_1->discard_changes; | 
            
              | 2261 |         $hold_2->discard_changes; | 
            
              | 2262 |         $hold_3->discard_changes; | 
            
              | 2263 |         $hold_4->discard_changes; | 
            
              | 2264 |  | 
            
              | 2265 |         is( $item->biblio->holds->count, 4, '4 holds on the biblio' ); | 
            
              | 2266 |  | 
            
              | 2267 |         use DDP; | 
            
              | 2268 |         p( $hold_1->priority ); | 
            
              | 2269 |         p( $hold_2->priority ); | 
            
              | 2270 |         p( $hold_3->priority ); | 
            
              | 2271 |         p( $hold_4->priority ); | 
            
              | 2272 |  | 
            
              | 2273 |         is( $hold_1->priority, 1, 'Priority is correct (1)' ); | 
            
              | 2274 |         is( $hold_2->priority, 2, 'Priority is correct (2)' ); | 
            
              | 2275 |         is( $hold_3->priority, 3, 'Priority is correct (3)' ); | 
            
              | 2276 |         is( $hold_4->priority, 4, 'Priority is correct (4)' ); | 
            
              | 2277 |  | 
            
              | 2278 |         $schema->storage->txn_rollback; | 
            
              | 2279 |     }; | 
            
              | 2280 | }; |