Bug 12803 - Add ability to skip closed libraries when generating the holds queue
[koha.git] / t / db_dependent / ReportsGuided.t
1 #!/usr/bin/perl
2
3 use Modern::Perl;
4
5 use Test::More tests => 13;
6
7 use Koha::Database;
8
9 use_ok('C4::Reports::Guided');
10
11 my $schema = Koha::Database->new->schema;
12 $schema->storage->txn_begin;
13
14 $_->delete for Koha::AuthorisedValues->search({ category => 'XXX' });
15 Koha::AuthorisedValue->new({category => 'LOC'})->store;
16
17 {   # GetReservedAuthorisedValues tests
18     # This one will catch new reserved words not added
19     # to GetReservedAuthorisedValues
20     my %test_authval = (
21         'date' => 1,
22         'branches' => 1,
23         'itemtypes' => 1,
24         'cn_source' => 1,
25         'categorycode' => 1,
26         'biblio_framework' => 1,
27     );
28
29     my $reserved_authorised_values = GetReservedAuthorisedValues();
30     is_deeply(\%test_authval, $reserved_authorised_values,
31                 'GetReservedAuthorisedValues returns a fixed list');
32 }
33
34 {
35     ok( IsAuthorisedValueValid('LOC'),
36         'User defined authorised value category is valid');
37
38     ok( ! IsAuthorisedValueValid('XXX'),
39         'Not defined authorised value category is invalid');
40
41     # Loop through the reserved authorised values
42     foreach my $authorised_value ( keys %{GetReservedAuthorisedValues()} ) {
43         ok( IsAuthorisedValueValid($authorised_value),
44             '\''.$authorised_value.'\' is a reserved word, and thus a valid authorised value');
45     }
46 }
47
48 {   # GetParametersFromSQL tests
49
50     my $test_query_1 = "
51         SELECT date_due
52         FROM old_issues
53         WHERE YEAR(timestamp) = <<Year|custom_list>> AND
54               branchcode = <<Branch|branches>> AND
55               borrowernumber = <<Borrower>>
56     ";
57
58     my @test_parameters_with_custom_list = (
59         { 'name' => 'Year', 'authval' => 'custom_list' },
60         { 'name' => 'Branch', 'authval' => 'branches' },
61         { 'name' => 'Borrower', 'authval' => undef }
62     );
63
64     is_deeply( GetParametersFromSQL($test_query_1), \@test_parameters_with_custom_list,
65         'SQL params are correctly parsed');
66
67     # ValidateSQLParameters tests
68     my @problematic_parameters = ();
69     push @problematic_parameters, { 'name' => 'Year', 'authval' => 'custom_list' };
70     is_deeply( ValidateSQLParameters( $test_query_1 ),
71                \@problematic_parameters,
72                '\'custom_list\' not a valid category' );
73
74     my $test_query_2 = "
75         SELECT date_due
76         FROM old_issues
77         WHERE YEAR(timestamp) = <<Year|date>> AND
78               branchcode = <<Branch|branches>> AND
79               borrowernumber = <<Borrower|LOC>>
80     ";
81
82     is_deeply( ValidateSQLParameters( $test_query_2 ),
83         [],
84         'All parameters valid, empty problematic authvals list');
85 }