Koha/t/db_dependent/Serials_2.t
Yohann Dufour 63789fc095 Bug 12482: removing the use of the module C4::SQLHelper.pm, it is replaced by DBIx::Class
This patch includes:
- removing the use of subroutines InsertInTable, UpdateInTable, SearchInTable replaced by subroutines of DBIx::Class in the subroutines AddBudget, ModBudget, GetBudgets, AddBudgetPeriods, ModBudgetPeriod and GetBudgetPeriods and admin/aqbudgetperiods.pl
- removing old database fields in OrderFromSubscription.t, Bookseller.t, Budgets.t, Serials.t, Serials_2.t
- improvement of unit tests in t/db_dependent/Budgets.t
- adaptation of calls to the subroutines AddBudget, ModBudget, GetBudgets, AddBudgetPeriods, ModBudgetPeriod and GetBudgetPeriods in order to match with the use of DBIx::Class

Test plan:

1) Execute the UT of all of files wich uses AddBudget, ModBudget, GetBudgets, AddBudgetPeriods, ModBudgetPeriod or GetBudgetPeriods by launching the command :
prove t/Budgets/ t/Budgets.t t/db_dependent/Budgets.t t/db_dependent/Acquisition.t t/db_dependent/Acquisition/ t/db_dependent/Bookseller.t t/db_dependent/Serials.t t/db_dependent/Serials_2.t

2) The result has to be a success :
t/Budgets/CanUserModifyBudget.t ........................... ok
t/Budgets/CanUserUseBudget.t .............................. ok
t/Budgets.t ............................................... ok
t/db_dependent/Budgets.t .................................. ok
t/db_dependent/Acquisition.t .............................. ok
t/db_dependent/Acquisition/GetBasketsInfosByBookseller.t .. ok
t/db_dependent/Acquisition/GetOrdersByBiblionumber.t ...... ok
t/db_dependent/Acquisition/Invoices.t ..................... ok
t/db_dependent/Acquisition/OrderFromSubscription.t ........ ok
t/db_dependent/Acquisition/TransferOrder.t ................ 1/11 # Transfering order to basket2
t/db_dependent/Acquisition/TransferOrder.t ................ ok
t/db_dependent/Acquisition/close_reopen_basket.t .......... ok
t/db_dependent/Bookseller.t ............................... 16/72 WARNING: GetBooksellerWithLateOrders is called with a negative value at /home/yohann/koha/C4/Bookseller.pm line 135.
t/db_dependent/Bookseller.t ............................... ok
t/db_dependent/Serials.t .................................. ok
t/db_dependent/Serials_2.t ................................ ok
All tests successful.
Files=14, Tests=571, 22 wallclock secs ( 0.17 usr  0.03 sys + 20.26 cusr  1.10 csys = 21.56 CPU)
Result: PASS

3) Go on the page admin/aqbudgetperiods.pl : Koha Administration > Budgets
4) Click on the button "New Budget" and record a new budget with a "nonzero amount" and "make budget active"
5) Click on the button "New Budget" and record another budget without "make budget active"
6) Verify there is the firt budget displayed in "Active budgets" and the second budget in "Inactive budgets"
7) Edit a budget and verify the new values are updated
8) Click on the budget active name in order to go on the page admin/aqbudgets.pl
9) Click on the button "New fund for ..." and record a new fund
10) Click on the button "Edit" then "Duplicate budget ..." in order to duplicate the budget
11) Verify there are two budgets in "Active Budgets" and one in "Inactive Budgets"
12) Click on "Funds" in the menu and verify there are two identical funds and each is associated to a different budget.

Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
2014-07-03 14:24:58 -03:00

249 lines
9.6 KiB
Perl

#!/usr/bin/perl
use Modern::Perl;
use Test::More tests => 37;
use MARC::Record;
use C4::Biblio qw( AddBiblio );
use C4::Members qw( AddMember );
use t::lib::Mocks;
use_ok('C4::Serials');
use_ok('C4::Budgets');
# Mock userenv
local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /redefined/ };
my $userenv;
*C4::Context::userenv = \&Mock_userenv;
my $dbh = C4::Context->dbh;
$dbh->{AutoCommit} = 0;
$dbh->{RaiseError} = 1;
my $supplierlist=eval{GetSuppliersWithLateIssues()};
ok(length($@)==0,"No SQL problem in GetSuppliersWithLateIssues");
my $record = MARC::Record->new();
$record->append_fields(
MARC::Field->new( '952', '0', '0', a => 'CPL', b => 'CPL' )
);
my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio($record, '');
my $my_branch = 'CPL';
my $another_branch = 'MPL';
my $budgetid;
my $bpid = AddBudgetPeriod({
budget_period_startdate => '2015-01-01',
budget_period_enddate => '2015-12-31',
budget_period_description => "budget desc"
});
my $budget_id = AddBudget({
budget_code => "ABCD",
budget_amount => "123.132",
budget_name => "Périodiques",
budget_notes => "This is a note",
budget_period_id => $bpid
});
my $subscriptionid_from_my_branch = NewSubscription(
undef, $my_branch, undef, undef, $budget_id, $biblionumber,
'2013-01-01', undef, undef, undef, undef,
undef, undef, undef, undef, undef, undef,
1, "notes",undef, '2013-01-01', undef, undef,
undef, undef, 0, "intnotes", 0,
undef, undef, 0, undef, '2013-12-31', 0
);
die unless $subscriptionid_from_my_branch;
my $subscriptionid_from_another_branch = NewSubscription(
undef, $another_branch, undef, undef, $budget_id, $biblionumber,
'2013-01-01', undef, undef, undef, undef,
undef, undef, undef, undef, undef, undef,
1, "notes",undef, '2013-01-01', undef, undef,
undef, undef, 0, "intnotes", 0,
undef, undef, 0, undef, '2013-12-31', 0
);
my $subscription_from_my_branch = GetSubscription( $subscriptionid_from_my_branch );
is( C4::Serials::can_edit_subscription($subscription_from_my_branch), 0, "cannot edit a subscription without userenv set");
my $userid = 'my_userid';
my $borrowernumber = C4::Members::AddMember(
firstname => 'my fistname',
surname => 'my surname',
categorycode => 'S',
branchcode => $my_branch,
userid => $userid,
);
$userenv = { flags => 1, id => $borrowernumber, branch => '' };
# Can edit a subscription
is( C4::Serials::can_edit_subscription($subscription_from_my_branch), 1, "User can edit a subscription with an empty branchcode");
my $subscription_from_another_branch = GetSubscription( $subscriptionid_from_another_branch );
$userenv->{id} = $userid;
$userenv->{branch} = $my_branch;
# Branches are independent
t::lib::Mocks::mock_preference( "IndependentBranches", 1 );
set_flags( 'superlibrarian', $borrowernumber );
is( C4::Serials::can_edit_subscription($subscription_from_my_branch), 1,
"With IndependentBranches, superlibrarian can edit a subscription from his branch"
);
is( C4::Serials::can_edit_subscription($subscription_from_another_branch), 1,
"With IndependentBranches, superlibrarian can edit a subscription from another branch"
);
is( C4::Serials::can_show_subscription($subscription_from_my_branch), 1,
"With IndependentBranches, superlibrarian can show a subscription from his branch"
);
is( C4::Serials::can_show_subscription($subscription_from_another_branch), 1,
"With IndependentBranches, superlibrarian can show a subscription from another branch"
);
set_flags( 'superserials', $borrowernumber );
is( C4::Serials::can_edit_subscription($subscription_from_my_branch), 1,
"With IndependentBranches, superserials can edit a subscription from his branch"
);
is( C4::Serials::can_edit_subscription($subscription_from_another_branch), 1,
"With IndependentBranches, superserials can edit a subscription from another branch"
);
is( C4::Serials::can_show_subscription($subscription_from_my_branch), 1,
"With IndependentBranches, superserials can show a subscription from his branch"
);
is( C4::Serials::can_show_subscription($subscription_from_another_branch), 1,
"With IndependentBranches, superserials can show a subscription from another branch"
);
set_flags( 'edit_subscription', $borrowernumber );
is( C4::Serials::can_edit_subscription($subscription_from_my_branch), 1,
"With IndependentBranches, edit_subscription can edit a subscription from his branch"
);
is( C4::Serials::can_edit_subscription($subscription_from_another_branch), 0,
"With IndependentBranches, edit_subscription cannot edit a subscription from another branch"
);
is( C4::Serials::can_show_subscription($subscription_from_my_branch), 1,
"With IndependentBranches, show_subscription can show a subscription from his branch"
);
is( C4::Serials::can_show_subscription($subscription_from_another_branch), 0,
"With IndependentBranches, show_subscription cannot show a subscription from another branch"
);
set_flags( 'renew_subscription', $borrowernumber );
is( C4::Serials::can_edit_subscription($subscription_from_my_branch), 0,
"With IndependentBranches, renew_subscription cannot edit a subscription from his branch"
);
is( C4::Serials::can_edit_subscription($subscription_from_another_branch), 0,
"With IndependentBranches, renew_subscription cannot edit a subscription from another branch"
);
is( C4::Serials::can_show_subscription($subscription_from_my_branch), 1,
"With IndependentBranches, renew_subscription can show a subscription from his branch"
);
is( C4::Serials::can_show_subscription($subscription_from_another_branch), 0,
"With IndependentBranches, renew_subscription cannot show a subscription from another branch"
);
# Branches are not independent
t::lib::Mocks::mock_preference( "IndependentBranches", 0 );
set_flags( 'superlibrarian', $borrowernumber );
is( C4::Serials::can_edit_subscription($subscription_from_my_branch), 1,
"Without IndependentBranches, superlibrarian can edit a subscription from his branch"
);
is( C4::Serials::can_edit_subscription($subscription_from_another_branch), 1,
"Without IndependentBranches, superlibrarian can edit a subscription from another branch"
);
is( C4::Serials::can_show_subscription($subscription_from_my_branch), 1,
"Without IndependentBranches, superlibrarian can show a subscription from his branch"
);
is( C4::Serials::can_show_subscription($subscription_from_another_branch), 1,
"Without IndependentBranches, superlibrarian can show a subscription from another branch"
);
set_flags( 'superserials', $borrowernumber );
is( C4::Serials::can_edit_subscription($subscription_from_my_branch), 1,
"Without IndependentBranches, superserials can edit a subscription from his branch"
);
is( C4::Serials::can_edit_subscription($subscription_from_another_branch), 1,
"Without IndependentBranches, superserials can edit a subscription from another branch"
);
is( C4::Serials::can_show_subscription($subscription_from_my_branch), 1,
"Without IndependentBranches, superserials can show a subscription from his branch"
);
is( C4::Serials::can_show_subscription($subscription_from_another_branch), 1,
"Without IndependentBranches, superserials can show a subscription from another branch"
);
set_flags( 'edit_subscription', $borrowernumber );
is( C4::Serials::can_edit_subscription($subscription_from_my_branch), 1,
"Without IndependentBranches, edit_subscription can edit a subscription from his branch"
);
is( C4::Serials::can_edit_subscription($subscription_from_another_branch), 1,
"Without IndependentBranches, edit_subscription can edit a subscription from another branch"
);
is( C4::Serials::can_show_subscription($subscription_from_my_branch), 1,
"Without IndependentBranches, show_subscription can show a subscription from his branch"
);
is( C4::Serials::can_show_subscription($subscription_from_another_branch), 1,
"Without IndependentBranches, show_subscription can show a subscription from another branch"
);
set_flags( 'renew_subscription', $borrowernumber );
is( C4::Serials::can_edit_subscription($subscription_from_my_branch), 0,
"Without IndependentBranches, renew_subscription cannot edit a subscription from his branch"
);
is( C4::Serials::can_edit_subscription($subscription_from_another_branch), 0,
"Without IndependentBranches, renew_subscription cannot edit a subscription from another branch"
);
is( C4::Serials::can_show_subscription($subscription_from_my_branch), 1,
"Without IndependentBranches, renew_subscription cannot show a subscription from his branch"
);
is( C4::Serials::can_show_subscription($subscription_from_another_branch), 1,
"Without IndependentBranches, renew_subscription cannot show a subscription from another branch"
);
$dbh->rollback;
# C4::Context->userenv
sub Mock_userenv {
return $userenv;
}
sub set_flags {
my ( $flags, $borrowernumber ) = @_;
my $superlibrarian_flags = 1;
if ( $flags eq 'superlibrarian' ) {
$dbh->do(
q|
UPDATE borrowers SET flags=? WHERE borrowernumber=?
|, {}, $superlibrarian_flags, $borrowernumber
);
$userenv->{flags} = $superlibrarian_flags;
}
else {
$dbh->do(
q|
UPDATE borrowers SET flags=? WHERE borrowernumber=?
|, {}, 0, $borrowernumber
);
$userenv->{flags} = 0;
my ( $module_bit, $code ) = ( '15', $flags );
$dbh->do(
q|
DELETE FROM user_permissions where borrowernumber=?
|, {}, $borrowernumber
);
$dbh->do(
q|
INSERT INTO user_permissions( borrowernumber, module_bit, code ) VALUES ( ?, ?, ? )
|, {}, $borrowernumber, $module_bit, $code
);
}
}