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

(-)a/t/db_dependent/Koha/Acquisition/Basket.t (-2 / +75 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 10;
22
use Test::More tests => 12;
23
use Test::Exception;
24
23
use t::lib::TestBuilder;
25
use t::lib::TestBuilder;
24
use t::lib::Mocks;
26
use t::lib::Mocks;
25
27
Lines 300-302 subtest 'orders' => sub { Link Here
300
302
301
    $schema->storage->txn_rollback;
303
    $schema->storage->txn_rollback;
302
};
304
};
303
- 
305
306
subtest 'closed() tests' => sub {
307
308
    plan tests => 2;
309
310
    $schema->storage->txn_begin;
311
312
    my $open_basket = $builder->build_object(
313
        {
314
            class => 'Koha::Acquisition::Baskets',
315
            value => {
316
                closedate => undef
317
            }
318
        }
319
    );
320
321
    my $closed_basket = $builder->build_object(
322
        {
323
            class => 'Koha::Acquisition::Baskets',
324
            value => {
325
                closedate => \'NOW()'
326
            }
327
        }
328
    );
329
330
    ok( $closed_basket->closed, 'Closed basket is tested as closed' );
331
    ok( !$open_basket->closed, 'Open basket is tested as open' );
332
333
    $schema->storage->txn_rollback;
334
};
335
336
subtest 'close() tests' => sub {
337
338
    plan tests => 3;
339
340
    $schema->storage->txn_begin;
341
342
    # Create an open basket
343
    my $basket = $builder->build_object(
344
        {
345
            class => 'Koha::Acquisition::Baskets',
346
            value => {
347
                closedate => undef
348
            }
349
        }
350
    );
351
352
    for my $status ( qw( new ordered partial complete cancelled ) ) {
353
        $builder->build_object(
354
            {
355
                class => 'Koha::Acquisition::Orders',
356
                value => {
357
                    basketno    => $basket->id,
358
                    orderstatus => $status
359
                }
360
            }
361
        );
362
    }
363
364
    $basket->close;
365
366
    ok( $basket->closed, 'Basket is closed' );
367
    my $ordered_orders = $basket->orders->search({ orderstatus => 'ordered' });
368
    is( $ordered_orders->count, 3, 'Only open orders have been marked as ordered' );
369
370
    throws_ok
371
        { $basket->close; }
372
        'Koha::Exceptions::Acquisition::Basket::AlreadyClosed',
373
        'Trying to close an already closed basket throws an exception';
374
375
    $schema->storage->txn_rollback;
376
};

Return to bug 26582