5 use Test
::More tests
=> 13;
10 use_ok
('C4::Reports::Guided');
12 my $context = new Test
::MockModule
('C4::Context');
13 my $koha = new Test
::MockModule
('C4::Koha');
16 t
::lib
::Mocks
::mock_dbh
;
19 sub MockedIsAuthorisedValueCategory
{
20 my $authorised_value = shift;
22 if ( $authorised_value eq 'LOC' ) {
30 'IsAuthorisedValueCategory',
31 \
&MockedIsAuthorisedValueCategory
34 { # GetReservedAuthorisedValues tests
35 # This one will catch new reserved words not added
36 # to GetReservedAuthorisedValues
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
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
' );
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
');