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

(-)a/t/db_dependent/Calendar.t (-2 / +59 lines)
Lines 17-24 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 5;
20
use Test::More tests => 6;
21
use Time::Fake;
21
use Time::Fake;
22
23
use t::lib::Mocks;
22
use t::lib::TestBuilder;
24
use t::lib::TestBuilder;
23
25
24
use DateTime;
26
use DateTime;
Lines 332-335 subtest 'is_holiday' => sub { Link Here
332
    };
334
    };
333
};
335
};
334
336
337
subtest 'get_push_amt' => sub {
338
    plan tests => 1;
339
340
    t::lib::Mocks::mock_preference('useDaysMode', 'Dayweek');
341
342
    subtest 'weekday holidays' => sub {
343
        plan tests => 7;
344
345
        my $library = $builder->build_object( { class => 'Koha::Libraries' } );
346
347
        my $day = DateTime->now();
348
        my $dow = scalar $day->day_of_week;
349
        $dow = 0 if $dow == 7;
350
351
        # Closed this day of the week
352
        my $dbh = C4::Context->dbh;
353
        $dbh->do(
354
            q|
355
            INSERT INTO repeatable_holidays (branchcode,weekday,day,month,title,description)
356
            VALUES ( ?, ?, NULL, NULL, ?, '' )
357
        |, undef, $library->branchcode, $dow, "TEST"
358
        );
359
360
        # Iterate 7 days
361
        my $sth = $dbh->prepare(
362
"UPDATE repeatable_holidays SET weekday = ? WHERE branchcode = ? AND title = 'TEST'"
363
        );
364
        for my $i ( 0 .. 6 ) {
365
            my $calendar =
366
              Koha::Calendar->new( branchcode => $library->branchcode, days_mode => 'Dayweek' );
367
368
            my $npa;
369
            eval {
370
                local $SIG{ALRM} = sub { die "alarm\n" };    # NB: \n required
371
                alarm 2;
372
                $npa = $calendar->next_open_days( $day, 0 );
373
                alarm 0;
374
            };
375
            if ($@) {
376
                die unless $@ eq "alarm\n";    # propagate unexpected errors
377
                # timed out
378
                ok(0, "next_push_amt succeeded for ".$day->day_name()." weekday holiday");
379
            }
380
            else {
381
                ok($npa, "next_push_amt succeeded for ".$day->day_name()." weekday holiday");
382
            }
383
384
            # Increment the date and holiday day
385
            $day->add( days => 1 );
386
            $dow++;
387
            $dow = 0 if $dow == 7;
388
            $sth->execute( $dow, $library->branchcode );
389
        }
390
    };
391
};
392
335
$schema->storage->txn_rollback();
393
$schema->storage->txn_rollback();
336
- 

Return to bug 25850