Bugzilla – Attachment 17351 Details for
Bug 9659
Undefined authorised value category yields empty dropdown menu on SQL reports
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 9659 - QA Follow up: Unit tests
Bug-9659---QA-Follow-up-Unit-tests.patch (text/plain), 5.52 KB, created by
Tomás Cohen Arazi (tcohen)
on 2013-04-10 18:53:31 UTC
(
hide
)
Description:
Bug 9659 - QA Follow up: Unit tests
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2013-04-10 18:53:31 UTC
Size:
5.52 KB
patch
obsolete
>From 252227cd1fd294d1398e02e6bf1b70e8ca2a3e63 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@gmail.com> >Date: Wed, 10 Apr 2013 15:50:50 -0300 >Subject: [PATCH] Bug 9659 - QA Follow up: Unit tests >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >Added some tests against the methods added by this patch. > >To test, prove -v >- t/Koha.t >- t/ReportsGuided.t > >Sponsored-by: Universidad Nacional de Córdoba >--- > t/Koha.t | 36 ++++++++++++++++- > t/ReportsGuided.t | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 145 insertions(+), 2 deletions(-) > create mode 100755 t/ReportsGuided.t > >diff --git a/t/Koha.t b/t/Koha.t >index 025ab98..5914d9a 100755 >--- a/t/Koha.t >+++ b/t/Koha.t >@@ -2,10 +2,43 @@ > use strict; > use warnings; > >-use Test::More tests => 8; >+use C4::Context; >+use Test::More tests => 11; >+use Test::MockModule; >+use DBD::Mock; > > use_ok('C4::Koha'); > >+my $module_context = new Test::MockModule('C4::Context'); >+$module_context->mock( >+ '_new_dbh', >+ sub { >+ my $dbh = DBI->connect( 'DBI:Mock:', '', '' ) >+ || die "Cannot create handle: $DBI::errstr\n"; >+ return $dbh; >+ } >+); >+ >+SKIP: { >+ >+ skip "DBD::Mock is too old", 8 >+ unless $DBD::Mock::VERSION >= 1.45; >+ >+ my @loc_results = (['category'],['LOC']); >+ my @empty_results = ([]); >+ my @relterms_results = (['category'],['RELTERMS']); >+ >+ my $dbh = C4::Context->dbh(); >+ >+ $dbh->{mock_add_resultset} = \@loc_results; >+ is ( IsAuthorisedValueCategory('LOC'), 1, 'LOC is a valid authorized value category'); >+ $dbh->{mock_add_resultset} = \@empty_results; >+ is ( IsAuthorisedValueCategory('something'), 0, 'something is not a valid authorized value category'); >+ $dbh->{mock_add_resultset} = \@relterms_results; >+ is ( IsAuthorisedValueCategory('RELTERMS'), 1, 'RELTERMS is a valid authorized value category'); >+ >+} # End SKIP block >+ > # > # test that &slashifyDate returns correct (non-US) date > # >@@ -28,4 +61,3 @@ is(C4::Koha::_isbn_cleanup('0-590-35340-3'), '0590353403', '_isbn_cleanup remove > is(C4::Koha::_isbn_cleanup('0590353403 (pbk.)'), '0590353403', '_isbn_cleanup removes parenthetical'); > is(C4::Koha::_isbn_cleanup('978-0-321-49694-2'), '0321496949', '_isbn_cleanup converts ISBN-13 to ISBN-10'); > >- >diff --git a/t/ReportsGuided.t b/t/ReportsGuided.t >new file mode 100755 >index 0000000..aa97740 >--- /dev/null >+++ b/t/ReportsGuided.t >@@ -0,0 +1,111 @@ >+#!/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 >+ ); >+ >+ my $reserved_authorised_values = GetReservedAuthorisedValues(); >+ is_deeply(\%test_authval, $reserved_authorised_values, >+ 'GetReservedAuthorisedValues returns a fixed list'); >+} >+ >+SKIP: { >+ >+ skip "DBD::Mock is too old", 6 >+ 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'); >+} >+ >-- >1.7.9.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 9659
:
15560
|
15596
|
15603
|
15618
|
15621
|
15626
|
17351
|
17652
|
17660
|
17661