5 use Test
::More tests
=> 13;
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
48 'biblio_framework' => 1,
51 my $reserved_authorised_values = GetReservedAuthorisedValues
();
52 is_deeply
(\
%test_authval, $reserved_authorised_values,
53 'GetReservedAuthorisedValues returns a fixed list');
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
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
' );
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
');