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

(-)a/t/db_dependent/Serials/GetFictiveIssueNumber.t (+91 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# This test deals with GetFictiveIssueNumber (from C4::Serials)
4
5
use Modern::Perl;
6
use Test::More tests => 2;
7
8
use Koha::Database;
9
use C4::Serials;
10
use C4::Serials::Frequency;
11
12
my $schema  = Koha::Database->new->schema;
13
$schema->storage->txn_begin;
14
my $dbh = C4::Context->dbh;
15
16
subtest 'Tests for irregular frequency' => sub {
17
    plan tests => 2;
18
19
    # Add a frequency
20
    my $freq_irr = AddSubscriptionFrequency({
21
        description => "Irregular",
22
        unit => undef,
23
    });
24
25
    # Test it
26
    my $subscription = {
27
        periodicity => $freq_irr,
28
        firstacquidate => '1972-02-07',
29
    };
30
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-12-31'), 0, 'Irregular: should be zero' );
31
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-12-31'), 0, 'Irregular: still zero' );
32
};
33
34
subtest 'Tests for yearly frequencies' => sub {
35
    plan tests => 8;
36
37
    # First add a few frequencies
38
    my $freq_1i_1y = AddSubscriptionFrequency({
39
        description => "1 issue per year",
40
        unit => 'year',
41
        issuesperunit => 1,
42
        unitsperissue => 1,
43
    });
44
    my $freq_1i_3y = AddSubscriptionFrequency({
45
        description => "1 issue per 3 years",
46
        unit => 'year',
47
        issuesperunit => 1,
48
        unitsperissue => 3,
49
    });
50
    my $freq_5i_1y = AddSubscriptionFrequency({
51
        description => "5 issue per year",
52
        unit => 'year',
53
        issuesperunit => 5,
54
        unitsperissue => 1,
55
    });
56
57
    # TEST CASE - 1 issue per year
58
    # Here we should only test the subtraction of both years
59
    my $subscription = {
60
        periodicity => $freq_1i_1y,
61
        firstacquidate => '1972-02-10',
62
        countissuesperunit => 1,
63
    };
64
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-12-31'), 1, 'Dec 31 still 1' );
65
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-01-01'), 2, 'Jan 1 goes to 2' );
66
67
    # TEST CASE - 1 issue per 3 years
68
    # Here we should test the subtraction of both years divided by 3
69
    $subscription->{periodicity} = $freq_1i_3y;
70
    $subscription->{firstacquidate} = '1972-02-20';
71
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-01-01'), 1, '1973 still 1' );
72
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1974-01-01'), 1, '1974 still 1' );
73
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1975-01-01'), 2, '1975 still 2' );
74
75
    # TEST CASE - 5 issues per year
76
    # Here we look at the subtraction AND the internal countissuesperunit
77
    # We do not really care about the accuracy of the internal count here
78
    $subscription->{periodicity} = $freq_5i_1y;
79
    $subscription->{firstacquidate} = '1972-02-29'; #leap year
80
    $subscription->{countissuesperunit} = 3;
81
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-06-01'), 3, 'Should be 3 due to internal count' );
82
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-28'), 3, 'Should still be 3 due to internal count' );
83
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-03-01'), 8, 'Should jump to 8 due to internal count' );
84
85
};
86
87
# TODO: subtest 'Tests for monthly frequencies' => sub {
88
# TODO: subtest 'Tests for weekly frequencies' => sub {
89
# TODO: subtest 'Tests for dayly frequencies' => sub {
90
91
$schema->storage->txn_rollback;
(-)a/t/db_dependent/Serials/GetNextDate.t (-9 / +43 lines)
Lines 1-15 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
use C4::Context;
4
use Test::More tests => 96;
5
use Modern::Perl;
3
use Modern::Perl;
4
use Test::More tests => 102;
6
5
6
use Koha::Database;
7
use C4::Serials;
8
use C4::Serials::Frequency;
9
10
my $schema  = Koha::Database->new->schema;
11
$schema->storage->txn_begin;
7
my $dbh = C4::Context->dbh;
12
my $dbh = C4::Context->dbh;
8
$dbh->{RaiseError} = 1;
9
$dbh->{AutoCommit} = 0;
10
13
11
use C4::Serials::Frequency;
12
use C4::Serials;
13
14
14
# TEST CASE - 1 issue per day, no irregularities
15
# TEST CASE - 1 issue per day, no irregularities
15
my $frequency = {
16
my $frequency = {
Lines 469-478 $publisheddate = GetNextDate($subscription, $publisheddate); Link Here
469
is($publisheddate, '1978-01-01');
470
is($publisheddate, '1978-01-01');
470
$publisheddate = GetNextDate($subscription, $publisheddate);
471
$publisheddate = GetNextDate($subscription, $publisheddate);
471
is($publisheddate, '1980-01-01');
472
is($publisheddate, '1980-01-01');
473
# Move publisheddate to Feb 29 (leap year 1980)
474
$publisheddate = '1980-02-29';
475
$publisheddate = GetNextDate( $subscription, $publisheddate );
476
is( $publisheddate, '1982-02-28', 'Test +2 year from Feb 29' );
472
477
473
# TEST CASE - 2 issues per year, no irregularity
478
# TEST CASE - 2 issues per year, no irregularity
474
$id = AddSubscriptionFrequency({
479
$id = AddSubscriptionFrequency({
475
    description => "1 issue every 2 years",
480
    description => "2 issues per year",
476
    unit => 'year',
481
    unit => 'year',
477
    issuesperunit => 2,
482
    issuesperunit => 2,
478
    unitsperissue => 1,
483
    unitsperissue => 1,
Lines 512-517 is($publisheddate, '1973-07-02'); Link Here
512
$publisheddate = GetNextDate($subscription, $publisheddate);
517
$publisheddate = GetNextDate($subscription, $publisheddate);
513
is($publisheddate, '1974-01-01');
518
is($publisheddate, '1974-01-01');
514
519
520
# TEST CASE - 9 issues per year, dates spread throughout month
521
$id = AddSubscriptionFrequency({
522
    description => "9 issues per year",
523
    unit => 'year',
524
    issuesperunit => 9,
525
    unitsperissue => 1,
526
});
527
$subscription = {
528
    periodicity => $id,
529
    firstacquidate => '1970-08-10',
530
    irregularity => '',
531
    countissuesperunit => 1,
532
};
533
my @dates = ( $subscription->{firstacquidate} );
534
foreach(1..27) {
535
    push @dates, GetNextDate( $subscription, $dates[-1] );
536
}
537
is( $dates[9],  '1971-08-10', 'Freq 9/yr, 1 year passed' );
538
is( $dates[18], '1972-08-10', 'Freq 9/yr, 2 years passed (leap year)' );
539
is( $dates[27], '1973-08-10', 'Freq 9/yr, 3 years passed' );
540
# Now move one back in the cycle and push back 49 days; we expect correction
541
# because 40 days are added and the difference (9 days) is <= issues per unit.
542
$subscription->{countissuesperunit} = 9;
543
$publisheddate = GetNextDate( $subscription, '1973-06-22' );
544
is( $publisheddate, '1973-08-10', 'Freq 9/yr, 3 years passed, corrected' );
545
# Set back again, one day more. Now we do not expect correction.
546
$subscription->{countissuesperunit} = 9;
547
$publisheddate = GetNextDate( $subscription, '1973-06-21' );
548
is( $publisheddate, '1973-07-31', 'Freq 9/yr, 3 years passed, not corrected' );
549
515
# TEST CASE - Irregular
550
# TEST CASE - Irregular
516
$id = AddSubscriptionFrequency({
551
$id = AddSubscriptionFrequency({
517
    description => "Irregular",
552
    description => "Irregular",
Lines 538-541 is($publisheddate, undef); Link Here
538
$publisheddate = GetNextDate(undef, undef);
573
$publisheddate = GetNextDate(undef, undef);
539
is($publisheddate, undef);
574
is($publisheddate, undef);
540
575
541
$dbh->rollback;
576
$schema->storage->txn_rollback;
542
- 

Return to bug 18356