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

(-)a/t/db_dependent/Koha/Object.t (-2 / +92 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 9;
20
use Test::More tests => 10;
21
use Test::Exception;
21
use Test::Warn;
22
use Test::Warn;
22
23
23
use C4::Context;
24
use C4::Context;
Lines 218-220 subtest "Test update method" => sub { Link Here
218
219
219
    $schema->storage->txn_rollback;
220
    $schema->storage->txn_rollback;
220
};
221
};
221
- 
222
223
subtest 'store() tests' => sub {
224
225
    plan tests => 10;
226
227
    $schema->storage->txn_begin;
228
229
    # Create a category to make sure its ID doesn't exist on the DB
230
    my $category = $builder->build_object({ class => 'Koha::Patron::Categories' });
231
    my $category_id = $category->id;
232
    $category->delete;
233
234
    my $patron = Koha::Patron->new({ categorycode => $category_id });
235
236
    my $print_error = $schema->storage->dbh->{PrintError};
237
    $schema->storage->dbh->{PrintError} = 0;
238
    throws_ok
239
        { $patron->store }
240
        'Koha::Exceptions::Object::FKConstraint',
241
        'Exception is thrown correctly';
242
    is(
243
        $@->message,
244
        "Broken FK constraint",
245
        'Exception message is correct'
246
    );
247
    is(
248
        $@->broken_fk,
249
        'categorycode',
250
        'Exception field is correct'
251
    );
252
253
    my $library = $builder->build_object({ class => 'Koha::Libraries' });
254
    $category   = $builder->build_object({ class => 'Koha::Patron::Categories' });
255
    $patron     = $builder->build_object({ class => 'Koha::Patrons' });
256
257
    my $new_patron = Koha::Patron->new({
258
        branchcode   => $library->id,
259
        cardnumber   => $patron->cardnumber,
260
        categorycode => $category->id
261
    });
262
263
    throws_ok
264
        { $new_patron->store }
265
        'Koha::Exceptions::Object::DuplicateID',
266
        'Exception is thrown correctly';
267
268
    is(
269
        $@->message,
270
        'Duplicate ID',
271
        'Exception message is correct'
272
    );
273
274
    is(
275
       $@->duplicate_id,
276
       'cardnumber',
277
       'Exception field is correct'
278
    );
279
280
    $new_patron = Koha::Patron->new({
281
        branchcode   => $library->id,
282
        userid       => $patron->userid,
283
        categorycode => $category->id
284
    });
285
286
    throws_ok
287
        { $new_patron->store }
288
        'Koha::Exceptions::Object::DuplicateID',
289
        'Exception is thrown correctly';
290
291
    is(
292
        $@->message,
293
        'Duplicate ID',
294
        'Exception message is correct'
295
    );
296
297
    is(
298
       $@->duplicate_id,
299
       'userid',
300
       'Exception field is correct'
301
    );
302
303
    $schema->storage->dbh->{PrintError} = $print_error;
304
305
    # Successful test
306
    $patron->set({ firstname => 'Manuel' });
307
    my $ret = $patron->store;
308
    is( ref($ret), 'Koha::Patron', 'store() returns the object on success' );
309
310
    $schema->storage->txn_rollback;
311
};

Return to bug 19828