Bug 14778: Install fixtures for t/Biblio.t
[koha.git] / t / db_dependent / ReportsGuided.t
blob097722a19f9e4d267ff31568ff06e2cc0cfbaf92
1 #!/usr/bin/perl
3 use Modern::Perl;
5 use Test::More tests => 13;
6 use Test::MockModule;
8 use t::lib::Mocks;
10 use_ok('C4::Reports::Guided');
12 my $context = new Test::MockModule('C4::Context');
13 my $koha = new Test::MockModule('C4::Koha');
15 BEGIN {
16 t::lib::Mocks::mock_dbh;
19 sub MockedIsAuthorisedValueCategory {
20 my $authorised_value = shift;
22 if ( $authorised_value eq 'LOC' ) {
23 return 1;
24 } else {
25 return 0;
29 $koha->mock(
30 'IsAuthorisedValueCategory',
31 \&MockedIsAuthorisedValueCategory
34 { # GetReservedAuthorisedValues tests
35 # This one will catch new reserved words not added
36 # to GetReservedAuthorisedValues
37 my %test_authval = (
38 'date' => 1,
39 'branches' => 1,
40 'itemtypes' => 1,
41 'cn_source' => 1,
42 'categorycode' => 1,
43 'biblio_framework' => 1,
46 my $reserved_authorised_values = GetReservedAuthorisedValues();
47 is_deeply(\%test_authval, $reserved_authorised_values,
48 'GetReservedAuthorisedValues returns a fixed list');
52 ok( IsAuthorisedValueValid('LOC'),
53 'User defined authorised value category is valid');
55 ok( ! IsAuthorisedValueValid('XXX'),
56 'Not defined authorised value category is invalid');
58 # Loop through the reserved authorised values
59 foreach my $authorised_value ( keys %{GetReservedAuthorisedValues()} ) {
60 ok( IsAuthorisedValueValid($authorised_value),
61 '\''.$authorised_value.'\' is a reserved word, and thus a valid authorised value');
65 { # GetParametersFromSQL tests
67 my $test_query_1 = "
68 SELECT date_due
69 FROM old_issues
70 WHERE YEAR(timestamp) = <<Year|custom_list>> AND
71 branchcode = <<Branch|branches>> AND
72 borrowernumber = <<Borrower>>
75 my @test_parameters_with_custom_list = (
76 { 'name' => 'Year', 'authval' => 'custom_list' },
77 { 'name' => 'Branch', 'authval' => 'branches' },
78 { 'name' => 'Borrower', 'authval' => undef }
81 is_deeply( GetParametersFromSQL($test_query_1), \@test_parameters_with_custom_list,
82 'SQL params are correctly parsed');
84 # ValidateSQLParameters tests
85 my @problematic_parameters = ();
86 push @problematic_parameters, { 'name' => 'Year', 'authval' => 'custom_list' };
87 is_deeply( ValidateSQLParameters( $test_query_1 ),
88 \@problematic_parameters,
89 '\'custom_list\' not a valid category' );
91 my $test_query_2 = "
92 SELECT date_due
93 FROM old_issues
94 WHERE YEAR(timestamp) = <<Year|date>> AND
95 branchcode = <<Branch|branches>> AND
96 borrowernumber = <<Borrower|LOC>>
99 is_deeply( ValidateSQLParameters( $test_query_2 ),
101 'All parameters valid, empty problematic authvals list');