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

(-)a/t/db_dependent/Koha/Account.t (-11 / +17 lines)
Lines 339-355 subtest 'add_debit() tests' => sub { Link Here
339
    ); } 'Koha::Exceptions::Account::AmountNotPositive', 'Expected validation exception thrown (amount)';
339
    ); } 'Koha::Exceptions::Account::AmountNotPositive', 'Expected validation exception thrown (amount)';
340
340
341
    throws_ok {
341
    throws_ok {
342
    $account->add_debit(
342
        local *STDERR;
343
        {
343
        open STDERR, '>', '/dev/null';
344
            amount      => 5,
344
        $account->add_debit(
345
            description => 'type validation failure',
345
            {
346
            library_id  => $patron->branchcode,
346
                amount      => 5,
347
            note        => 'this should fail anyway',
347
                description => 'type validation failure',
348
            type        => 'failure',
348
                library_id  => $patron->branchcode,
349
            user_id     => $patron->id,
349
                note        => 'this should fail anyway',
350
            interface   => 'commandline'
350
                type        => 'failure',
351
        }
351
                user_id     => $patron->id,
352
    ); } 'Koha::Exceptions::Account::UnrecognisedType', 'Expected validation exception thrown (type)';
352
                interface   => 'commandline'
353
            }
354
        );
355
        close STDERR;
356
    }
357
    'Koha::Exceptions::Account::UnrecognisedType',
358
      'Expected validation exception thrown (type)';
353
359
354
    throws_ok {
360
    throws_ok {
355
    $account->add_debit(
361
    $account->add_debit(
(-)a/t/db_dependent/Koha/ApiKeys.t (-3 / +11 lines)
Lines 79-88 subtest 'store() tests' => sub { Link Here
79
    my $deleted_id = $patron_to_delete->id;
79
    my $deleted_id = $patron_to_delete->id;
80
    $patron_to_delete->delete;
80
    $patron_to_delete->delete;
81
81
82
    throws_ok
82
    {    # hide useless warnings
83
        { Koha::ApiKey->new({ patron_id => $deleted_id, description => 'a description' })->store }
83
        local *STDERR;
84
        open STDERR, '>', '/dev/null';
85
        throws_ok {
86
            Koha::ApiKey->new(
87
                { patron_id => $deleted_id, description => 'a description' } )
88
              ->store
89
        }
84
        'Koha::Exceptions::Object::FKConstraint',
90
        'Koha::Exceptions::Object::FKConstraint',
85
        'Invalid patron ID raises exception';
91
          'Invalid patron ID raises exception';
92
        close STDERR;
93
    }
86
    is( $@->message,   'Broken FK constraint', 'Exception message is correct' );
94
    is( $@->message,   'Broken FK constraint', 'Exception message is correct' );
87
    is( $@->broken_fk, 'patron_id',            'Exception field is correct' );
95
    is( $@->broken_fk, 'patron_id',            'Exception field is correct' );
88
96
(-)a/t/db_dependent/Koha/Object.t (-4 / +7 lines)
Lines 620-627 subtest 'store() tests' => sub { Link Here
620
620
621
    my $dbh = $schema->storage->dbh;
621
    my $dbh = $schema->storage->dbh;
622
    {
622
    {
623
        local $dbh->{PrintError} = 0;
623
        local *STDERR;
624
        local $dbh->{RaiseError} = 0;
624
        open STDERR, '>', '/dev/null';
625
        throws_ok
625
        throws_ok
626
            { $api_key->store }
626
            { $api_key->store }
627
            'Koha::Exceptions::Object::FKConstraint',
627
            'Koha::Exceptions::Object::FKConstraint',
Lines 662-667 subtest 'store() tests' => sub { Link Here
662
           qr/(api_keys\.)?secret/,
662
           qr/(api_keys\.)?secret/,
663
           'Exception field is correct (note that MySQL 8 is displaying the tablename)'
663
           'Exception field is correct (note that MySQL 8 is displaying the tablename)'
664
        );
664
        );
665
        close STDERR;
665
    }
666
    }
666
667
667
    # Successful test
668
    # Successful test
Lines 714-723 subtest 'store() tests' => sub { Link Here
714
715
715
        my $patron = $builder->build_object({ class => 'Koha::Patrons' });
716
        my $patron = $builder->build_object({ class => 'Koha::Patrons' });
716
717
718
717
        try {
719
        try {
718
            local $schema->storage->dbh->{RaiseError} = 0;
720
            local *STDERR;
719
            local $schema->storage->dbh->{PrintError} = 0;
721
            open STDERR, '>', '/dev/null';
720
            $patron->lastseen('wrong_value')->store;
722
            $patron->lastseen('wrong_value')->store;
723
            close STDERR;
721
        } catch {
724
        } catch {
722
            ok( $_->isa('Koha::Exceptions::Object::BadValue'), 'Exception thrown correctly' );
725
            ok( $_->isa('Koha::Exceptions::Object::BadValue'), 'Exception thrown correctly' );
723
            like( $_->property, qr/(borrowers\.)?lastseen/, 'Column should be the expected one' ); # The table name is not always displayed, it depends on the DBMS version
726
            like( $_->property, qr/(borrowers\.)?lastseen/, 'Column should be the expected one' ); # The table name is not always displayed, it depends on the DBMS version
(-)a/t/db_dependent/Koha/Patrons.t (-3 / +7 lines)
Lines 1738-1747 subtest '->store' => sub { Link Here
1738
    my $patron_1 = $builder->build_object({class=> 'Koha::Patrons'});
1738
    my $patron_1 = $builder->build_object({class=> 'Koha::Patrons'});
1739
    my $patron_2 = $builder->build_object({class=> 'Koha::Patrons'});
1739
    my $patron_2 = $builder->build_object({class=> 'Koha::Patrons'});
1740
1740
1741
    throws_ok
1741
    {
1742
        { $patron_2->userid($patron_1->userid)->store; }
1742
        local *STDERR;
1743
        open STDERR, '>', '/dev/null';
1744
        throws_ok { $patron_2->userid( $patron_1->userid )->store; }
1743
        'Koha::Exceptions::Object::DuplicateID',
1745
        'Koha::Exceptions::Object::DuplicateID',
1744
        'Koha::Patron->store raises an exception on duplicate ID';
1746
          'Koha::Patron->store raises an exception on duplicate ID';
1747
        close STDERR;
1748
    }
1745
1749
1746
    # Test password
1750
    # Test password
1747
    t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 );
1751
    t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 );
(-)a/t/db_dependent/Koha/Suggestions.t (-13 / +39 lines)
Lines 125-133 subtest 'constraints' => sub { Link Here
125
        "The suggestion is not deleted when the related branch is deleted" );
125
        "The suggestion is not deleted when the related branch is deleted" );
126
126
127
    # managerid
127
    # managerid
128
    throws_ok { $suggestion->managedby($nonexistent_borrowernumber)->store; }
128
    {   # hide useless warnings
129
    'Koha::Exceptions::Object::FKConstraint',
129
        local *STDERR;
130
      'store raises an exception on invalid managerid';
130
        open STDERR, '>', '/dev/null';
131
        throws_ok {
132
            $suggestion->managedby($nonexistent_borrowernumber)->store;
133
        }
134
        'Koha::Exceptions::Object::FKConstraint',
135
          'store raises an exception on invalid managerid';
136
        close STDERR;
137
    }
131
    my $manager = $builder->build_object( { class => "Koha::Patrons" } );
138
    my $manager = $builder->build_object( { class => "Koha::Patrons" } );
132
    $suggestion->managedby( $manager->borrowernumber )->store;
139
    $suggestion->managedby( $manager->borrowernumber )->store;
133
    $manager->delete;
140
    $manager->delete;
Lines 136-144 subtest 'constraints' => sub { Link Here
136
        "The suggestion is not deleted when the related manager is deleted" );
143
        "The suggestion is not deleted when the related manager is deleted" );
137
144
138
    # acceptedby
145
    # acceptedby
139
    throws_ok { $suggestion->acceptedby($nonexistent_borrowernumber)->store; }
146
    {    # hide useless warnings
140
    'Koha::Exceptions::Object::FKConstraint',
147
        local *STDERR;
141
      'store raises an exception on invalid acceptedby id';
148
        open STDERR, '>', '/dev/null';
149
        throws_ok {
150
            $suggestion->acceptedby($nonexistent_borrowernumber)->store;
151
        }
152
        'Koha::Exceptions::Object::FKConstraint',
153
          'store raises an exception on invalid acceptedby id';
154
        close STDERR;
155
    }
142
    my $acceptor = $builder->build_object( { class => "Koha::Patrons" } );
156
    my $acceptor = $builder->build_object( { class => "Koha::Patrons" } );
143
    $suggestion->acceptedby( $acceptor->borrowernumber )->store;
157
    $suggestion->acceptedby( $acceptor->borrowernumber )->store;
144
    $acceptor->delete;
158
    $acceptor->delete;
Lines 147-155 subtest 'constraints' => sub { Link Here
147
        "The suggestion is not deleted when the related acceptor is deleted" );
161
        "The suggestion is not deleted when the related acceptor is deleted" );
148
162
149
    # rejectedby
163
    # rejectedby
150
    throws_ok { $suggestion->rejectedby($nonexistent_borrowernumber)->store; }
164
    {    # hide useless warnings
151
    'Koha::Exceptions::Object::FKConstraint',
165
        local *STDERR;
152
      'store raises an exception on invalid rejectedby id';
166
        open STDERR, '>', '/dev/null';
167
        throws_ok {
168
            $suggestion->rejectedby($nonexistent_borrowernumber)->store;
169
        }
170
        'Koha::Exceptions::Object::FKConstraint',
171
          'store raises an exception on invalid rejectedby id';
172
        close STDERR;
173
    }
153
    my $rejecter = $builder->build_object( { class => "Koha::Patrons" } );
174
    my $rejecter = $builder->build_object( { class => "Koha::Patrons" } );
154
    $suggestion->rejectedby( $rejecter->borrowernumber )->store;
175
    $suggestion->rejectedby( $rejecter->borrowernumber )->store;
155
    $rejecter->delete;
176
    $rejecter->delete;
Lines 158-166 subtest 'constraints' => sub { Link Here
158
        "The suggestion is not deleted when the related rejecter is deleted" );
179
        "The suggestion is not deleted when the related rejecter is deleted" );
159
180
160
    # budgetid
181
    # budgetid
161
    throws_ok { $suggestion->budgetid($nonexistent_borrowernumber)->store; }
182
    {    # hide useless warnings
162
    'Koha::Exceptions::Object::FKConstraint',
183
        local *STDERR;
163
      'store raises an exception on invalid budgetid';
184
        open STDERR, '>', '/dev/null';
185
186
        throws_ok { $suggestion->budgetid($nonexistent_borrowernumber)->store; }
187
        'Koha::Exceptions::Object::FKConstraint',
188
          'store raises an exception on invalid budgetid';
189
        close STDERR;
190
    }
164
    my $fund = $builder->build_object( { class => "Koha::Acquisition::Funds" } );
191
    my $fund = $builder->build_object( { class => "Koha::Acquisition::Funds" } );
165
    $suggestion->budgetid( $fund->id )->store;
192
    $suggestion->budgetid( $fund->id )->store;
166
    $fund->delete;
193
    $fund->delete;
167
- 

Return to bug 26157