Bugzilla – Attachment 50027 Details for
Bug 12787
Unit test files should be better organized
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 12787: Reorganise t/db_dependent files
Bug-12787-Reorganise-tdbdependent-files.patch (text/plain), 31.17 KB, created by
Jonathan Druart
on 2016-04-07 13:26:02 UTC
(
hide
)
Description:
Bug 12787: Reorganise t/db_dependent files
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2016-04-07 13:26:02 UTC
Size:
31.17 KB
patch
obsolete
>From cdae5c8a88f8648dbb0c95ecf324975da6083b63 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 7 Apr 2016 13:29:16 +0100 >Subject: [PATCH] Bug 12787: Reorganise t/db_dependent files > >This patch tries to reorganise test files in the db_dependent directory: >- Circulation_Branch.t has been moved to Circulation/Branch.t >- Circulation_issuingrules.t has been moved to Circulation/CalcDateDue.t >- Circulation_Issuingrule.t has been moved to Circulation/GetHardDueDate.t >- Circulation_dateexpiry.t has been moved to Circulation/dateexpiry.t >- Circulation_issue.t has been moved to Circulation/issue.t >- Circulation_transfers.t has been moved to Circulation/transfers.t >- Items_DelItem.t has been moved to Items/DelItem.t >- BiblioObject.t has been moved to Koha/Biblio.t >- Members_Attributes.t has been moved to Members/Attributes.t >- Members_columns.t has been moved to Members/columns.t >- Circulation_OfflineOperation.t has been moved to Circulation/OfflineOperation.t >- Koha_template_plugin_KohaDates.t has been moved to Template/Plugin/KohaDates.t >- Koha_template_plugin_Branches.t has been moved to Template/Plugin/Branches.t >- Reports/Guided.t, ReportsGuided.t and Reports_Guided.t have been > merged > >Test plan: >Confirm that all the modified tests still pass >--- > .../{Circulation_Branch.t => Circulation/Branch.t} | 0 > .../CalcDateDue.t} | 25 +- > .../GetHardDueDate.t} | 0 > .../OfflineOperation.t} | 0 > .../dateexpiry.t} | 0 > .../{Circulation_issue.t => Circulation/issue.t} | 0 > .../transfers.t} | 0 > .../{Items_DelItem.t => Items/DelItem.t} | 0 > t/db_dependent/{BiblioObject.t => Koha/Biblio.t} | 0 > t/db_dependent/Koha_template_plugin_Branches.t | 57 ---- > .../{Members_Attributes.t => Members/Attributes.t} | 0 > .../{Members_columns.t => Members/columns.t} | 0 > t/db_dependent/Reports/Guided.t | 304 ++++++++++++++++----- > t/db_dependent/ReportsGuided.t | 85 ------ > t/db_dependent/Reports_Guided.t | 124 --------- > t/db_dependent/Template/Plugin/Branches.t | 28 +- > .../Plugin/KohaDates.t} | 0 > 17 files changed, 266 insertions(+), 357 deletions(-) > rename t/db_dependent/{Circulation_Branch.t => Circulation/Branch.t} (100%) > rename t/db_dependent/{Circulation_issuingrules.t => Circulation/CalcDateDue.t} (80%) > rename t/db_dependent/{Circulation_Issuingrule.t => Circulation/GetHardDueDate.t} (100%) > rename t/db_dependent/{Circulation_OfflineOperation.t => Circulation/OfflineOperation.t} (100%) > rename t/db_dependent/{Circulation_dateexpiry.t => Circulation/dateexpiry.t} (100%) > rename t/db_dependent/{Circulation_issue.t => Circulation/issue.t} (100%) > rename t/db_dependent/{Circulation_transfers.t => Circulation/transfers.t} (100%) > rename t/db_dependent/{Items_DelItem.t => Items/DelItem.t} (100%) > rename t/db_dependent/{BiblioObject.t => Koha/Biblio.t} (100%) > delete mode 100644 t/db_dependent/Koha_template_plugin_Branches.t > rename t/db_dependent/{Members_Attributes.t => Members/Attributes.t} (100%) > mode change 100755 => 100644 > rename t/db_dependent/{Members_columns.t => Members/columns.t} (100%) > delete mode 100755 t/db_dependent/ReportsGuided.t > delete mode 100755 t/db_dependent/Reports_Guided.t > rename t/db_dependent/{Koha_template_plugin_KohaDates.t => Template/Plugin/KohaDates.t} (100%) > >diff --git a/t/db_dependent/Circulation_Branch.t b/t/db_dependent/Circulation/Branch.t >similarity index 100% >rename from t/db_dependent/Circulation_Branch.t >rename to t/db_dependent/Circulation/Branch.t >diff --git a/t/db_dependent/Circulation_issuingrules.t b/t/db_dependent/Circulation/CalcDateDue.t >similarity index 80% >rename from t/db_dependent/Circulation_issuingrules.t >rename to t/db_dependent/Circulation/CalcDateDue.t >index c2508c6..a0a5b8b 100644 >--- a/t/db_dependent/Circulation_issuingrules.t >+++ b/t/db_dependent/Circulation/CalcDateDue.t >@@ -2,7 +2,7 @@ > > use Modern::Perl; > >-use Test::More tests => 7; >+use Test::More tests => 5; > use Test::MockModule; > use DBI; > use DateTime; >@@ -20,18 +20,6 @@ my $issuelength = 10; > my $renewalperiod = 5; > my $lengthunit = 'days'; > >-my $expected = { >- issuelength => $issuelength, >- renewalperiod => $renewalperiod, >- lengthunit => $lengthunit >-}; >- >-my $default = { >- issuelength => 0, >- renewalperiod => 0, >- lengthunit => 'days' >-}; >- > my $loanlength; > my $mock_undef = [ > [] >@@ -46,17 +34,6 @@ my $categorycode = 'B'; > my $itemtype = 'MX'; > my $branchcode = 'FPL'; > >-#=== GetLoanLength >-$dbh->{mock_add_resultset} = $mock_loan_length; >-$loanlength = C4::Circulation::GetLoanLength($categorycode, $itemtype, $branchcode); >-is_deeply($loanlength, $expected, 'first matches'); >- >-$dbh->{mock_add_resultset} = $mock_undef; >-$loanlength = C4::Circulation::GetLoanLength($categorycode, $itemtype, $branchcode); >-is_deeply($loanlength, $default, 'none matches'); >- >-#=== CalcDateDue >- > #Set syspref ReturnBeforeExpiry = 1 and useDaysMode = 'Days' > t::lib::Mocks::mock_preference('ReturnBeforeExpiry', 1); > t::lib::Mocks::mock_preference('useDaysMode', 'Days'); >diff --git a/t/db_dependent/Circulation_Issuingrule.t b/t/db_dependent/Circulation/GetHardDueDate.t >similarity index 100% >rename from t/db_dependent/Circulation_Issuingrule.t >rename to t/db_dependent/Circulation/GetHardDueDate.t >diff --git a/t/db_dependent/Circulation_OfflineOperation.t b/t/db_dependent/Circulation/OfflineOperation.t >similarity index 100% >rename from t/db_dependent/Circulation_OfflineOperation.t >rename to t/db_dependent/Circulation/OfflineOperation.t >diff --git a/t/db_dependent/Circulation_dateexpiry.t b/t/db_dependent/Circulation/dateexpiry.t >similarity index 100% >rename from t/db_dependent/Circulation_dateexpiry.t >rename to t/db_dependent/Circulation/dateexpiry.t >diff --git a/t/db_dependent/Circulation_issue.t b/t/db_dependent/Circulation/issue.t >similarity index 100% >rename from t/db_dependent/Circulation_issue.t >rename to t/db_dependent/Circulation/issue.t >diff --git a/t/db_dependent/Circulation_transfers.t b/t/db_dependent/Circulation/transfers.t >similarity index 100% >rename from t/db_dependent/Circulation_transfers.t >rename to t/db_dependent/Circulation/transfers.t >diff --git a/t/db_dependent/Items_DelItem.t b/t/db_dependent/Items/DelItem.t >similarity index 100% >rename from t/db_dependent/Items_DelItem.t >rename to t/db_dependent/Items/DelItem.t >diff --git a/t/db_dependent/BiblioObject.t b/t/db_dependent/Koha/Biblio.t >similarity index 100% >rename from t/db_dependent/BiblioObject.t >rename to t/db_dependent/Koha/Biblio.t >diff --git a/t/db_dependent/Koha_template_plugin_Branches.t b/t/db_dependent/Koha_template_plugin_Branches.t >deleted file mode 100644 >index af055ad..0000000 >--- a/t/db_dependent/Koha_template_plugin_Branches.t >+++ /dev/null >@@ -1,57 +0,0 @@ >-#!/usr/bin/perl >- >-# Copyright 2013-2014 Equinox Software, Inc. >-# >-# This file is part of Koha. >-# >-# Koha is free software; you can redistribute it and/or modify it under the >-# terms of the GNU General Public License as published by the Free Software >-# Foundation; either version 3 of the License, or (at your option) any later >-# version. >-# >-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >-# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >-# >-# You should have received a copy of the GNU General Public License along >-# with Koha; if not, see <http://www.gnu.org/licenses>. >- >-use Modern::Perl; >- >-use Test::More tests => 7; >- >-use C4::Context; >-use Koha::Database; >- >-use t::lib::TestBuilder; >- >-BEGIN { >- use_ok('Koha::Template::Plugin::Branches'); >-} >- >-my $schema = Koha::Database->schema; >-$schema->storage->txn_begin; >-my $builder = t::lib::TestBuilder->new; >-my $library = $builder->build({ >- source => 'Branch', >-}); >- >-my $plugin = Koha::Template::Plugin::Branches->new(); >-ok($plugin, "initialized Branches plugin"); >- >-my $name = $plugin->GetName($library->{branchcode}); >-is($name, $library->{branchname}, 'retrieved expected name for library'); >- >-$name = $plugin->GetName('__ANY__'); >-is($name, '', 'received empty string as name of the "__ANY__" placeholder library code'); >- >-$name = $plugin->GetName(undef); >-is($name, '', 'received empty string as name of NULL/undefined library code'); >- >-$library = $plugin->GetLoggedInBranchcode(); >-is($library, '', 'no active library if there is no active user session'); >- >-C4::Context->_new_userenv('DUMMY_SESSION_ID'); >-C4::Context->set_userenv(123, 'userid', 'usercnum', 'First name', 'Surname', 'MYLIBRARY', 'My Library', 0); >-$library = $plugin->GetLoggedInBranchcode(); >-is($library, 'MYLIBRARY', 'GetLoggedInBranchcode() returns active library'); >diff --git a/t/db_dependent/Members_Attributes.t b/t/db_dependent/Members/Attributes.t >old mode 100755 >new mode 100644 >similarity index 100% >rename from t/db_dependent/Members_Attributes.t >rename to t/db_dependent/Members/Attributes.t >diff --git a/t/db_dependent/Members_columns.t b/t/db_dependent/Members/columns.t >similarity index 100% >rename from t/db_dependent/Members_columns.t >rename to t/db_dependent/Members/columns.t >diff --git a/t/db_dependent/Reports/Guided.t b/t/db_dependent/Reports/Guided.t >index 506acee..0e39710 100644 >--- a/t/db_dependent/Reports/Guided.t >+++ b/t/db_dependent/Reports/Guided.t >@@ -1,4 +1,5 @@ > # Copyright 2012 Catalyst IT Ltd. >+# Copyright 2015 Koha Development team > # > # This file is part of Koha. > # >@@ -15,75 +16,252 @@ > # You should have received a copy of the GNU General Public License > # along with Koha; if not, see <http://www.gnu.org/licenses>. > >-use strict; >-use warnings; >+use Modern::Perl; > >-use Test::More tests => 19; # last test to print >+use Test::More tests => 7; >+use Test::Warn; >+ >+use t::lib::TestBuilder; >+use C4::Context; >+use Koha::Database; > > use_ok('C4::Reports::Guided'); >+can_ok( >+ 'C4::Reports::Guided', >+ qw(save_report delete_report execute_query) >+); >+ >+my $schema = Koha::Database->new->schema; >+$schema->storage->txn_begin; >+my $builder = t::lib::TestBuilder->new; > >-# This is the query I found that triggered bug 8594. >-my $sql = "SELECT aqorders.ordernumber, biblio.title, biblio.biblionumber, items.homebranch, >- aqorders.entrydate, aqorders.datereceived, >- (SELECT DATE(datetime) FROM statistics >- WHERE itemnumber=items.itemnumber AND >- (type='return' OR type='issue') LIMIT 1) >- AS shelvedate, >- DATEDIFF(COALESCE( >+subtest 'strip_limit' => sub { >+ # This is the query I found that triggered bug 8594. >+ my $sql = "SELECT aqorders.ordernumber, biblio.title, biblio.biblionumber, items.homebranch, >+ aqorders.entrydate, aqorders.datereceived, > (SELECT DATE(datetime) FROM statistics > WHERE itemnumber=items.itemnumber AND >- (type='return' OR type='issue') LIMIT 1), >- aqorders.datereceived), aqorders.entrydate) AS totaldays >-FROM aqorders >-LEFT JOIN biblio USING (biblionumber) >-LEFT JOIN items ON (items.biblionumber = biblio.biblionumber >- AND dateaccessioned=aqorders.datereceived) >-WHERE (entrydate >= '2011-01-01' AND (datereceived < '2011-02-01' OR datereceived IS NULL)) >- AND items.homebranch LIKE 'INFO' >-ORDER BY title"; >- >-my ($res_sql, $res_lim1, $res_lim2) = C4::Reports::Guided::strip_limit($sql); >-is($res_sql, $sql, "Not breaking subqueries"); >-is($res_lim1, 0, "Returns correct default offset"); >-is($res_lim2, undef, "Returns correct default LIMIT"); >- >-# Now the same thing, but we want it to remove the LIMIT from the end >- >-my $test_sql = $res_sql . " LIMIT 242"; >-($res_sql, $res_lim1, $res_lim2) = C4::Reports::Guided::strip_limit($test_sql); >-# The replacement drops a ' ' where the limit was >-is(trim($res_sql), $sql, "Correctly removes only final LIMIT"); >-is($res_lim1, 0, "Returns correct default offset"); >-is($res_lim2, 242, "Returns correct extracted LIMIT"); >- >-$test_sql = $res_sql . " LIMIT 13,242"; >-($res_sql, $res_lim1, $res_lim2) = C4::Reports::Guided::strip_limit($test_sql); >-# The replacement drops a ' ' where the limit was >-is(trim($res_sql), $sql, "Correctly removes only final LIMIT (with offset)"); >-is($res_lim1, 13, "Returns correct extracted offset"); >-is($res_lim2, 242, "Returns correct extracted LIMIT"); >- >-# After here is the simpler case, where there isn't a WHERE clause to worry >-# about. >- >-# First case with nothing to change >-$sql = "SELECT * FROM items"; >-($res_sql, $res_lim1, $res_lim2) = C4::Reports::Guided::strip_limit($sql); >-is($res_sql, $sql, "Not breaking simple queries"); >-is($res_lim1, 0, "Returns correct default offset"); >-is($res_lim2, undef, "Returns correct default LIMIT"); >- >-$test_sql = $sql . " LIMIT 242"; >-($res_sql, $res_lim1, $res_lim2) = C4::Reports::Guided::strip_limit($test_sql); >-is(trim($res_sql), $sql, "Correctly removes LIMIT in simple case"); >-is($res_lim1, 0, "Returns correct default offset"); >-is($res_lim2, 242, "Returns correct extracted LIMIT"); >- >-$test_sql = $sql . " LIMIT 13,242"; >-($res_sql, $res_lim1, $res_lim2) = C4::Reports::Guided::strip_limit($test_sql); >-is(trim($res_sql), $sql, "Correctly removes LIMIT in simple case (with offset)"); >-is($res_lim1, 13, "Returns correct extracted offset"); >-is($res_lim2, 242, "Returns correct extracted LIMIT"); >+ (type='return' OR type='issue') LIMIT 1) >+ AS shelvedate, >+ DATEDIFF(COALESCE( >+ (SELECT DATE(datetime) FROM statistics >+ WHERE itemnumber=items.itemnumber AND >+ (type='return' OR type='issue') LIMIT 1), >+ aqorders.datereceived), aqorders.entrydate) AS totaldays >+ FROM aqorders >+ LEFT JOIN biblio USING (biblionumber) >+ LEFT JOIN items ON (items.biblionumber = biblio.biblionumber >+ AND dateaccessioned=aqorders.datereceived) >+ WHERE (entrydate >= '2011-01-01' AND (datereceived < '2011-02-01' OR datereceived IS NULL)) >+ AND items.homebranch LIKE 'INFO' >+ ORDER BY title"; >+ >+ my ($res_sql, $res_lim1, $res_lim2) = C4::Reports::Guided::strip_limit($sql); >+ is($res_sql, $sql, "Not breaking subqueries"); >+ is($res_lim1, 0, "Returns correct default offset"); >+ is($res_lim2, undef, "Returns correct default LIMIT"); >+ >+ # Now the same thing, but we want it to remove the LIMIT from the end >+ >+ my $test_sql = $res_sql . " LIMIT 242"; >+ ($res_sql, $res_lim1, $res_lim2) = C4::Reports::Guided::strip_limit($test_sql); >+ # The replacement drops a ' ' where the limit was >+ is(trim($res_sql), $sql, "Correctly removes only final LIMIT"); >+ is($res_lim1, 0, "Returns correct default offset"); >+ is($res_lim2, 242, "Returns correct extracted LIMIT"); >+ >+ $test_sql = $res_sql . " LIMIT 13,242"; >+ ($res_sql, $res_lim1, $res_lim2) = C4::Reports::Guided::strip_limit($test_sql); >+ # The replacement drops a ' ' where the limit was >+ is(trim($res_sql), $sql, "Correctly removes only final LIMIT (with offset)"); >+ is($res_lim1, 13, "Returns correct extracted offset"); >+ is($res_lim2, 242, "Returns correct extracted LIMIT"); >+ >+ # After here is the simpler case, where there isn't a WHERE clause to worry >+ # about. >+ >+ # First case with nothing to change >+ $sql = "SELECT * FROM items"; >+ ($res_sql, $res_lim1, $res_lim2) = C4::Reports::Guided::strip_limit($sql); >+ is($res_sql, $sql, "Not breaking simple queries"); >+ is($res_lim1, 0, "Returns correct default offset"); >+ is($res_lim2, undef, "Returns correct default LIMIT"); >+ >+ $test_sql = $sql . " LIMIT 242"; >+ ($res_sql, $res_lim1, $res_lim2) = C4::Reports::Guided::strip_limit($test_sql); >+ is(trim($res_sql), $sql, "Correctly removes LIMIT in simple case"); >+ is($res_lim1, 0, "Returns correct default offset"); >+ is($res_lim2, 242, "Returns correct extracted LIMIT"); >+ >+ $test_sql = $sql . " LIMIT 13,242"; >+ ($res_sql, $res_lim1, $res_lim2) = C4::Reports::Guided::strip_limit($test_sql); >+ is(trim($res_sql), $sql, "Correctly removes LIMIT in simple case (with offset)"); >+ is($res_lim1, 13, "Returns correct extracted offset"); >+ is($res_lim2, 242, "Returns correct extracted LIMIT"); >+}; >+ >+$_->delete for Koha::AuthorisedValues->search({ category => 'XXX' }); >+Koha::AuthorisedValue->new({category => 'LOC'})->store; >+ >+subtest 'GetReservedAuthorisedValues' => sub { >+ plan tests => 1; >+ # 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'); >+}; >+ >+subtest 'IsAuthorisedValueValid' => sub { >+ plan tests => 8; >+ 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'); >+ } >+}; >+ >+subtest 'GetParametersFromSQL+ValidateSQLParameters' => sub { >+ plan tests => 3; >+ 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'); >+ >+ 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' >+ ); >+}; >+ >+subtest 'get_saved_reports' => sub { >+ plan tests => 16; >+ my $dbh = C4::Context->dbh; >+ $dbh->do(q|DELETE FROM saved_sql|); >+ $dbh->do(q|DELETE FROM saved_reports|); >+ >+ #Test save_report >+ my $count = scalar @{ get_saved_reports() }; >+ is( $count, 0, "There is no report" ); >+ >+ my @report_ids; >+ foreach ( 1..3 ) { >+ my $id = $builder->build({ source => 'Borrower' })->{ borrowernumber }; >+ push @report_ids, save_report({ >+ borrowernumber => $id, >+ sql => "SQL$id", >+ name => "Name$id", >+ area => "area$id", >+ group => "group$id", >+ subgroup => "subgroup$id", >+ type => "type$id", >+ notes => "note$id", >+ cache_expiry => "null", >+ public => "null" >+ }); >+ $count++; >+ } >+ like( $report_ids[0], '/^\d+$/', "Save_report returns an id for first" ); >+ like( $report_ids[1], '/^\d+$/', "Save_report returns an id for second" ); >+ like( $report_ids[2], '/^\d+$/', "Save_report returns an id for third" ); >+ >+ is( scalar @{ get_saved_reports() }, >+ $count, "$count reports have been added" ); >+ >+ is( scalar @{ get_saved_reports( $report_ids[0] ) }, >+ 1, "filter takes report id" ); >+ >+ #Test delete_report >+ is (delete_report(),undef, "Without id delete_report returns undef"); >+ >+ is( delete_report( $report_ids[0] ), 1, "report 1 is deleted" ); >+ $count--; >+ >+ is( scalar @{ get_saved_reports() }, $count, "Report1 has been deleted" ); >+ >+ is( delete_report( $report_ids[1], $report_ids[2] ), 2, "report 2 and 3 are deleted" ); >+ $count -= 2; >+ >+ is( scalar @{ get_saved_reports() }, >+ $count, "Report2 and report3 have been deleted" ); >+ >+ my $sth = execute_query('SELECT COUNT(*) FROM systempreferences', 0, 10); >+ my $results = $sth->fetchall_arrayref; >+ is(scalar @$results, 1, 'running a query returned a result'); >+ >+ my $version = C4::Context->preference('Version'); >+ $sth = execute_query( >+ 'SELECT value FROM systempreferences WHERE variable = ?', >+ 0, >+ 10, >+ [ 'Version' ], >+ ); >+ $results = $sth->fetchall_arrayref; >+ is_deeply( >+ $results, >+ [ [ $version ] ], >+ 'running a query with a parameter returned the expected result' >+ ); >+ >+ # for next test, we want to let execute_query capture any SQL errors >+ $dbh->{RaiseError} = 0; >+ my $errors; >+ warning_like { ($sth, $errors) = execute_query( >+ 'SELECT surname FRM borrowers', # error in the query is intentional >+ 0, 10 ) } >+ qr/^DBD::mysql::st execute failed: You have an error in your SQL syntax;/, >+ "Wrong SQL syntax raises warning"; >+ ok( >+ defined($errors) && exists($errors->{queryerr}), >+ 'attempting to run a report with an SQL syntax error returns error message (Bug 12214)' >+ ); >+ >+ is_deeply( get_report_areas(), [ 'CIRC', 'CAT', 'PAT', 'ACQ', 'ACC', 'SER' ], >+ "get_report_areas returns the correct array of report areas"); >+}; >+ >+$schema->storage->txn_rollback; > > sub trim { > my ($s) = @_; >diff --git a/t/db_dependent/ReportsGuided.t b/t/db_dependent/ReportsGuided.t >deleted file mode 100755 >index 40e49a8..0000000 >--- a/t/db_dependent/ReportsGuided.t >+++ /dev/null >@@ -1,85 +0,0 @@ >-#!/usr/bin/perl >- >-use Modern::Perl; >- >-use Test::More tests => 13; >- >-use Koha::Database; >- >-use_ok('C4::Reports::Guided'); >- >-my $schema = Koha::Database->new->schema; >-$schema->storage->txn_begin; >- >-$_->delete for Koha::AuthorisedValues->search({ category => 'XXX' }); >-Koha::AuthorisedValue->new({category => 'LOC'})->store; >- >-{ # 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'); >-} >- >-{ >- 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'); >-} >diff --git a/t/db_dependent/Reports_Guided.t b/t/db_dependent/Reports_Guided.t >deleted file mode 100755 >index 4d89ebd..0000000 >--- a/t/db_dependent/Reports_Guided.t >+++ /dev/null >@@ -1,124 +0,0 @@ >-#!/usr/bin/perl >- >-# This file is part of Koha. >-# >-# Koha is free software; you can redistribute it and/or modify it >-# under the terms of the GNU General Public License as published by >-# the Free Software Foundation; either version 3 of the License, or >-# (at your option) any later version. >-# >-# Koha is distributed in the hope that it will be useful, but >-# WITHOUT ANY WARRANTY; without even the implied warranty of >-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >-# GNU General Public License for more details. >-# >-# You should have received a copy of the GNU General Public License >-# along with Koha; if not, see <http://www.gnu.org/licenses>. >- >-use Modern::Perl; >- >-use Test::More tests => 18; >-use Test::Warn; >-use t::lib::TestBuilder; >- >-use C4::Context; >-use Koha::Database; >- >-BEGIN { >- use_ok('C4::Reports::Guided'); >-} >-can_ok( >- 'C4::Reports::Guided', >- qw(save_report delete_report execute_query) >-); >- >-my $schema = Koha::Database->new->schema; >-$schema->storage->txn_begin; >-my $builder = t::lib::TestBuilder->new; >- >-my $dbh = C4::Context->dbh; >-$dbh->do(q|DELETE FROM saved_sql|); >-$dbh->do(q|DELETE FROM saved_reports|); >- >-#Start tests >- >-#Test save_report >-my $count = scalar @{ get_saved_reports() }; >-is( $count, 0, "There is no report" ); >- >-my @report_ids; >-foreach ( 1..3 ) { >- my $id = $builder->build({ source => 'Borrower' })->{ borrowernumber }; >- push @report_ids, save_report({ >- borrowernumber => $id, >- sql => "SQL$id", >- name => "Name$id", >- area => "area$id", >- group => "group$id", >- subgroup => "subgroup$id", >- type => "type$id", >- notes => "note$id", >- cache_expiry => "null", >- public => "null" >- }); >- $count++; >-} >-like( $report_ids[0], '/^\d+$/', "Save_report returns an id for first" ); >-like( $report_ids[1], '/^\d+$/', "Save_report returns an id for second" ); >-like( $report_ids[2], '/^\d+$/', "Save_report returns an id for third" ); >- >-is( scalar @{ get_saved_reports() }, >- $count, "$count reports have been added" ); >- >-is( scalar @{ get_saved_reports( $report_ids[0] ) }, >- 1, "filter takes report id" ); >- >-#Test delete_report >-is (delete_report(),undef, "Without id delete_report returns undef"); >- >-is( delete_report( $report_ids[0] ), 1, "report 1 is deleted" ); >-$count--; >- >-is( scalar @{ get_saved_reports() }, $count, "Report1 has been deleted" ); >- >-is( delete_report( $report_ids[1], $report_ids[2] ), 2, "report 2 and 3 are deleted" ); >-$count -= 2; >- >-is( scalar @{ get_saved_reports() }, >- $count, "Report2 and report3 have been deleted" ); >- >-my $sth = execute_query('SELECT COUNT(*) FROM systempreferences', 0, 10); >-my $results = $sth->fetchall_arrayref; >-is(scalar @$results, 1, 'running a query returned a result'); >- >-my $version = C4::Context->preference('Version'); >-$sth = execute_query( >- 'SELECT value FROM systempreferences WHERE variable = ?', >- 0, >- 10, >- [ 'Version' ], >-); >-$results = $sth->fetchall_arrayref; >-is_deeply( >- $results, >- [ [ $version ] ], >- 'running a query with a parameter returned the expected result' >-); >- >-# for next test, we want to let execute_query capture any SQL errors >-$dbh->{RaiseError} = 0; >-my $errors; >-warning_like { ($sth, $errors) = execute_query( >- 'SELECT surname FRM borrowers', # error in the query is intentional >- 0, 10 ) } >- qr/^DBD::mysql::st execute failed: You have an error in your SQL syntax;/, >- "Wrong SQL syntax raises warning"; >-ok( >- defined($errors) && exists($errors->{queryerr}), >- 'attempting to run a report with an SQL syntax error returns error message (Bug 12214)' >-); >- >-is_deeply( get_report_areas(), [ 'CIRC', 'CAT', 'PAT', 'ACQ', 'ACC', 'SER' ], >- "get_report_areas returns the correct array of report areas"); >- >-$schema->storage->txn_rollback; >diff --git a/t/db_dependent/Template/Plugin/Branches.t b/t/db_dependent/Template/Plugin/Branches.t >index fb276f3..978340a 100644 >--- a/t/db_dependent/Template/Plugin/Branches.t >+++ b/t/db_dependent/Template/Plugin/Branches.t >@@ -1,9 +1,10 @@ > use Modern::Perl; > >-use Test::More tests => 5; >+use Test::More tests => 11; > > use C4::Context; > use Koha::Library; >+use Koha::Libraries; > use Koha::Template::Plugin::Branches; > > my $dbh = C4::Context->dbh; >@@ -17,16 +18,35 @@ for my $i ( 1 .. 5 ) { > branchname => "test_br_$i", > } > )->store; >- > } >+my $library = Koha::Libraries->search->next->unblessed; >+ >+my $plugin = Koha::Template::Plugin::Branches->new(); >+ok($plugin, "initialized Branches plugin"); >+ >+my $name = $plugin->GetName($library->{branchcode}); >+is($name, $library->{branchname}, 'retrieved expected name for library'); >+ >+$name = $plugin->GetName('__ANY__'); >+is($name, '', 'received empty string as name of the "__ANY__" placeholder library code'); >+ >+$name = $plugin->GetName(undef); >+is($name, '', 'received empty string as name of NULL/undefined library code'); >+ >+$library = $plugin->GetLoggedInBranchcode(); >+is($library, '', 'no active library if there is no active user session'); >+C4::Context->_new_userenv('DUMMY_SESSION_ID'); >+C4::Context->set_userenv(123, 'userid', 'usercnum', 'First name', 'Surname', 'MYLIBRARY', 'My Library', 0); >+$library = $plugin->GetLoggedInBranchcode(); >+is($library, 'MYLIBRARY', 'GetLoggedInBranchcode() returns active library'); > >-my $branches = Koha::Template::Plugin::Branches->new->all; >+my $branches = $plugin->all; > my $test_branches = [ grep { $_->{branchcode} =~ m|^test_br_| } @$branches ]; > is( scalar( @$test_branches ), 5, 'Plugin Branches should return the branches' ); > my $selected_branches = [ grep { $_->{selected} } @$branches ]; > is( scalar( @$selected_branches ), 0, 'Plugin Branches should not select a branch if not needed' ); > >-$branches = Koha::Template::Plugin::Branches->new->all({selected => 'test_br_3'}); >+$branches = $plugin->all({selected => 'test_br_3'}); > $test_branches = [ grep { $_->{branchcode} =~ m|^test_br_| } @$branches ]; > is( scalar( @$test_branches ), 5, 'Plugin Branches should return the branches if selected passed' ); > $selected_branches = [ grep { $_->{selected} } @$branches ]; >diff --git a/t/db_dependent/Koha_template_plugin_KohaDates.t b/t/db_dependent/Template/Plugin/KohaDates.t >similarity index 100% >rename from t/db_dependent/Koha_template_plugin_KohaDates.t >rename to t/db_dependent/Template/Plugin/KohaDates.t >-- >2.7.0
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 12787
:
50027
|
50033
|
50034
|
50521
|
50522
|
50523
|
50524