Koha/t/db_dependent/ReportsGuided.t
Mark Tompsett 82c65678bf Bug 13141: Add ability for biblio_framework to be a dropdown in Guided Reports
By tweaking the GetReservedAuthorisedValues function in
C4::Reports::Guided, biblio_framework can be added as a dropdown
list into the guided reports parameters.

The change in C4/Reports/Guided.pm required a test, which is
found in t/db_dependent/ReportsGuided.t

Code was then added to reports/guided_reports.pl to build the
appropriate hash to trigger the proper dropdown list.

TEST PLAN
---------
1) Apply patch
2) prove -v t/db_dependent/ReportsGuided.t
   -- all should pass, this confirms that both
      C4/Reports/Guided.pm and this test file work.
3) Log into staff client
4) Reports
5) Create from SQL
6) Enter appropriate information like:
Report name: Test 13141
-- no need to change Report group or Report is public or Notes or Type
SQL:
SELECT CONCAT('<a href=\"/cgi-bin/koha/catalogue/detail.pl?biblionumber=',
     biblio.biblionumber,'\">',biblio.biblionumber,'</a>') AS
     BiblioNumbers, title, author, frameworkcode
FROM biblio
WHERE frameworkcode=<<Enter the frameworkcode|biblio_framework>>

7) Save report
8) Run report
   -- The parameter entry page should have a drop down of
      framework codes.
9) Select a framework code, and click Run the report
   -- The displayed SQL should have a "frameworkcode=" portion
      matching the selected framework.
10) Run the koha qa test tool.

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Test plan followed successfully.

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
2014-10-31 13:14:59 -03:00

111 lines
3 KiB
Perl
Executable file

#!/usr/bin/perl
use Modern::Perl;
use Test::More tests => 12;
use Test::MockModule;
use DBD::Mock;
use_ok('C4::Reports::Guided');
my $context = new Test::MockModule('C4::Context');
my $koha = new Test::MockModule('C4::Koha');
$context->mock(
'_new_dbh',
sub {
my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
|| die "Cannot create handle: $DBI::errstr\n";
return $dbh;
}
);
sub MockedIsAuthorisedValueCategory {
my $authorised_value = shift;
if ( $authorised_value eq 'LOC' ) {
return 1;
} else {
return 0;
}
}
$koha->mock(
'IsAuthorisedValueCategory',
\&MockedIsAuthorisedValueCategory
);
{ # GetReservedAuthorisedValues tests
# This one will catch new reserved words not added
# to GetReservedAuthorisedValues
my %test_authval = (
'date' => 1,
'branches' => 1,
'itemtypes' => 1,
'cn_source' => 1,
'categorycode' => 1,
'biblio_framework' => 1,
);
my $reserved_authorised_values = GetReservedAuthorisedValues();
is_deeply(\%test_authval, $reserved_authorised_values,
'GetReservedAuthorisedValues returns a fixed list');
}
SKIP: {
skip "DBD::Mock is too old", 7
unless $DBD::Mock::VERSION >= 1.45;
ok( IsAuthorisedValueValid('LOC'),
'User defined authorised value category is valid');
ok( ! IsAuthorisedValueValid('XXX'),
'Not defined authorised value category is invalid');
# Loop through the reserved authorised values
foreach my $authorised_value ( keys %{GetReservedAuthorisedValues()} ) {
ok( IsAuthorisedValueValid($authorised_value),
'\''.$authorised_value.'\' is a reserved word, and thus a valid authorised value');
}
}
{ # GetParametersFromSQL tests
my $test_query_1 = "
SELECT date_due
FROM old_issues
WHERE YEAR(timestamp) = <<Year|custom_list>> AND
branchcode = <<Branch|branches>> AND
borrowernumber = <<Borrower>>
";
my @test_parameters_with_custom_list = (
{ 'name' => 'Year', 'authval' => 'custom_list' },
{ 'name' => 'Branch', 'authval' => 'branches' },
{ 'name' => 'Borrower', 'authval' => undef }
);
is_deeply( GetParametersFromSQL($test_query_1), \@test_parameters_with_custom_list,
'SQL params are correctly parsed');
# ValidateSQLParameters tests
my @problematic_parameters = ();
push @problematic_parameters, { 'name' => 'Year', 'authval' => 'custom_list' };
is_deeply( ValidateSQLParameters( $test_query_1 ),
\@problematic_parameters,
'\'custom_list\' not a valid category' );
my $test_query_2 = "
SELECT date_due
FROM old_issues
WHERE YEAR(timestamp) = <<Year|date>> AND
branchcode = <<Branch|branches>> AND
borrowernumber = <<Borrower|LOC>>
";
is_deeply( ValidateSQLParameters( $test_query_2 ),
[],
'All parameters valid, empty problematic authvals list');
}