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

(-)a/t/db_dependent/Circulation/MarkIssueReturned.t (-11 / +12 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 128-134 subtest 'Anonymous patron tests' => sub { Link Here
128
129
129
subtest 'Manually pass a return date' => sub {
130
subtest 'Manually pass a return date' => sub {
130
131
131
    plan tests => 3;
132
    plan tests => 4;
132
133
133
    $schema->storage->txn_begin;
134
    $schema->storage->txn_begin;
134
135
Lines 158-174 subtest 'Manually pass a return date' => sub { Link Here
158
159
159
    $issue = C4::Circulation::AddIssue( $patron, $item->barcode );
160
    $issue = C4::Circulation::AddIssue( $patron, $item->barcode );
160
161
161
    {
162
    warning_like(
162
        # Hiding the expected warning displayed by DBI
163
        sub {
163
        # DBD::mysql::st execute failed: Incorrect datetime value: 'bad_date' for column 'returndate'
164
            throws_ok {
164
        local *STDERR;
165
                $issue_id =
165
        open STDERR, '>', '/dev/null';
166
                    C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, 'bad_date', 0 );
166
        throws_ok
167
            }
167
            { $issue_id = C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, 'bad_date', 0 ); }
168
            'Koha::Exceptions::Object::BadValue',
168
            'Koha::Exceptions::Object::BadValue',
169
            'An exception is thrown on bad date';
169
                'An exception is thrown on bad date';
170
        close STDERR;
170
        },
171
    }
171
        qr{Incorrect datetime value: 'bad_date' for column .*returndate}
172
    );
172
173
173
    $schema->storage->txn_rollback;
174
    $schema->storage->txn_rollback;
174
};
175
};
(-)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 326-332 subtest 'add_credit() tests' => sub { Link Here
326
327
327
subtest 'add_debit() tests' => sub {
328
subtest 'add_debit() tests' => sub {
328
329
329
    plan tests => 14;
330
    plan tests => 15;
330
331
331
    $schema->storage->txn_begin;
332
    $schema->storage->txn_begin;
332
333
Lines 353-376 subtest 'add_debit() tests' => sub { Link Here
353
        }
354
        }
354
    ); } 'Koha::Exceptions::Account::AmountNotPositive', 'Expected validation exception thrown (amount)';
355
    ); } 'Koha::Exceptions::Account::AmountNotPositive', 'Expected validation exception thrown (amount)';
355
356
356
    throws_ok {
357
    warning_like(
357
        local *STDERR;
358
        sub {
358
        open STDERR, '>', '/dev/null';
359
            throws_ok {
359
        $account->add_debit(
360
                $account->add_debit(
360
            {
361
                    {
361
                amount      => 5,
362
                        amount      => 5,
362
                description => 'type validation failure',
363
                        description => 'type validation failure',
363
                library_id  => $patron->branchcode,
364
                        library_id  => $patron->branchcode,
364
                note        => 'this should fail anyway',
365
                        note        => 'this should fail anyway',
365
                type        => 'failure',
366
                        type        => 'failure',
366
                user_id     => $patron->id,
367
                        user_id     => $patron->id,
367
                interface   => 'commandline'
368
                        interface   => 'commandline'
369
                    }
370
                );
368
            }
371
            }
369
        );
372
            'Koha::Exceptions::Account::UnrecognisedType',
370
        close STDERR;
373
                'Expected validation exception thrown (type)';
371
    }
374
        },
372
    'Koha::Exceptions::Account::UnrecognisedType',
375
        qr{a foreign key constraint fails}
373
      'Expected validation exception thrown (type)';
376
    );
374
377
375
    throws_ok {
378
    throws_ok {
376
    $account->add_debit(
379
    $account->add_debit(
(-)a/t/db_dependent/Koha/ApiKey.t (-13 / +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 98-115 subtest 'store() tests' => sub { Link Here
98
    my $deleted_id = $patron_to_delete->id;
99
    my $deleted_id = $patron_to_delete->id;
99
    $patron_to_delete->delete;
100
    $patron_to_delete->delete;
100
101
101
    {    # hide useless warnings
102
    warning_like(
102
        local *STDERR;
103
        sub {
103
        open STDERR, '>', '/dev/null';
104
            throws_ok {
104
        throws_ok {
105
                Koha::ApiKey->new( { patron_id => $deleted_id, description => 'a description' } )->store
105
            Koha::ApiKey->new(
106
            }
106
                { patron_id => $deleted_id, description => 'a description' } )
107
            'Koha::Exceptions::Object::FKConstraint',
107
              ->store
108
                'Invalid patron ID raises exception';
108
        }
109
        },
109
        'Koha::Exceptions::Object::FKConstraint',
110
        qr{a foreign key constraint fails}
110
          'Invalid patron ID raises exception';
111
    );
111
        close STDERR;
112
    }
113
    is( $@->message,   'Broken FK constraint', 'Exception message is correct' );
112
    is( $@->message,   'Broken FK constraint', 'Exception message is correct' );
114
    is( $@->broken_fk, 'patron_id',            'Exception field is correct' );
113
    is( $@->broken_fk, 'patron_id',            'Exception field is correct' );
115
114
(-)a/t/db_dependent/Koha/Checkouts/Renewal.t (-23 / +14 lines)
Lines 85-115 subtest "store() tests" => sub { Link Here
85
        'Renewal stored on the DB'
85
        'Renewal stored on the DB'
86
    );
86
    );
87
87
88
    {    # hide useless warnings
88
    my $another_checkout = $builder->build_object( { class => 'Koha::Checkouts' } );
89
        local *STDERR;
89
    my $checkout_id      = $another_checkout->id;
90
        open STDERR, '>', '/dev/null';
90
    $another_checkout->delete;
91
92
        my $another_checkout =
93
          $builder->build_object( { class => 'Koha::Checkouts' } );
94
        my $checkout_id = $another_checkout->id;
95
        $another_checkout->delete;
96
97
        my $THE_renewal;
98
99
        throws_ok {
100
            $THE_renewal = Koha::Checkouts::Renewal->new(
101
                {
102
                    checkout_id => $checkout_id,
103
                    interface   => 'intranet'
104
                }
105
            )->store;
106
        }
107
        'Koha::Exceptions::Object::FKConstraint',
108
          'An exception is thrown on invalid checkout_id';
109
        close STDERR;
110
91
111
        is( $@->broken_fk, 'checkout_id', 'Exception field is correct' );
92
    throws_ok {
93
        Koha::Checkouts::Renewal->new(
94
            {
95
                checkout_id => $checkout_id,
96
                interface   => 'intranet'
97
            }
98
        )->store;
112
    }
99
    }
100
    'Koha::Exceptions::Object::FKConstraint',
101
        'An exception is thrown on invalid checkout_id';
102
103
    is( $@->broken_fk, 'checkout_id', 'Exception field is correct' );
113
104
114
    $schema->storage->txn_rollback;
105
    $schema->storage->txn_rollback;
115
};
106
};
(-)a/t/db_dependent/Koha/Checkouts/ReturnClaim.t (-8 / +4 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 115-121 subtest "store() tests" => sub { Link Here
115
116
116
subtest "resolve() tests" => sub {
117
subtest "resolve() tests" => sub {
117
118
118
    plan tests => 10;
119
    plan tests => 11;
119
120
120
    $schema->storage->txn_begin;
121
    $schema->storage->txn_begin;
121
122
Lines 159-175 subtest "resolve() tests" => sub { Link Here
159
    my $deleted_patron_id = $deleted_patron->id;
160
    my $deleted_patron_id = $deleted_patron->id;
160
    $deleted_patron->delete;
161
    $deleted_patron->delete;
161
162
162
    {   # hide useless warnings
163
    warning_like(sub{
163
        local *STDERR;
164
        open STDERR, '>', '/dev/null';
165
166
        throws_ok
164
        throws_ok
167
            { $claim->resolve({ resolution => "X", resolved_by => $deleted_patron_id }) }
165
            { $claim->resolve({ resolution => "X", resolved_by => $deleted_patron_id }) }
168
            'Koha::Exceptions::Object::FKConstraint',
166
            'Koha::Exceptions::Object::FKConstraint',
169
            "Exception thrown on invalid resolver";
167
            "Exception thrown on invalid resolver";
170
168
    }, qr{a foreign key constraint fails});
171
        close STDERR;
172
    }
173
169
174
    my $today    = dt_from_string;
170
    my $today    = dt_from_string;
175
    my $tomorrow = dt_from_string->add( days => 1 );
171
    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 (-9 / +10 lines)
Lines 368-374 subtest 'is_active' => sub { Link Here
368
368
369
subtest 'add_guarantor() tests' => sub {
369
subtest 'add_guarantor() tests' => sub {
370
370
371
    plan tests => 6;
371
    plan tests => 7;
372
372
373
    $schema->storage->txn_begin;
373
    $schema->storage->txn_begin;
374
374
Lines 397-411 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
            'Koha::Exceptions::Patron::Relationship::DuplicateRelationship',
405
            'Koha::Exceptions::Patron::Relationship::DuplicateRelationship',
406
            'Exception is thrown for duplicated relationship';
406
                'Exception is thrown for duplicated relationship';
407
        close STDERR;
407
        },
408
    }
408
        qr{Duplicate entry.* for key 'guarantor_guarantee_idx'}
409
    );
409
410
410
    $schema->storage->txn_rollback;
411
    $schema->storage->txn_rollback;
411
};
412
};
(-)a/t/db_dependent/Koha/Patron/Relationship.t (-17 / +19 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 107-129 subtest 'store() tests' => sub { Link Here
107
        }
108
        }
108
    );
109
    );
109
110
110
    {
111
    warning_like(
111
        local *STDERR;
112
        sub {
112
        open STDERR, '>', '/dev/null';
113
            throws_ok { $relationship_2->store; }
113
        throws_ok
114
            { $relationship_2->store; }
115
            'Koha::Exceptions::Patron::Relationship::DuplicateRelationship',
114
            'Koha::Exceptions::Patron::Relationship::DuplicateRelationship',
116
            'Exception is thrown for duplicated relationship';
115
                'Exception is thrown for duplicated relationship';
117
116
        },
118
        is( "$@",
117
        qr{Duplicate entry.* for key 'guarantor_guarantee_idx'}
119
            "There already exists a relationship for the same guarantor ("
118
    );
120
                . $patron_2->borrowernumber
119
121
                . ") and guarantee ("
120
    is(
122
                . $patron_1->borrowernumber
121
        "$@",
123
                . ") combination",
122
        "There already exists a relationship for the same guarantor ("
124
            'Exception stringified correctly'
123
            . $patron_2->borrowernumber
125
        );
124
            . ") and guarantee ("
126
    }
125
            . $patron_1->borrowernumber
126
            . ") combination",
127
        'Exception stringified correctly'
128
    );
127
129
128
    t::lib::Mocks::mock_preference( 'borrowerRelationship', '' );
130
    t::lib::Mocks::mock_preference( 'borrowerRelationship', '' );
129
131
(-)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 133-144 is( Koha::Suggestions->search->count, $nb_of_suggestions + 1, 'Delete should hav Link Here
133
$schema->storage->txn_rollback;
134
$schema->storage->txn_rollback;
134
135
135
subtest 'constraints' => sub {
136
subtest 'constraints' => sub {
136
    plan tests => 11;
137
    plan tests => 15;
137
    $schema->storage->txn_begin;
138
    $schema->storage->txn_begin;
138
139
139
    my $print_error = $schema->storage->dbh->{PrintError};
140
    $schema->storage->dbh->{PrintError} = 0;
141
142
    my $patron = $builder->build_object( { class => "Koha::Patrons" } );
140
    my $patron = $builder->build_object( { class => "Koha::Patrons" } );
143
    my $biblio = $builder->build_sample_biblio();
141
    my $biblio = $builder->build_sample_biblio();
144
    my $branch = $builder->build_object( { class => "Koha::Libraries" } );
142
    my $branch = $builder->build_object( { class => "Koha::Libraries" } );
Lines 178-193 subtest 'constraints' => sub { Link Here
178
        "The suggestion is not deleted when the related branch is deleted" );
176
        "The suggestion is not deleted when the related branch is deleted" );
179
177
180
    # managerid
178
    # managerid
181
    {   # hide useless warnings
179
    warning_like(
182
        local *STDERR;
180
        sub {
183
        open STDERR, '>', '/dev/null';
181
            throws_ok {
184
        throws_ok {
182
                $suggestion->managedby($nonexistent_borrowernumber)->store;
185
            $suggestion->managedby($nonexistent_borrowernumber)->store;
183
            }
186
        }
184
            'Koha::Exceptions::Object::FKConstraint',
187
        'Koha::Exceptions::Object::FKConstraint',
185
                'store raises an exception on invalid managerid';
188
          'store raises an exception on invalid managerid';
186
        },
189
        close STDERR;
187
        qr{a foreign key constraint fails}
190
    }
188
    );
191
    my $manager = $builder->build_object( { class => "Koha::Patrons" } );
189
    my $manager = $builder->build_object( { class => "Koha::Patrons" } );
192
    $suggestion->managedby( $manager->borrowernumber )->store;
190
    $suggestion->managedby( $manager->borrowernumber )->store;
193
    $manager->delete;
191
    $manager->delete;
Lines 196-211 subtest 'constraints' => sub { Link Here
196
        "The suggestion is not deleted when the related manager is deleted" );
194
        "The suggestion is not deleted when the related manager is deleted" );
197
195
198
    # acceptedby
196
    # acceptedby
199
    {    # hide useless warnings
197
    warning_like(
200
        local *STDERR;
198
        sub {
201
        open STDERR, '>', '/dev/null';
199
            throws_ok {
202
        throws_ok {
200
                $suggestion->acceptedby($nonexistent_borrowernumber)->store;
203
            $suggestion->acceptedby($nonexistent_borrowernumber)->store;
201
            }
204
        }
202
            'Koha::Exceptions::Object::FKConstraint',
205
        'Koha::Exceptions::Object::FKConstraint',
203
                'store raises an exception on invalid acceptedby id';
206
          'store raises an exception on invalid acceptedby id';
204
        },
207
        close STDERR;
205
        qr{a foreign key constraint fails}
208
    }
206
    );
209
    my $acceptor = $builder->build_object( { class => "Koha::Patrons" } );
207
    my $acceptor = $builder->build_object( { class => "Koha::Patrons" } );
210
    $suggestion->acceptedby( $acceptor->borrowernumber )->store;
208
    $suggestion->acceptedby( $acceptor->borrowernumber )->store;
211
    $acceptor->delete;
209
    $acceptor->delete;
Lines 214-229 subtest 'constraints' => sub { Link Here
214
        "The suggestion is not deleted when the related acceptor is deleted" );
212
        "The suggestion is not deleted when the related acceptor is deleted" );
215
213
216
    # rejectedby
214
    # rejectedby
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->rejectedby($nonexistent_borrowernumber)->store;
221
            $suggestion->rejectedby($nonexistent_borrowernumber)->store;
219
            }
222
        }
220
            'Koha::Exceptions::Object::FKConstraint',
223
        'Koha::Exceptions::Object::FKConstraint',
221
                'store raises an exception on invalid rejectedby id';
224
          'store raises an exception on invalid rejectedby id';
222
        },
225
        close STDERR;
223
        qr{a foreign key constraint fails}
226
    }
224
    );
227
    my $rejecter = $builder->build_object( { class => "Koha::Patrons" } );
225
    my $rejecter = $builder->build_object( { class => "Koha::Patrons" } );
228
    $suggestion->rejectedby( $rejecter->borrowernumber )->store;
226
    $suggestion->rejectedby( $rejecter->borrowernumber )->store;
229
    $rejecter->delete;
227
    $rejecter->delete;
Lines 232-246 subtest 'constraints' => sub { Link Here
232
        "The suggestion is not deleted when the related rejecter is deleted" );
230
        "The suggestion is not deleted when the related rejecter is deleted" );
233
231
234
    # budgetid
232
    # budgetid
235
    {    # hide useless warnings
233
    warning_like(
236
        local *STDERR;
234
        sub {
237
        open STDERR, '>', '/dev/null';
235
            throws_ok { $suggestion->budgetid($nonexistent_borrowernumber)->store; }
238
236
            'Koha::Exceptions::Object::FKConstraint',
239
        throws_ok { $suggestion->budgetid($nonexistent_borrowernumber)->store; }
237
                'store raises an exception on invalid budgetid';
240
        'Koha::Exceptions::Object::FKConstraint',
238
        },
241
          'store raises an exception on invalid budgetid';
239
        qr{a foreign key constraint fails}
242
        close STDERR;
240
    );
243
    }
244
    my $fund = $builder->build_object( { class => "Koha::Acquisition::Funds" } );
241
    my $fund = $builder->build_object( { class => "Koha::Acquisition::Funds" } );
245
    $suggestion->budgetid( $fund->id )->store;
242
    $suggestion->budgetid( $fund->id )->store;
246
    $fund->delete;
243
    $fund->delete;
Lines 248-254 subtest 'constraints' => sub { Link Here
248
    is( $suggestion->budgetid, undef,
245
    is( $suggestion->budgetid, undef,
249
        "The suggestion is not deleted when the related budget is deleted" );
246
        "The suggestion is not deleted when the related budget is deleted" );
250
247
251
    $schema->storage->dbh->{PrintError} = $print_error;
252
    $schema->storage->txn_rollback;
248
    $schema->storage->txn_rollback;
253
};
249
};
254
250
(-)a/t/db_dependent/Suggestions.t (-14 / +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 284-304 $status = ModSuggestion($mod_suggestion5); Link Here
284
$messages = C4::Letters::GetQueuedMessages( { borrowernumber => $borrowernumber } );
284
$messages = C4::Letters::GetQueuedMessages( { borrowernumber => $borrowernumber } );
285
is( @$messages, 3, 'ModSuggestions does send a message if the status has been changed' );
285
is( @$messages, 3, 'ModSuggestions does send a message if the status has been changed' );
286
286
287
{
288
    # Hiding the expected warning displayed by DBI
289
    # DBD::mysql::st execute failed: Incorrect date value: 'invalid date!' for column 'manageddate'
290
    local *STDERR;
291
    open STDERR, '>', '/dev/null';
292
287
293
    $mod_suggestion4->{manageddate} = 'invalid date!';
288
$mod_suggestion4->{manageddate} = 'invalid date!';
294
    ModSuggestion($mod_suggestion4);
289
warning_like(
295
    $messages = C4::Letters::GetQueuedMessages({
290
    sub {
296
        borrowernumber => $borrowernumber2
291
        ModSuggestion($mod_suggestion4);
297
    });
292
    },
293
    qr{Incorrect date value: 'invalid date!' for column .*manageddate}
294
);
295
$messages = C4::Letters::GetQueuedMessages( { borrowernumber => $borrowernumber2 } );
298
296
299
    close STDERR;
297
is( scalar(@$messages), 1, 'No new letter should have been generated if the update raised an error' );
300
    is (scalar(@$messages), 1, 'No new letter should have been generated if the update raised an error');
301
}
302
298
303
is( GetSuggestionInfo(), undef, 'GetSuggestionInfo without the suggestion id returns undef' );
299
is( GetSuggestionInfo(), undef, 'GetSuggestionInfo without the suggestion id returns undef' );
304
$suggestion = GetSuggestionInfo($my_suggestionid);
300
$suggestion = GetSuggestionInfo($my_suggestionid);
(-)a/t/db_dependent/api/v1/item_groups.t (-7 / +2 lines)
Lines 112-124 subtest 'add() tests' => sub { Link Here
112
      ->status_is( 201, 'REST3.2.1' );
112
      ->status_is( 201, 'REST3.2.1' );
113
113
114
    # Invalid biblio id
114
    # Invalid biblio id
115
    {   # hide useless warnings
115
    $t->post_ok( "//$auth_userid:$password@/api/v1/biblios/XXX/item_groups" => json => $item_group )
116
        local *STDERR;
116
        ->status_is( 404 );
117
        open STDERR, '>', '/dev/null';
118
        $t->post_ok( "//$auth_userid:$password@/api/v1/biblios/XXX/item_groups" => json => $item_group )
119
            ->status_is( 404 );
120
        close STDERR;
121
    }
122
117
123
    $schema->storage->txn_rollback;
118
    $schema->storage->txn_rollback;
124
};
119
};
(-)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