63789fc095
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>
244 lines
9.8 KiB
Perl
244 lines
9.8 KiB
Perl
#!/usr/bin/perl
|
|
#
|
|
# This Koha test module is a stub!
|
|
# Add more tests here!!!
|
|
|
|
use Modern::Perl;
|
|
use YAML;
|
|
|
|
use CGI;
|
|
use C4::Serials;
|
|
use C4::Serials::Frequency;
|
|
use C4::Serials::Numberpattern;
|
|
use C4::Debug;
|
|
use C4::Bookseller;
|
|
use C4::Biblio;
|
|
use C4::Budgets;
|
|
use Koha::DateUtils;
|
|
use Test::More tests => 44;
|
|
|
|
BEGIN {
|
|
use_ok('C4::Serials');
|
|
}
|
|
|
|
my $dbh = C4::Context->dbh;
|
|
|
|
# Start transaction
|
|
$dbh->{AutoCommit} = 0;
|
|
$dbh->{RaiseError} = 1;
|
|
|
|
my $booksellerid = C4::Bookseller::AddBookseller(
|
|
{
|
|
name => "my vendor",
|
|
address1 => "bookseller's address",
|
|
phone => "0123456",
|
|
active => 1
|
|
}
|
|
);
|
|
|
|
my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, '');
|
|
|
|
my $budgetid;
|
|
my $bpid = AddBudgetPeriod({
|
|
budget_period_startdate => '01-01-2015',
|
|
budget_period_enddate => '31-12-2015',
|
|
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 $frequency_id = AddSubscriptionFrequency({ description => "Test frequency 1" });
|
|
my $pattern_id = AddSubscriptionNumberpattern({
|
|
label => 'Test numberpattern 1',
|
|
numberingmethod => '{X}',
|
|
label1 => q{},
|
|
add1 => 1,
|
|
every1 => 1,
|
|
every1 => 1,
|
|
numbering1 => 1,
|
|
whenmorethan1 => 1,
|
|
});
|
|
|
|
my $subscriptionid = NewSubscription(
|
|
undef, "", undef, undef, $budget_id, $biblionumber,
|
|
'2013-01-01', $frequency_id, undef, undef, undef,
|
|
undef, undef, undef, undef, undef, undef,
|
|
1, "notes",undef, '2013-01-01', undef, $pattern_id,
|
|
undef, undef, 0, "intnotes", 0,
|
|
undef, undef, 0, undef, '2013-12-31', 0
|
|
);
|
|
|
|
my $subscriptioninformation = GetSubscription( $subscriptionid );
|
|
|
|
my @subscriptions = GetSubscriptions( $$subscriptioninformation{bibliotitle} );
|
|
isa_ok( \@subscriptions, 'ARRAY' );
|
|
|
|
@subscriptions = GetSubscriptions( undef, $$subscriptioninformation{issn} );
|
|
isa_ok( \@subscriptions, 'ARRAY' );
|
|
|
|
@subscriptions = GetSubscriptions( undef, undef, $$subscriptioninformation{ean} );
|
|
isa_ok( \@subscriptions, 'ARRAY' );
|
|
|
|
@subscriptions = GetSubscriptions( undef, undef, undef, $$subscriptioninformation{bibnum} );
|
|
isa_ok( \@subscriptions, 'ARRAY' );
|
|
|
|
my $frequency = GetSubscriptionFrequency($subscriptioninformation->{periodicity});
|
|
my $old_frequency;
|
|
if (not $frequency->{unit}) {
|
|
$old_frequency = $frequency->{id};
|
|
$frequency->{unit} = "month";
|
|
$frequency->{unitsperissue} = 1;
|
|
$frequency->{issuesperunit} = 1;
|
|
$frequency->{description} = "Frequency created by t/db_dependant/Serials.t";
|
|
$subscriptioninformation->{periodicity} = AddSubscriptionFrequency($frequency);
|
|
|
|
ModSubscription( @$subscriptioninformation{qw(
|
|
librarian branchcode aqbooksellerid cost aqbudgetid startdate
|
|
periodicity firstacquidate irregularity numberpattern locale
|
|
numberlength weeklength monthlength lastvalue1 innerloop1 lastvalue2
|
|
innerloop2 lastvalue3 innerloop3 status biblionumber callnumber notes
|
|
letter manualhistory internalnotes serialsadditems staffdisplaycount
|
|
opacdisplaycount graceperiod location enddate subscriptionid
|
|
skip_serialseq
|
|
)} );
|
|
}
|
|
my $expirationdate = GetExpirationDate($subscriptionid) ;
|
|
ok( $expirationdate, "expiration date is not NULL" );
|
|
|
|
is(C4::Serials::GetLateIssues(), undef, 'test getting late issues');
|
|
|
|
ok(C4::Serials::GetSubscriptionHistoryFromSubscriptionId($subscriptionid), 'test getting history from sub-scription');
|
|
|
|
my ($serials_count, @serials) = GetSerials($subscriptionid);
|
|
ok($serials_count > 0, 'Subscription has at least one serial');
|
|
my $serial = $serials[0];
|
|
|
|
ok(C4::Serials::GetSerialStatusFromSerialId($serial->{serialid}), 'test getting Serial Status From Serial Id');
|
|
|
|
isa_ok(C4::Serials::GetSerialInformation($serial->{serialid}), 'HASH', 'test getting Serial Information');
|
|
|
|
# Delete created frequency
|
|
if ($old_frequency) {
|
|
my $freq_to_delete = $subscriptioninformation->{periodicity};
|
|
$subscriptioninformation->{periodicity} = $old_frequency;
|
|
|
|
ModSubscription( @$subscriptioninformation{qw(
|
|
librarian branchcode aqbooksellerid cost aqbudgetid startdate
|
|
periodicity firstacquidate irregularity numberpattern locale
|
|
numberlength weeklength monthlength lastvalue1 innerloop1 lastvalue2
|
|
innerloop2 lastvalue3 innerloop3 status biblionumber callnumber notes
|
|
letter manualhistory internalnotes serialsadditems staffdisplaycount
|
|
opacdisplaycount graceperiod location enddate subscriptionid
|
|
skip_serialseq
|
|
)} );
|
|
|
|
DelSubscriptionFrequency($freq_to_delete);
|
|
}
|
|
|
|
|
|
# Test calling subs without parameters
|
|
is(C4::Serials::AddItem2Serial(), undef, 'test adding item to serial');
|
|
is(C4::Serials::UpdateClaimdateIssues(), undef, 'test updating claim date');
|
|
is(C4::Serials::GetFullSubscription(), undef, 'test getting full subscription');
|
|
is(C4::Serials::PrepareSerialsData(), undef, 'test preparing serial data');
|
|
is(C4::Serials::GetSubscriptionsFromBiblionumber(), undef, 'test getting subscriptions form biblio number');
|
|
|
|
is(C4::Serials::GetSerials(), undef, 'test getting serials when you enter nothing');
|
|
is(C4::Serials::GetSerials2(), undef, 'test getting serials when you enter nothing');
|
|
|
|
is(C4::Serials::GetLatestSerials(), undef, 'test getting lastest serials');
|
|
|
|
is(C4::Serials::GetDistributedTo(), undef, 'test getting distributed when nothing is entered');
|
|
|
|
is(C4::Serials::GetNextSeq(), undef, 'test getting next seq when you enter nothing');
|
|
|
|
is(C4::Serials::GetSeq(), undef, 'test getting seq when you enter nothing');
|
|
|
|
is(C4::Serials::CountSubscriptionFromBiblionumber(), undef, 'test counting subscription when nothing is entered');
|
|
|
|
is(C4::Serials::ModSubscriptionHistory(), undef, 'test modding subscription history');
|
|
|
|
is(C4::Serials::ModSerialStatus(),undef, 'test modding serials');
|
|
|
|
is(C4::Serials::NewIssue(), undef, 'test getting 0 when nothing is entered');
|
|
|
|
is(C4::Serials::ItemizeSerials(),undef, 'test getting nothing when nothing is entered');
|
|
|
|
is(C4::Serials::HasSubscriptionStrictlyExpired(), undef, 'test if the subscriptions has expired');
|
|
is(C4::Serials::HasSubscriptionExpired(), undef, 'test if the subscriptions has expired');
|
|
|
|
is(C4::Serials::GetLateOrMissingIssues(), undef, 'test getting last or missing issues');
|
|
|
|
is(C4::Serials::removeMissingIssue(), undef, 'test removing a missing issue');
|
|
|
|
is(C4::Serials::updateClaim(),undef, 'test updating claim');
|
|
|
|
is(C4::Serials::getsupplierbyserialid(),undef, 'test getting supplier idea');
|
|
|
|
is(C4::Serials::check_routing(), undef, 'test checking route');
|
|
|
|
is(C4::Serials::addroutingmember(),undef, 'test adding route member');
|
|
|
|
|
|
# Unit tests for statuses management (Bug 11689)
|
|
$subscriptionid = NewSubscription(
|
|
undef, "", undef, undef, $budget_id, $biblionumber,
|
|
'2013-01-01', $frequency_id, undef, undef, undef,
|
|
undef, undef, undef, undef, undef, undef,
|
|
1, "notes",undef, '2013-01-01', undef, $pattern_id,
|
|
undef, undef, 0, "intnotes", 0,
|
|
undef, undef, 0, undef, '2013-12-31', 0
|
|
);
|
|
my $total_issues;
|
|
( $total_issues, @serials ) = C4::Serials::GetSerials( $subscriptionid );
|
|
is( $total_issues, 1, "NewSubscription created a first serial" );
|
|
is( @serials, 1, "GetSerials returns the serial" );
|
|
my $subscription = C4::Serials::GetSubscription($subscriptionid);
|
|
my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subscription->{numberpattern});
|
|
( $total_issues, @serials ) = C4::Serials::GetSerials( $subscriptionid );
|
|
my $publisheddate = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
|
|
( $total_issues, @serials ) = C4::Serials::GetSerials( $subscriptionid );
|
|
my $nextpublisheddate = C4::Serials::GetNextDate($subscription, $publisheddate, 1);
|
|
my @statuses = qw( 2 2 3 3 3 3 3 4 4 41 42 43 44 5 );
|
|
# Add 14 serials
|
|
my $counter = 0;
|
|
for my $status ( @statuses ) {
|
|
my $serialseq = "No.".$counter;
|
|
my ( $expected_serial ) = GetSerials2( $subscriptionid, 1 );
|
|
C4::Serials::ModSerialStatus( $expected_serial->{serialid}, $serialseq, $publisheddate, $publisheddate, $statuses[$counter], 'an useless note' );
|
|
$counter++;
|
|
}
|
|
# Here we have 15 serials with statuses : 2*2 + 5*3 + 2*4 + 1*41 + 1*42 + 1*43 + 1*44 + 1*5 + 1*1
|
|
( $total_issues, @serials ) = C4::Serials::GetSerials( $subscriptionid );
|
|
is( $total_issues, @statuses + 1, "GetSerials returns total_issues" );
|
|
my @arrived_missing = map { my $status = $_->{status}; ( grep { /^$status$/ } qw( 2 4 41 42 43 44 5 ) ) ? $_ : () } @serials;
|
|
my @others = map { my $status = $_->{status}; ( grep { /^$status$/ } qw( 2 4 41 42 43 44 5 ) ) ? () : $_ } @serials;
|
|
is( @arrived_missing, 5, "GetSerials returns 5 arrived/missing by default" );
|
|
is( @others, 6, "GetSerials returns all serials not arrived and not missing" );
|
|
|
|
( $total_issues, @serials ) = C4::Serials::GetSerials( $subscriptionid, 10 );
|
|
is( $total_issues, @statuses + 1, "GetSerials returns total_issues" );
|
|
@arrived_missing = map { my $status = $_->{status}; ( grep { /^$status$/ } qw( 2 4 41 42 43 44 5 ) ) ? $_ : () } @serials;
|
|
@others = map { my $status = $_->{status}; ( grep { /^$status$/ } qw( 2 4 41 42 43 44 5 ) ) ? () : $_ } @serials;
|
|
is( @arrived_missing, 9, "GetSerials returns all arrived/missing if count given" );
|
|
is( @others, 6, "GetSerials returns all serials not arrived and not missing if count given" );
|
|
|
|
$subscription = C4::Serials::GetSubscription($subscriptionid); # Retrieve the updated subscription
|
|
|
|
my @serialseqs;
|
|
for my $am ( @arrived_missing ) {
|
|
if ( grep {/^$am->{status}$/} qw( 4 41 42 43 44 ) ) {
|
|
push @serialseqs, $am->{serialseq}
|
|
} elsif ( grep {/^$am->{status}$/} qw( 5 ) ) {
|
|
push @serialseqs, 'not issued ' . $am->{serialseq};
|
|
}
|
|
}
|
|
is( $subscription->{missinglist}, join('; ', @serialseqs), "subscription missinglist is updated after ModSerialStatus" );
|
|
|
|
$dbh->rollback;
|