4 use Test
::More tests
=> 95;
9 my $schema = Koha
::Database
->new->schema;
10 $schema->storage->txn_begin;
12 use C4
::Serials
::Numberpattern
;
14 # Start by deleting all numberpatterns.
15 my @numberpatterns = GetSubscriptionNumberpatterns
();
16 foreach my $n (@numberpatterns) {
17 DelSubscriptionNumberpattern
($n->{id
});
20 @numberpatterns = GetSubscriptionNumberpatterns
();
21 is
(scalar @numberpatterns, 0, "There is no numberpatterns in database");
23 my $numberpattern = GetSubscriptionNumberpattern
(1);
24 is
($numberpattern, undef, "GetSubscriptionNumberpattern(1) returns undef");
26 my $rv = ModSubscriptionNumberpattern
($numberpattern);
27 is
($rv, undef, "ModSubscriptionNumberpattern(undef) returns undef");
29 $rv = ModSubscriptionNumberpattern
($numberpattern);
30 is
($rv, undef, "ModSubscriptionNumberpattern({}) returns undef");
31 # returns 0 because id doesn't exist
32 $numberpattern = { id
=> 1, label
=> "Test numberpattern 1", description
=> '' };
33 $rv = ModSubscriptionNumberpattern
($numberpattern);
34 is
($rv, '0E0', "ModSubscriptionNumberpattern({id=1,label=>'Test numberpattern 1'}) returns '0 but true'");
36 $numberpattern = undef;
37 my $id = AddSubscriptionNumberpattern
($numberpattern);
38 is
($id, undef, "AddSubscriptionNumberpattern(undef) returns undef");
40 $id = AddSubscriptionNumberpattern
($numberpattern);
41 is
($id, undef, "AddSubscriptionNumberpattern({}) returns undef");
42 $numberpattern = { label
=> "Test numberpattern 1", numberingmethod
=> "{X}", description
=> '' };
43 $id = AddSubscriptionNumberpattern
($numberpattern);
44 ok
((defined($id) && ($id > 0)), "AddSubscriptionNumberpattern({label => 'Test numberpattern 1', numberingmethod => '{X}'}) returns numberpattern id");
46 $numberpattern = GetSubscriptionNumberpattern
($id);
47 isa_ok
($numberpattern, 'HASH', "GetSubscriptionNumberpattern($id)");
48 is
($numberpattern->{label
}, "Test numberpattern 1", "label OK");
49 is
($numberpattern->{numberingmethod
}, '{X}', "unit OK");
50 is
($numberpattern->{description
}, '', "description OK");
51 is
($numberpattern->{displayorder
}, undef, "displayorder OK");
52 foreach my $key (qw(label add every setto whenmorethan numbering)) {
53 foreach my $index (1,2,3) {
54 ok
(exists $numberpattern->{$key . $index}, "$key$index exists");
55 is
($numberpattern->{$key . $index}, undef, "$key$index is undef");
59 $numberpattern->{label
} = $numberpattern->{label
} . " (modified)";
60 $numberpattern->{displayorder
} = 1;
62 foreach my $key (qw(label add every setto whenmorethan numbering)) {
63 foreach my $index (1,2,3) {
64 $numberpattern->{$key . $index} = $i++;
67 $rv = ModSubscriptionNumberpattern
($numberpattern);
68 is
($rv, 1, "ModSubscriptionNumberpattern(\$numberpattern) returns 1");
70 $numberpattern = GetSubscriptionNumberpattern
($id);
71 isa_ok
($numberpattern, 'HASH', "GetSubscriptionNumberpattern($id)");
72 is
($numberpattern->{label
}, "Test numberpattern 1 (modified)", "label OK");
73 is
($numberpattern->{numberingmethod
}, '{X}', "unit OK");
74 is
($numberpattern->{description
}, '', "description OK");
75 is
($numberpattern->{displayorder
}, 1, "displayorder OK");
77 foreach my $key (qw(label add every setto whenmorethan numbering)) {
78 foreach my $index (1,2,3) {
79 ok
(exists $numberpattern->{$key . $index}, "$key$index exists");
80 is
($numberpattern->{$key . $index}, $i++, "$key$index is $i");
84 @numberpatterns = GetSubscriptionNumberpatterns
();
85 is
(scalar @numberpatterns, 1, "There is one numberpattern");
87 # Add another numberpattern
88 undef $numberpattern->{id
};
89 my $id2 = AddSubscriptionNumberpattern
($numberpattern);
91 @numberpatterns = GetSubscriptionNumberpatterns
();
92 is
(scalar @numberpatterns, 2, "There are two numberpatterns");
94 # Delete one numberpattern
95 DelSubscriptionNumberpattern
($id);
96 @numberpatterns = GetSubscriptionNumberpatterns
();
97 is
(scalar @numberpatterns, 1, "There is one numberpattern");
99 # Delete the other numberpattern
100 DelSubscriptionNumberpattern
($id2);
101 @numberpatterns = GetSubscriptionNumberpatterns
();
102 is
(scalar @numberpatterns, 0, "There is no numberpattern");