Bug 5010: Fix OPACBaseURL to include protocol
[koha.git] / t / db_dependent / ReportsGuided.t
blobd51ca8d96336913e3f2bbce8f064ac031f01ae52
1 #!/usr/bin/perl
3 use Modern::Perl;
5 use Test::More tests => 13;
6 use Test::MockModule;
7 use DBD::Mock;
9 use_ok('C4::Reports::Guided');
11 my $context = new Test::MockModule('C4::Context');
12 my $koha = new Test::MockModule('C4::Koha');
14 $context->mock(
15 '_new_dbh',
16 sub {
17 my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
18 || die "Cannot create handle: $DBI::errstr\n";
19 return $dbh;
24 sub MockedIsAuthorisedValueCategory {
25 my $authorised_value = shift;
27 if ( $authorised_value eq 'LOC' ) {
28 return 1;
29 } else {
30 return 0;
34 $koha->mock(
35 'IsAuthorisedValueCategory',
36 \&MockedIsAuthorisedValueCategory
39 { # GetReservedAuthorisedValues tests
40 # This one will catch new reserved words not added
41 # to GetReservedAuthorisedValues
42 my %test_authval = (
43 'date' => 1,
44 'branches' => 1,
45 'itemtypes' => 1,
46 'cn_source' => 1,
47 'categorycode' => 1,
48 'biblio_framework' => 1,
51 my $reserved_authorised_values = GetReservedAuthorisedValues();
52 is_deeply(\%test_authval, $reserved_authorised_values,
53 'GetReservedAuthorisedValues returns a fixed list');
56 SKIP: {
58 skip "DBD::Mock is too old", 8
59 unless $DBD::Mock::VERSION >= 1.45;
61 ok( IsAuthorisedValueValid('LOC'),
62 'User defined authorised value category is valid');
64 ok( ! IsAuthorisedValueValid('XXX'),
65 'Not defined authorised value category is invalid');
67 # Loop through the reserved authorised values
68 foreach my $authorised_value ( keys %{GetReservedAuthorisedValues()} ) {
69 ok( IsAuthorisedValueValid($authorised_value),
70 '\''.$authorised_value.'\' is a reserved word, and thus a valid authorised value');
74 { # GetParametersFromSQL tests
76 my $test_query_1 = "
77 SELECT date_due
78 FROM old_issues
79 WHERE YEAR(timestamp) = <<Year|custom_list>> AND
80 branchcode = <<Branch|branches>> AND
81 borrowernumber = <<Borrower>>
84 my @test_parameters_with_custom_list = (
85 { 'name' => 'Year', 'authval' => 'custom_list' },
86 { 'name' => 'Branch', 'authval' => 'branches' },
87 { 'name' => 'Borrower', 'authval' => undef }
90 is_deeply( GetParametersFromSQL($test_query_1), \@test_parameters_with_custom_list,
91 'SQL params are correctly parsed');
93 # ValidateSQLParameters tests
94 my @problematic_parameters = ();
95 push @problematic_parameters, { 'name' => 'Year', 'authval' => 'custom_list' };
96 is_deeply( ValidateSQLParameters( $test_query_1 ),
97 \@problematic_parameters,
98 '\'custom_list\' not a valid category' );
100 my $test_query_2 = "
101 SELECT date_due
102 FROM old_issues
103 WHERE YEAR(timestamp) = <<Year|date>> AND
104 branchcode = <<Branch|branches>> AND
105 borrowernumber = <<Borrower|LOC>>
108 is_deeply( ValidateSQLParameters( $test_query_2 ),
110 'All parameters valid, empty problematic authvals list');