View | Details | Raw Unified | Return to bug 38375
Collapse All | Expand All

(-)a/t/db_dependent/SIP/Transaction.t (-26 / +64 lines)
Lines 1099-1129 subtest checkin_withdrawn => sub { Link Here
1099
};
1099
};
1100
1100
1101
subtest _get_sort_bin => sub {
1101
subtest _get_sort_bin => sub {
1102
    plan tests => 6;
1102
    plan tests => 24;
1103
1103
1104
    my $library  = $builder->build_object( { class => 'Koha::Libraries' } );
1104
    my $library  = $builder->build_object( { class => 'Koha::Libraries' } );
1105
    my $branch   = $library->branchcode;
1105
    my $branch   = $library->branchcode;
1106
    my $library2 = $builder->build_object( { class => 'Koha::Libraries' } );
1106
    my $library2 = $builder->build_object( { class => 'Koha::Libraries' } );
1107
    my $branch2  = $library2->branchcode;
1107
    my $branch2  = $library2->branchcode;
1108
1108
1109
    # Rules starts with malformed line, empty line and a comment to prove they are skipped
1110
    my $rules = <<"RULES";
1111
$branch:homebranch:ne:\$holdingbranch:X\r
1112
$branch:effective_itemtype:eq:CD:0\r
1113
$branch:itemcallnumber:<:340:1\r
1114
$branch:itemcallnumber:<:370:2\r
1115
$branch:itemcallnumber:<:600:3\r
1116
$branch2:homebranch:ne:\$holdingbranch:X\r
1117
$branch2:effective_itemtype:eq:CD:4\r
1118
$branch2:itemcallnumber:>:600:5\r
1119
$branch2:effective_itemtype:eq:BOOK:ccode:eq:TEEN:6\r
1120
# Comment line to skip\r
1121
\r
1122
$branch:homebranch:Z\r
1123
RULES
1124
1125
    t::lib::Mocks::mock_preference( 'SIP2SortBinMapping', $rules );
1126
1127
    my $item_cd = $builder->build_sample_item(
1109
    my $item_cd = $builder->build_sample_item(
1128
        {
1110
        {
1129
            library => $library->branchcode,
1111
            library => $library->branchcode,
Lines 1156-1182 RULES Link Here
1156
1138
1157
    my $bin;
1139
    my $bin;
1158
1140
1141
    my @line_endings = ( "\n", "\r\n", "\r" );
1142
    my %eol_display  = ( "\n" => '\\n', "\r\n" => '\\r\\n', "\r" => '\\r' );
1143
1144
    foreach my $eol (@line_endings) {
1145
1146
        # Rules contain malformed line, empty line and a comment to prove they are skipped
1147
        my $rules = join(
1148
            $eol,
1149
            (
1150
                "$branch:homebranch:ne:\$holdingbranch:X",
1151
                "$branch:effective_itemtype:eq:CD:0",
1152
                "$branch:itemcallnumber:<:340:1",
1153
                "$branch:itemcallnumber:<:370:2",
1154
                "$branch:itemcallnumber:<:600:3",
1155
                "$branch2:homebranch:ne:\$holdingbranch:X",
1156
                "$branch2:effective_itemtype:eq:CD:4",
1157
                "$branch2:itemcallnumber:>:600:5",
1158
                "$branch2:effective_itemtype:eq:BOOK:ccode:eq:TEEN:6",
1159
                "# Comment line to skip",
1160
                "",                        # Empty line
1161
                "$branch:homebranch:Z",    # Malformed line
1162
            )
1163
        );
1164
1165
        t::lib::Mocks::mock_preference( 'SIP2SortBinMapping', $rules );
1166
1167
        # Set holdingbranch as though item returned to library other than homebranch (As AddReturn would)
1168
        $item_cd->holdingbranch( $library2->branchcode )->store();
1169
        $bin = C4::SIP::ILS::Transaction::Checkin::_get_sort_bin( $item_cd, $library2->branchcode );
1170
        is( $bin, 'X', "Item parameter on RHS of comparison works (ne comparator) with EOL '$eol_display{$eol}'" );
1171
1172
        # Reset holdingbranch as though item returned to home library
1173
        $item_cd->holdingbranch( $library->branchcode )->store();
1174
        $bin = C4::SIP::ILS::Transaction::Checkin::_get_sort_bin( $item_cd, $library->branchcode );
1175
        is( $bin, '0', "Fixed value on RHS of comparison works (eq comparator) with EOL '$eol_display{$eol}'" );
1176
        $bin = C4::SIP::ILS::Transaction::Checkin::_get_sort_bin( $item_book, $library->branchcode );
1177
        is( $bin, '1', "Rules applied in order (< comparator) with EOL '$eol_display{$eol}'" );
1178
        $item_book->itemcallnumber('350.20')->store();
1179
        $bin = C4::SIP::ILS::Transaction::Checkin::_get_sort_bin( $item_book, $library->branchcode );
1180
        is( $bin, '2', "Rules applied in order (< comparator) with EOL '$eol_display{$eol}'" );
1181
1182
        $bin = C4::SIP::ILS::Transaction::Checkin::_get_sort_bin( $item_book2, $library2->branchcode );
1183
        is( $bin, '6', "Rules with multiple field matches with EOL '$eol_display{$eol}'" );
1184
1185
        warnings_are { $bin = C4::SIP::ILS::Transaction::Checkin::_get_sort_bin( $item_dvd, $library2->branchcode ); }
1186
        ["Malformed preference line found: '$branch:homebranch:Z'"],
1187
            "Comments and blank lines are skipped, Malformed lines are warned and skipped with EOL '$eol_display{$eol}'";
1188
1189
        # Reset for next loop
1190
        $item_book->itemcallnumber('200.01')->store();
1191
    }
1192
1193
    my $mixed_rules =
1194
        "$branch:homebranch:ne:\$holdingbranch:X\n$branch:effective_itemtype:eq:CD:0\r\n$branch:itemcallnumber:<:340:1\r$branch:itemcallnumber:<:370:2\r\n$branch:itemcallnumber:<:600:3\n$branch2:homebranch:ne:\$holdingbranch:X\r$branch2:effective_itemtype:eq:CD:4\r\n$branch2:itemcallnumber:>:600:5\n$branch2:effective_itemtype:eq:BOOK:ccode:eq:TEEN:6\r# Comment line to skip\r\n\r\n\n$branch:homebranch:Z";
1195
    t::lib::Mocks::mock_preference( 'SIP2SortBinMapping', $mixed_rules );
1196
1159
    # Set holdingbranch as though item returned to library other than homebranch (As AddReturn would)
1197
    # Set holdingbranch as though item returned to library other than homebranch (As AddReturn would)
1160
    $item_cd->holdingbranch( $library2->branchcode )->store();
1198
    $item_cd->holdingbranch( $library2->branchcode )->store();
1161
    $bin = C4::SIP::ILS::Transaction::Checkin::_get_sort_bin( $item_cd, $library2->branchcode );
1199
    $bin = C4::SIP::ILS::Transaction::Checkin::_get_sort_bin( $item_cd, $library2->branchcode );
1162
    is( $bin, 'X', "Item parameter on RHS of comparison works (ne comparator)" );
1200
    is( $bin, 'X', "Item parameter on RHS of comparison works (ne comparator) with mixed EOL" );
1163
1201
1164
    # Reset holdingbranch as though item returned to home library
1202
    # Reset holdingbranch as though item returned to home library
1165
    $item_cd->holdingbranch( $library->branchcode )->store();
1203
    $item_cd->holdingbranch( $library->branchcode )->store();
1166
    $bin = C4::SIP::ILS::Transaction::Checkin::_get_sort_bin( $item_cd, $library->branchcode );
1204
    $bin = C4::SIP::ILS::Transaction::Checkin::_get_sort_bin( $item_cd, $library->branchcode );
1167
    is( $bin, '0', "Fixed value on RHS of comparison works (eq comparator)" );
1205
    is( $bin, '0', "Fixed value on RHS of comparison works (eq comparator) with mixed EOL" );
1168
    $bin = C4::SIP::ILS::Transaction::Checkin::_get_sort_bin( $item_book, $library->branchcode );
1206
    $bin = C4::SIP::ILS::Transaction::Checkin::_get_sort_bin( $item_book, $library->branchcode );
1169
    is( $bin, '1', "Rules applied in order (< comparator)" );
1207
    is( $bin, '1', "Rules applied in order (< comparator) with mixed EOL" );
1170
    $item_book->itemcallnumber('350.20')->store();
1208
    $item_book->itemcallnumber('350.20')->store();
1171
    $bin = C4::SIP::ILS::Transaction::Checkin::_get_sort_bin( $item_book, $library->branchcode );
1209
    $bin = C4::SIP::ILS::Transaction::Checkin::_get_sort_bin( $item_book, $library->branchcode );
1172
    is( $bin, '2', "Rules applied in order (< comparator)" );
1210
    is( $bin, '2', "Rules applied in order (< comparator) with mixed EOL" );
1173
1211
1174
    $bin = C4::SIP::ILS::Transaction::Checkin::_get_sort_bin( $item_book2, $library2->branchcode );
1212
    $bin = C4::SIP::ILS::Transaction::Checkin::_get_sort_bin( $item_book2, $library2->branchcode );
1175
    is( $bin, '6', "Rules with multiple field matches" );
1213
    is( $bin, '6', "Rules with multiple field matches with mixed EOL" );
1176
1214
1177
    warnings_are { $bin = C4::SIP::ILS::Transaction::Checkin::_get_sort_bin( $item_dvd, $library2->branchcode ); }
1215
    warnings_are { $bin = C4::SIP::ILS::Transaction::Checkin::_get_sort_bin( $item_dvd, $library2->branchcode ); }
1178
    ["Malformed preference line found: '$branch:homebranch:Z'"],
1216
    ["Malformed preference line found: '$branch:homebranch:Z'"],
1179
        "Comments and blank lines are skipped, Malformed lines are warned and skipped";
1217
        "Comments and blank lines are skipped, Malformed lines are warned and skipped with mixed EOL";
1218
1180
};
1219
};
1181
1220
1182
subtest item_circulation_status => sub {
1221
subtest item_circulation_status => sub {
1183
- 

Return to bug 38375