5 use Test::More tests => 13;
9 use_ok('C4::Reports::Guided');
11 my $schema = Koha::Database->new->schema;
12 $schema->storage->txn_begin;
14 $_->delete for Koha::AuthorisedValues->search({ category => 'XXX' });
15 Koha::AuthorisedValue->new({category => 'LOC'})->store;
17 { # GetReservedAuthorisedValues tests
18 # This one will catch new reserved words not added
19 # to GetReservedAuthorisedValues
26 'biblio_framework' => 1,
29 my $reserved_authorised_values = GetReservedAuthorisedValues();
30 is_deeply(\%test_authval, $reserved_authorised_values,
31 'GetReservedAuthorisedValues returns a fixed list');
35 ok( IsAuthorisedValueValid('LOC'),
36 'User defined authorised value category is valid');
38 ok( ! IsAuthorisedValueValid('XXX'),
39 'Not defined authorised value category is invalid');
41 # Loop through the reserved authorised values
42 foreach my $authorised_value ( keys %{GetReservedAuthorisedValues()} ) {
43 ok( IsAuthorisedValueValid($authorised_value),
44 '\''.$authorised_value.'\' is a reserved word, and thus a valid authorised value');
48 { # GetParametersFromSQL tests
53 WHERE YEAR(timestamp) = <<Year|custom_list>> AND
54 branchcode = <<Branch|branches>> AND
55 borrowernumber = <<Borrower>>
58 my @test_parameters_with_custom_list = (
59 { 'name' => 'Year', 'authval' => 'custom_list' },
60 { 'name' => 'Branch', 'authval' => 'branches' },
61 { 'name' => 'Borrower', 'authval' => undef }
64 is_deeply( GetParametersFromSQL($test_query_1), \@test_parameters_with_custom_list,
65 'SQL params are correctly parsed');
67 # ValidateSQLParameters tests
68 my @problematic_parameters = ();
69 push @problematic_parameters, { 'name' => 'Year', 'authval' => 'custom_list' };
70 is_deeply( ValidateSQLParameters( $test_query_1 ),
71 \@problematic_parameters,
72 '\'custom_list\' not a valid category' );
77 WHERE YEAR(timestamp) = <<Year|date>> AND
78 branchcode = <<Branch|branches>> AND
79 borrowernumber = <<Borrower|LOC>>
82 is_deeply( ValidateSQLParameters( $test_query_2 ),
84 'All parameters valid, empty problematic authvals list');