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

(-)a/t/db_dependent/Circulation/MarkIssueReturned.t (-13 / +13 lines)
Lines 20-25 use Modern::Perl; Link Here
20
use Test::NoWarnings;
20
use Test::NoWarnings;
21
use Test::More tests => 6;
21
use Test::More tests => 6;
22
use Test::Exception;
22
use Test::Exception;
23
use Test::Warn;
23
24
24
use t::lib::Mocks;
25
use t::lib::Mocks;
25
use t::lib::TestBuilder;
26
use t::lib::TestBuilder;
Lines 133-139 subtest 'Anonymous patron tests' => sub { Link Here
133
134
134
subtest 'Manually pass a return date' => sub {
135
subtest 'Manually pass a return date' => sub {
135
136
136
    plan tests => 3;
137
    plan tests => 4;
137
138
138
    $schema->storage->txn_begin;
139
    $schema->storage->txn_begin;
139
140
Lines 165-182 subtest 'Manually pass a return date' => sub { Link Here
165
166
166
    $issue = C4::Circulation::AddIssue( $patron, $item->barcode );
167
    $issue = C4::Circulation::AddIssue( $patron, $item->barcode );
167
168
168
    {
169
    warning_like(
169
        # Hiding the expected warning displayed by DBI
170
        sub {
170
        # DBD::mysql::st execute failed: Incorrect datetime value: 'bad_date' for column 'returndate'
171
            throws_ok {
171
        local *STDERR;
172
                $issue_id =
172
        open STDERR, '>', '/dev/null';
173
                    C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, 'bad_date', 0 );
173
        throws_ok {
174
            }
174
            $issue_id = C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, 'bad_date', 0 );
175
            'Koha::Exceptions::Object::BadValue',
175
        }
176
                'An exception is thrown on bad date';
176
        'Koha::Exceptions::Object::BadValue',
177
        },
177
            'An exception is thrown on bad date';
178
        qr{Incorrect datetime value: 'bad_date' for column .*returndate}
178
        close STDERR;
179
    );
179
    }
180
180
181
    $schema->storage->txn_rollback;
181
    $schema->storage->txn_rollback;
182
};
182
};
(-)a/t/db_dependent/Koha/Account.t (-18 / +21 lines)
Lines 23-28 use Test::NoWarnings; Link Here
23
use Test::More tests => 16;
23
use Test::More tests => 16;
24
use Test::MockModule;
24
use Test::MockModule;
25
use Test::Exception;
25
use Test::Exception;
26
use Test::Warn;
26
27
27
use DateTime;
28
use DateTime;
28
29
Lines 336-342 subtest 'add_credit() tests' => sub { Link Here
336
337
337
subtest 'add_debit() tests' => sub {
338
subtest 'add_debit() tests' => sub {
338
339
339
    plan tests => 14;
340
    plan tests => 15;
340
341
341
    $schema->storage->txn_begin;
342
    $schema->storage->txn_begin;
342
343
Lines 364-387 subtest 'add_debit() tests' => sub { Link Here
364
    }
365
    }
365
    'Koha::Exceptions::Account::AmountNotPositive', 'Expected validation exception thrown (amount)';
366
    'Koha::Exceptions::Account::AmountNotPositive', 'Expected validation exception thrown (amount)';
366
367
367
    throws_ok {
368
    warning_like(
368
        local *STDERR;
369
        sub {
369
        open STDERR, '>', '/dev/null';
370
            throws_ok {
370
        $account->add_debit(
371
                $account->add_debit(
371
            {
372
                    {
372
                amount      => 5,
373
                        amount      => 5,
373
                description => 'type validation failure',
374
                        description => 'type validation failure',
374
                library_id  => $patron->branchcode,
375
                        library_id  => $patron->branchcode,
375
                note        => 'this should fail anyway',
376
                        note        => 'this should fail anyway',
376
                type        => 'failure',
377
                        type        => 'failure',
377
                user_id     => $patron->id,
378
                        user_id     => $patron->id,
378
                interface   => 'commandline'
379
                        interface   => 'commandline'
380
                    }
381
                );
379
            }
382
            }
380
        );
383
            'Koha::Exceptions::Account::UnrecognisedType',
381
        close STDERR;
384
                'Expected validation exception thrown (type)';
382
    }
385
        },
383
    'Koha::Exceptions::Account::UnrecognisedType',
386
        qr{a foreign key constraint fails}
384
        'Expected validation exception thrown (type)';
387
    );
385
388
386
    throws_ok {
389
    throws_ok {
387
        $account->add_debit(
390
        $account->add_debit(
(-)a/t/db_dependent/Koha/ApiKey.t (-11 / +12 lines)
Lines 21-26 use Test::NoWarnings; Link Here
21
use Test::More tests => 5;
21
use Test::More tests => 5;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Exception;
23
use Test::Exception;
24
use Test::Warn;
24
25
25
use t::lib::TestBuilder;
26
use t::lib::TestBuilder;
26
27
Lines 33-39 my $builder = t::lib::TestBuilder->new; Link Here
33
34
34
subtest 'store() tests' => sub {
35
subtest 'store() tests' => sub {
35
36
36
    plan tests => 16;
37
    plan tests => 17;
37
38
38
    $schema->storage->txn_begin;
39
    $schema->storage->txn_begin;
39
40
Lines 102-117 subtest 'store() tests' => sub { Link Here
102
    my $deleted_id       = $patron_to_delete->id;
103
    my $deleted_id       = $patron_to_delete->id;
103
    $patron_to_delete->delete;
104
    $patron_to_delete->delete;
104
105
105
    {    # hide useless warnings
106
    warning_like(
106
        local *STDERR;
107
        sub {
107
        open STDERR, '>', '/dev/null';
108
            throws_ok {
108
        throws_ok {
109
                Koha::ApiKey->new( { patron_id => $deleted_id, description => 'a description' } )->store
109
            Koha::ApiKey->new( { patron_id => $deleted_id, description => 'a description' } )->store
110
            }
110
        }
111
            'Koha::Exceptions::Object::FKConstraint',
111
        'Koha::Exceptions::Object::FKConstraint',
112
                'Invalid patron ID raises exception';
112
            'Invalid patron ID raises exception';
113
        },
113
        close STDERR;
114
        qr{a foreign key constraint fails}
114
    }
115
    );
115
    is( $@->message,   'Broken FK constraint', 'Exception message is correct' );
116
    is( $@->message,   'Broken FK constraint', 'Exception message is correct' );
116
    is( $@->broken_fk, 'patron_id',            'Exception field is correct' );
117
    is( $@->broken_fk, 'patron_id',            'Exception field is correct' );
117
118
(-)a/t/db_dependent/Koha/Checkouts/Renewal.t (-22 / +14 lines)
Lines 84-113 subtest "store() tests" => sub { Link Here
84
        'Renewal stored on the DB'
84
        'Renewal stored on the DB'
85
    );
85
    );
86
86
87
    {    # hide useless warnings
87
    my $another_checkout = $builder->build_object( { class => 'Koha::Checkouts' } );
88
        local *STDERR;
88
    my $checkout_id      = $another_checkout->id;
89
        open STDERR, '>', '/dev/null';
89
    $another_checkout->delete;
90
91
        my $another_checkout = $builder->build_object( { class => 'Koha::Checkouts' } );
92
        my $checkout_id      = $another_checkout->id;
93
        $another_checkout->delete;
94
95
        my $THE_renewal;
96
97
        throws_ok {
98
            $THE_renewal = Koha::Checkouts::Renewal->new(
99
                {
100
                    checkout_id => $checkout_id,
101
                    interface   => 'intranet'
102
                }
103
            )->store;
104
        }
105
        'Koha::Exceptions::Object::FKConstraint',
106
            'An exception is thrown on invalid checkout_id';
107
        close STDERR;
108
90
109
        is( $@->broken_fk, 'checkout_id', 'Exception field is correct' );
91
    throws_ok {
92
        Koha::Checkouts::Renewal->new(
93
            {
94
                checkout_id => $checkout_id,
95
                interface   => 'intranet'
96
            }
97
        )->store;
110
    }
98
    }
99
    'Koha::Exceptions::Object::FKConstraint',
100
        'An exception is thrown on invalid checkout_id';
101
102
    is( $@->broken_fk, 'checkout_id', 'Exception field is correct' );
111
103
112
    $schema->storage->txn_rollback;
104
    $schema->storage->txn_rollback;
113
};
105
};
(-)a/t/db_dependent/Koha/Checkouts/ReturnClaim.t (-11 / +10 lines)
Lines 20-25 use Modern::Perl; Link Here
20
use Test::NoWarnings;
20
use Test::NoWarnings;
21
use Test::More tests => 7;
21
use Test::More tests => 7;
22
use Test::Exception;
22
use Test::Exception;
23
use Test::Warn;
23
24
24
use Koha::Database;
25
use Koha::Database;
25
use Koha::DateUtils qw( dt_from_string output_pref );
26
use Koha::DateUtils qw( dt_from_string output_pref );
Lines 116-122 subtest "store() tests" => sub { Link Here
116
117
117
subtest "resolve() tests" => sub {
118
subtest "resolve() tests" => sub {
118
119
119
    plan tests => 10;
120
    plan tests => 11;
120
121
121
    $schema->storage->txn_begin;
122
    $schema->storage->txn_begin;
122
123
Lines 158-173 subtest "resolve() tests" => sub { Link Here
158
    my $deleted_patron_id = $deleted_patron->id;
159
    my $deleted_patron_id = $deleted_patron->id;
159
    $deleted_patron->delete;
160
    $deleted_patron->delete;
160
161
161
    {    # hide useless warnings
162
    warning_like(
162
        local *STDERR;
163
        sub {
163
        open STDERR, '>', '/dev/null';
164
            throws_ok { $claim->resolve( { resolution => "X", resolved_by => $deleted_patron_id } ) }
164
165
            'Koha::Exceptions::Object::FKConstraint',
165
        throws_ok { $claim->resolve( { resolution => "X", resolved_by => $deleted_patron_id } ) }
166
                "Exception thrown on invalid resolver";
166
        'Koha::Exceptions::Object::FKConstraint',
167
        },
167
            "Exception thrown on invalid resolver";
168
        qr{a foreign key constraint fails}
168
169
    );
169
        close STDERR;
170
    }
171
170
172
    my $today    = dt_from_string;
171
    my $today    = dt_from_string;
173
    my $tomorrow = dt_from_string->add( days => 1 );
172
    my $tomorrow = dt_from_string->add( days => 1 );
(-)a/t/db_dependent/Koha/Object.t (-52 / +58 lines)
Lines 946-952 subtest "Test update method" => sub { Link Here
946
946
947
subtest 'store() tests' => sub {
947
subtest 'store() tests' => sub {
948
948
949
    plan tests => 16;
949
    plan tests => 18;
950
950
951
    # Using Koha::Library::Groups to test Koha::Object>-store
951
    # Using Koha::Library::Groups to test Koha::Object>-store
952
    # Simple object with foreign keys and unique key
952
    # Simple object with foreign keys and unique key
Lines 966-1014 subtest 'store() tests' => sub { Link Here
966
    );
966
    );
967
967
968
    my $dbh = $schema->storage->dbh;
968
    my $dbh = $schema->storage->dbh;
969
    {
969
    warning_like(
970
        local *STDERR;
970
        sub {
971
        open STDERR, '>', '/dev/null';
971
            throws_ok { $library_group->store }
972
        throws_ok { $library_group->store }
972
            'Koha::Exceptions::Object::FKConstraint',
973
        'Koha::Exceptions::Object::FKConstraint',
973
                'Exception is thrown correctly';
974
            'Exception is thrown correctly';
974
        },
975
        is(
975
        qr{a foreign key constraint fails}
976
            $@->message,
976
    );
977
            "Broken FK constraint",
977
    is(
978
            'Exception message is correct'
978
        $@->message,
979
        );
979
        "Broken FK constraint",
980
        is(
980
        'Exception message is correct'
981
            $@->broken_fk,
981
    );
982
            'branchcode',
982
    is(
983
            'Exception field is correct'
983
        $@->broken_fk,
984
        );
984
        'branchcode',
985
985
        'Exception field is correct'
986
        $library_group = $builder->build_object( { class => 'Koha::Library::Groups' } );
986
    );
987
987
988
        my $new_library_group = Koha::Library::Group->new(
988
    $library_group = $builder->build_object( { class => 'Koha::Library::Groups' } );
989
            {
990
                branchcode => $library_group->branchcode,
991
                title      => $library_group->title,
992
            }
993
        );
994
989
995
        throws_ok { $new_library_group->store }
990
    my $new_library_group = Koha::Library::Group->new(
996
        'Koha::Exceptions::Object::DuplicateID',
991
        {
997
            'Exception is thrown correctly';
992
            branchcode => $library_group->branchcode,
993
            title      => $library_group->title,
994
        }
995
    );
998
996
999
        is(
997
    warning_like(
1000
            $@->message,
998
        sub {
1001
            'Duplicate ID',
999
            throws_ok { $new_library_group->store }
1002
            'Exception message is correct'
1000
            'Koha::Exceptions::Object::DuplicateID',
1003
        );
1001
                'Exception is thrown correctly';
1002
        },
1003
        qr{Duplicate entry.* for key 'title'}
1004
    );
1004
1005
1005
        like(
1006
    is(
1006
            $@->duplicate_id,
1007
        $@->message,
1007
            qr/(library_groups\.)?title/,
1008
        'Duplicate ID',
1008
            'Exception field is correct (note that MySQL 8 is displaying the tablename)'
1009
        'Exception message is correct'
1009
        );
1010
    );
1010
        close STDERR;
1011
    like(
1011
    }
1012
        $@->duplicate_id,
1013
        qr/(library_groups\.)?title/,
1014
        'Exception field is correct (note that MySQL 8 is displaying the tablename)'
1015
    );
1012
1016
1013
    # Successful test
1017
    # Successful test
1014
    $library_group->set( { title => 'Manuel' } );
1018
    $library_group->set( { title => 'Manuel' } );
Lines 1065-1085 subtest 'store() tests' => sub { Link Here
1065
1069
1066
    subtest 'Bad value tests' => sub {
1070
    subtest 'Bad value tests' => sub {
1067
1071
1068
        plan tests => 3;
1072
        plan tests => 4;
1069
1073
1070
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
1074
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
1071
1075
1072
        try {
1076
        warning_like(
1073
            local *STDERR;
1077
            sub {
1074
            open STDERR, '>', '/dev/null';
1078
                try {
1075
            $patron->lastseen('wrong_value')->store;
1079
                    $patron->lastseen('wrong_value')->store;
1076
            close STDERR;
1080
                } catch {
1077
        } catch {
1081
                    ok( $_->isa('Koha::Exceptions::Object::BadValue'), 'Exception thrown correctly' );
1078
            ok( $_->isa('Koha::Exceptions::Object::BadValue'), 'Exception thrown correctly' );
1082
                    like( $_->property, qr/(borrowers\.)?lastseen/, 'Column should be the expected one' )
1079
            like( $_->property, qr/(borrowers\.)?lastseen/, 'Column should be the expected one' )
1083
                        ;    # The table name is not always displayed, it depends on the DBMS version
1080
                ;    # The table name is not always displayed, it depends on the DBMS version
1084
                    is( $_->value, 'wrong_value', 'Value should be the expected one' );
1081
            is( $_->value, 'wrong_value', 'Value should be the expected one' );
1085
                };
1082
        };
1086
            },
1087
            qr{Incorrect datetime value: 'wrong_value' for column .*lastseen}
1088
        );
1083
    };
1089
    };
1084
1090
1085
    $schema->storage->txn_rollback;
1091
    $schema->storage->txn_rollback;
(-)a/t/db_dependent/Koha/Patron.t (-11 / +11 lines)
Lines 370-376 subtest 'is_active' => sub { Link Here
370
370
371
subtest 'add_guarantor() tests' => sub {
371
subtest 'add_guarantor() tests' => sub {
372
372
373
    plan tests => 6;
373
    plan tests => 7;
374
374
375
    $schema->storage->txn_begin;
375
    $schema->storage->txn_begin;
376
376
Lines 397-412 subtest 'add_guarantor() tests' => sub { Link Here
397
397
398
    is( $guarantors->count, 1, 'No guarantors added' );
398
    is( $guarantors->count, 1, 'No guarantors added' );
399
399
400
    {
400
    warning_like(
401
        local *STDERR;
401
        sub {
402
        open STDERR, '>', '/dev/null';
402
            throws_ok {
403
        throws_ok {
403
                $patron_1->add_guarantor( { guarantor_id => $patron_2->borrowernumber, relationship => 'father2' } );
404
            $patron_1->add_guarantor( { guarantor_id => $patron_2->borrowernumber, relationship => 'father2' } );
404
            }
405
        }
405
            'Koha::Exceptions::Patron::Relationship::DuplicateRelationship',
406
        'Koha::Exceptions::Patron::Relationship::DuplicateRelationship',
406
                'Exception is thrown for duplicated relationship';
407
            'Exception is thrown for duplicated relationship';
407
        },
408
        close STDERR;
408
        qr{Duplicate entry.* for key 'guarantor_guarantee_idx'}
409
    }
409
    );
410
410
411
    $schema->storage->txn_rollback;
411
    $schema->storage->txn_rollback;
412
};
412
};
(-)a/t/db_dependent/Koha/Patron/Relationship.t (-18 / +20 lines)
Lines 22-27 use Modern::Perl; Link Here
22
use Test::NoWarnings;
22
use Test::NoWarnings;
23
use Test::More tests => 2;
23
use Test::More tests => 2;
24
use Test::Exception;
24
use Test::Exception;
25
use Test::Warn;
25
26
26
use Koha::Database;
27
use Koha::Database;
27
use Koha::Patrons;
28
use Koha::Patrons;
Lines 36-42 my $builder = t::lib::TestBuilder->new; Link Here
36
37
37
subtest 'store() tests' => sub {
38
subtest 'store() tests' => sub {
38
39
39
    plan tests => 13;
40
    plan tests => 14;
40
41
41
    $schema->storage->txn_begin;
42
    $schema->storage->txn_begin;
42
43
Lines 110-132 subtest 'store() tests' => sub { Link Here
110
        }
111
        }
111
    );
112
    );
112
113
113
    {
114
    warning_like(
114
        local *STDERR;
115
        sub {
115
        open STDERR, '>', '/dev/null';
116
            throws_ok { $relationship_2->store; }
116
        throws_ok { $relationship_2->store; }
117
            'Koha::Exceptions::Patron::Relationship::DuplicateRelationship',
117
        'Koha::Exceptions::Patron::Relationship::DuplicateRelationship',
118
                'Exception is thrown for duplicated relationship';
118
            'Exception is thrown for duplicated relationship';
119
        },
119
120
        qr{Duplicate entry.* for key 'guarantor_guarantee_idx'}
120
        is(
121
    );
121
            "$@",
122
122
            "There already exists a relationship for the same guarantor ("
123
    is(
123
                . $patron_2->borrowernumber
124
        "$@",
124
                . ") and guarantee ("
125
        "There already exists a relationship for the same guarantor ("
125
                . $patron_1->borrowernumber
126
            . $patron_2->borrowernumber
126
                . ") combination",
127
            . ") and guarantee ("
127
            'Exception stringified correctly'
128
            . $patron_1->borrowernumber
128
        );
129
            . ") combination",
129
    }
130
        'Exception stringified correctly'
131
    );
130
132
131
    t::lib::Mocks::mock_preference( 'borrowerRelationship', '' );
133
    t::lib::Mocks::mock_preference( 'borrowerRelationship', '' );
132
134
(-)a/t/db_dependent/Koha/Suggestions.t (-44 / +40 lines)
Lines 22-27 use Modern::Perl; Link Here
22
use Test::NoWarnings;
22
use Test::NoWarnings;
23
use Test::More tests => 12;
23
use Test::More tests => 12;
24
use Test::Exception;
24
use Test::Exception;
25
use Test::Warn;
25
26
26
use Koha::Suggestions;
27
use Koha::Suggestions;
27
use Koha::Notice::Messages;
28
use Koha::Notice::Messages;
Lines 142-153 is( Koha::Suggestions->search->count, $nb_of_suggestions + 1, 'Delete should hav Link Here
142
$schema->storage->txn_rollback;
143
$schema->storage->txn_rollback;
143
144
144
subtest 'constraints' => sub {
145
subtest 'constraints' => sub {
145
    plan tests => 11;
146
    plan tests => 15;
146
    $schema->storage->txn_begin;
147
    $schema->storage->txn_begin;
147
148
148
    my $print_error = $schema->storage->dbh->{PrintError};
149
    $schema->storage->dbh->{PrintError} = 0;
150
151
    my $patron = $builder->build_object( { class => "Koha::Patrons" } );
149
    my $patron = $builder->build_object( { class => "Koha::Patrons" } );
152
    my $biblio = $builder->build_sample_biblio();
150
    my $biblio = $builder->build_sample_biblio();
153
    my $branch = $builder->build_object( { class => "Koha::Libraries" } );
151
    my $branch = $builder->build_object( { class => "Koha::Libraries" } );
Lines 194-209 subtest 'constraints' => sub { Link Here
194
    );
192
    );
195
193
196
    # managerid
194
    # managerid
197
    {    # hide useless warnings
195
    warning_like(
198
        local *STDERR;
196
        sub {
199
        open STDERR, '>', '/dev/null';
197
            throws_ok {
200
        throws_ok {
198
                $suggestion->managedby($nonexistent_borrowernumber)->store;
201
            $suggestion->managedby($nonexistent_borrowernumber)->store;
199
            }
202
        }
200
            'Koha::Exceptions::Object::FKConstraint',
203
        'Koha::Exceptions::Object::FKConstraint',
201
                'store raises an exception on invalid managerid';
204
            'store raises an exception on invalid managerid';
202
        },
205
        close STDERR;
203
        qr{a foreign key constraint fails}
206
    }
204
    );
207
    my $manager = $builder->build_object( { class => "Koha::Patrons" } );
205
    my $manager = $builder->build_object( { class => "Koha::Patrons" } );
208
    $suggestion->managedby( $manager->borrowernumber )->store;
206
    $suggestion->managedby( $manager->borrowernumber )->store;
209
    $manager->delete;
207
    $manager->delete;
Lines 214-229 subtest 'constraints' => sub { Link Here
214
    );
212
    );
215
213
216
    # acceptedby
214
    # acceptedby
217
    {    # hide useless warnings
215
    warning_like(
218
        local *STDERR;
216
        sub {
219
        open STDERR, '>', '/dev/null';
217
            throws_ok {
220
        throws_ok {
218
                $suggestion->acceptedby($nonexistent_borrowernumber)->store;
221
            $suggestion->acceptedby($nonexistent_borrowernumber)->store;
219
            }
222
        }
220
            'Koha::Exceptions::Object::FKConstraint',
223
        'Koha::Exceptions::Object::FKConstraint',
221
                'store raises an exception on invalid acceptedby id';
224
            'store raises an exception on invalid acceptedby id';
222
        },
225
        close STDERR;
223
        qr{a foreign key constraint fails}
226
    }
224
    );
227
    my $acceptor = $builder->build_object( { class => "Koha::Patrons" } );
225
    my $acceptor = $builder->build_object( { class => "Koha::Patrons" } );
228
    $suggestion->acceptedby( $acceptor->borrowernumber )->store;
226
    $suggestion->acceptedby( $acceptor->borrowernumber )->store;
229
    $acceptor->delete;
227
    $acceptor->delete;
Lines 234-249 subtest 'constraints' => sub { Link Here
234
    );
232
    );
235
233
236
    # rejectedby
234
    # rejectedby
237
    {    # hide useless warnings
235
    warning_like(
238
        local *STDERR;
236
        sub {
239
        open STDERR, '>', '/dev/null';
237
            throws_ok {
240
        throws_ok {
238
                $suggestion->rejectedby($nonexistent_borrowernumber)->store;
241
            $suggestion->rejectedby($nonexistent_borrowernumber)->store;
239
            }
242
        }
240
            'Koha::Exceptions::Object::FKConstraint',
243
        'Koha::Exceptions::Object::FKConstraint',
241
                'store raises an exception on invalid rejectedby id';
244
            'store raises an exception on invalid rejectedby id';
242
        },
245
        close STDERR;
243
        qr{a foreign key constraint fails}
246
    }
244
    );
247
    my $rejecter = $builder->build_object( { class => "Koha::Patrons" } );
245
    my $rejecter = $builder->build_object( { class => "Koha::Patrons" } );
248
    $suggestion->rejectedby( $rejecter->borrowernumber )->store;
246
    $suggestion->rejectedby( $rejecter->borrowernumber )->store;
249
    $rejecter->delete;
247
    $rejecter->delete;
Lines 254-268 subtest 'constraints' => sub { Link Here
254
    );
252
    );
255
253
256
    # budgetid
254
    # budgetid
257
    {    # hide useless warnings
255
    warning_like(
258
        local *STDERR;
256
        sub {
259
        open STDERR, '>', '/dev/null';
257
            throws_ok { $suggestion->budgetid($nonexistent_borrowernumber)->store; }
260
258
            'Koha::Exceptions::Object::FKConstraint',
261
        throws_ok { $suggestion->budgetid($nonexistent_borrowernumber)->store; }
259
                'store raises an exception on invalid budgetid';
262
        'Koha::Exceptions::Object::FKConstraint',
260
        },
263
            'store raises an exception on invalid budgetid';
261
        qr{a foreign key constraint fails}
264
        close STDERR;
262
    );
265
    }
266
    my $fund = $builder->build_object( { class => "Koha::Acquisition::Funds" } );
263
    my $fund = $builder->build_object( { class => "Koha::Acquisition::Funds" } );
267
    $suggestion->budgetid( $fund->id )->store;
264
    $suggestion->budgetid( $fund->id )->store;
268
    $fund->delete;
265
    $fund->delete;
Lines 272-278 subtest 'constraints' => sub { Link Here
272
        "The suggestion is not deleted when the related budget is deleted"
269
        "The suggestion is not deleted when the related budget is deleted"
273
    );
270
    );
274
271
275
    $schema->storage->dbh->{PrintError} = $print_error;
276
    $schema->storage->txn_rollback;
272
    $schema->storage->txn_rollback;
277
};
273
};
278
274
(-)a/t/db_dependent/Suggestions.t (-13 / +10 lines)
Lines 19-25 use Modern::Perl; Link Here
19
19
20
use DateTime::Duration;
20
use DateTime::Duration;
21
use Test::NoWarnings;
21
use Test::NoWarnings;
22
use Test::More tests => 95;
22
use Test::More tests => 96;
23
use Test::Warn;
23
use Test::Warn;
24
24
25
use t::lib::Mocks;
25
use t::lib::Mocks;
Lines 300-318 $status = ModSuggestion($mod_suggestion5); Link Here
300
$messages = C4::Letters::GetQueuedMessages( { borrowernumber => $borrowernumber } );
300
$messages = C4::Letters::GetQueuedMessages( { borrowernumber => $borrowernumber } );
301
is( @$messages, 3, 'ModSuggestions does send a message if the status has been changed' );
301
is( @$messages, 3, 'ModSuggestions does send a message if the status has been changed' );
302
302
303
{
303
$mod_suggestion4->{manageddate} = 'invalid date!';
304
    # Hiding the expected warning displayed by DBI
304
warning_like(
305
    # DBD::mysql::st execute failed: Incorrect date value: 'invalid date!' for column 'manageddate'
305
    sub {
306
    local *STDERR;
306
        ModSuggestion($mod_suggestion4);
307
    open STDERR, '>', '/dev/null';
307
    },
308
308
    qr{Incorrect date value: 'invalid date!' for column .*manageddate}
309
    $mod_suggestion4->{manageddate} = 'invalid date!';
309
);
310
    ModSuggestion($mod_suggestion4);
310
$messages = C4::Letters::GetQueuedMessages( { borrowernumber => $borrowernumber2 } );
311
    $messages = C4::Letters::GetQueuedMessages( { borrowernumber => $borrowernumber2 } );
312
311
313
    close STDERR;
312
is( scalar(@$messages), 1, 'No new letter should have been generated if the update raised an error' );
314
    is( scalar(@$messages), 1, 'No new letter should have been generated if the update raised an error' );
315
}
316
313
317
is( GetSuggestionInfo(), undef, 'GetSuggestionInfo without the suggestion id returns undef' );
314
is( GetSuggestionInfo(), undef, 'GetSuggestionInfo without the suggestion id returns undef' );
318
$suggestion = GetSuggestionInfo($my_suggestionid);
315
$suggestion = GetSuggestionInfo($my_suggestionid);
(-)a/t/db_dependent/api/v1/item_groups.t (-7 / +1 lines)
Lines 119-131 subtest 'add() tests' => sub { Link Here
119
        ->status_is( 201, 'REST3.2.1' );
119
        ->status_is( 201, 'REST3.2.1' );
120
120
121
    # Invalid biblio id
121
    # Invalid biblio id
122
    {    # hide useless warnings
122
    $t->post_ok( "//$auth_userid:$password@/api/v1/biblios/XXX/item_groups" => json => $item_group )->status_is(404);
123
        local *STDERR;
124
        open STDERR, '>', '/dev/null';
125
        $t->post_ok( "//$auth_userid:$password@/api/v1/biblios/XXX/item_groups" => json => $item_group )
126
            ->status_is(404);
127
        close STDERR;
128
    }
129
123
130
    $schema->storage->txn_rollback;
124
    $schema->storage->txn_rollback;
131
};
125
};
(-)a/t/db_dependent/selenium/01-installation.t (-2 lines)
Lines 22-28 Link Here
22
22
23
use Modern::Perl;
23
use Modern::Perl;
24
24
25
use Test::NoWarnings;
26
use Test::More tests => 3;
25
use Test::More tests => 3;
27
26
28
use t::lib::Selenium;
27
use t::lib::Selenium;
29
- 

Return to bug 38944