5 use Test
::More tests
=> 12;
9 use_ok
('C4::Reports::Guided');
11 my $context = new Test
::MockModule
('C4::Context');
12 my $koha = new Test
::MockModule
('C4::Koha');
17 my $dbh = DBI
->connect( 'DBI:Mock:', '', '' )
18 || die "Cannot create handle: $DBI::errstr\n";
24 sub MockedIsAuthorisedValueCategory
{
25 my $authorised_value = shift;
27 if ( $authorised_value eq 'LOC' ) {
35 'IsAuthorisedValueCategory',
36 \
&MockedIsAuthorisedValueCategory
39 { # GetReservedAuthorisedValues tests
40 # This one will catch new reserved words not added
41 # to GetReservedAuthorisedValues
50 my $reserved_authorised_values = GetReservedAuthorisedValues
();
51 is_deeply
(\
%test_authval, $reserved_authorised_values,
52 'GetReservedAuthorisedValues returns a fixed list');
57 skip
"DBD::Mock is too old", 7
58 unless $DBD::Mock
::VERSION
>= 1.45;
60 ok
( IsAuthorisedValueValid
('LOC'),
61 'User defined authorised value category is valid');
63 ok
( ! IsAuthorisedValueValid
('XXX'),
64 'Not defined authorised value category is invalid');
66 # Loop through the reserved authorised values
67 foreach my $authorised_value ( keys %{GetReservedAuthorisedValues
()} ) {
68 ok
( IsAuthorisedValueValid
($authorised_value),
69 '\''.$authorised_value.'\' is a reserved word, and thus a valid authorised value');
73 { # GetParametersFromSQL tests
78 WHERE YEAR(timestamp) = <<Year|custom_list>> AND
79 branchcode = <<Branch|branches>> AND
80 borrowernumber = <<Borrower>>
83 my @test_parameters_with_custom_list = (
84 { 'name' => 'Year', 'authval' => 'custom_list' },
85 { 'name' => 'Branch', 'authval' => 'branches' },
86 { 'name' => 'Borrower', 'authval
' => undef }
89 is_deeply( GetParametersFromSQL($test_query_1), \@test_parameters_with_custom_list,
90 'SQL params are correctly parsed
');
92 # ValidateSQLParameters tests
93 my @problematic_parameters = ();
94 push @problematic_parameters, { 'name
' => 'Year
', 'authval
' => 'custom_list
' };
95 is_deeply( ValidateSQLParameters( $test_query_1 ),
96 \@problematic_parameters,
97 '\'custom_list
\' not a valid category
' );
102 WHERE YEAR(timestamp) = <<Year|date>> AND
103 branchcode = <<Branch|branches>> AND
104 borrowernumber = <<Borrower|LOC>>
107 is_deeply( ValidateSQLParameters( $test_query_2 ),
109 'All parameters valid
, empty problematic authvals list
');