Koha/t/db_dependent/Serials/GetFictiveIssueNumber.t
Baptiste Wojtkowski cb01b25330 Bug 17047: SQL reports management with Mana-KB
Includes:

* code factorization
Some code from subscription & Mana-KB has been factorized in order to speed-up next developments

* SytemPreferences:
Mana Activation:
    - add a value "no, let me think about it", that is the default value.
    - as long as this value is selected, messages ask if user want to activate it ( in Administration and Add-subscription(page 2) )
AutoShareWithMana
    - Add the syspref AutoShareWithMana: user can automatically share infos with Mana-KB (not set by default)

* Interface :
    - On mana-search, rows are now sorted by date of last import, then by number of users
    - Windows redesigned to improve the user experience

* New Feature : report a mistake.
    - people can now report an invalid data (wrong, obsolete,...)
    - if a data is reported as invalid many time, it will appear differently
    - Added few tooltip (to explain the fields last import, nb of users, to explain the new feature)
    - When reporting a data as invalid, a comment can also be added. Koha will then display comments related to data in result lists

* API (svc/mana)
    - add svc/mana/addvaluetofield: allows to ask mana incrementing a field of a resource
    - no hardcoding for resources in the code of api (api needs to be called with a ressourcename)

* New feature : SQL report sharing
    - Create Koha::Report.pm and Koha::Reports.pm, objects class for Reports
    - New feature: share reports with Mana-KB
    - New feature: search report in Mana-KB with keywords
    - New feature: load reports from Mana-KB

Test plan:
    1 - Apply Patch + update database
    2 - Copy the three lines about mana config in etc/koha-conf.xml in ../etc/koha-conf.xml (after <backupdir> for example)
        <!-- URL of the mana KB server -->
        <!-- alternative value http://mana-test.koha-community.org to query the test server -->
        <mana_config>https://mana-kb.koha-community.org</mana_config>
    3 - Check Mana syspref and AutoShareWithMana syspref are not activated
    4 - Search the syspref ManaToken and follow the instructions
    5 - subscriptions
      - Try create a new subscription for a first serial  => Mana-KB shouldn't show you anything (except if the base hase been filled)
      - Share this serial with Mana-KB (on the serial individual's page there must be a Share button)
      - Try to create a new subscription for serial nr1 => a message should appear when you click on "next", click on "use", the fields should automaticaly appear
      - Activate AutoShareWithMana => Subscriptions
      - Create a new subscription for a second serial
      - There shouldn't be any Share button
      - Create a second subscription => the message should appear, click again on use

    6 - SQL Report
      - Create a new SQL report, without notes.
      - On the table with all report (reports > use saved), there should be the action "Share"
      - If you click on share, you have an error message
      - Create a new report, with a title and notes longer than 20 characters
      - You  can share it with mana => you will have a success message
      - On (report > use saved), there must be a message inviting you to search on Mana-KB for more results, enter a few word from title, notes, type of  the report you shared, it should appear. You can use it, it will load it into your report list.

    7 - Report mistakes.
      - On any table containing Mana-KB search results, you can report a mistake and add a comment.

    8 - For each previous test, try to send wrong data, to delete the security token, to send nothing: it should show a correct warning message.

Signed-off-by: Brendan A Gallagher <brendan@bywatersolutions.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Rebased-by: Alex Arnaud <alex.arnaud@biblibre.com> (2018-07-04)
Signed-off-by: Michal Denar <black23@gmail.com>

Signed-off-by: Michal Denar <black23@gmail.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
2019-01-23 14:39:26 +00:00

232 lines
8.7 KiB
Perl

#!/usr/bin/perl
# This test deals with GetFictiveIssueNumber (from C4::Serials)
use Modern::Perl;
use Test::More tests => 5;
use Koha::Database;
use C4::Serials;
use C4::Serials::Frequency;
my $schema = Koha::Database->new->schema;
$schema->storage->txn_begin;
my $dbh = C4::Context->dbh;
subtest 'Tests for irregular frequency' => sub {
plan tests => 2;
# Add a frequency
my $freq_irr = AddSubscriptionFrequency({
description => "Irregular",
unit => undef,
});
# Test it
my $subscription = {
periodicity => $freq_irr,
firstacquidate => '1972-02-07',
};
is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-12-31'), undef, 'Irregular: should be undef' );
is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-12-31'), undef, 'Irregular: still undef' );
};
subtest 'Tests for yearly frequencies' => sub {
plan tests => 10;
# First add a few frequencies
my $freq_1i_1y = AddSubscriptionFrequency({
description => "1 issue per year",
unit => 'year',
issuesperunit => 1,
unitsperissue => 1,
});
my $freq_1i_3y = AddSubscriptionFrequency({
description => "1 issue per 3 years",
unit => 'year',
issuesperunit => 1,
unitsperissue => 3,
});
my $freq_5i_1y = AddSubscriptionFrequency({
description => "5 issues per year",
unit => 'year',
issuesperunit => 5,
unitsperissue => 1,
});
my $freq_366i_1y = AddSubscriptionFrequency({
description => "366 issue per year",
unit => 'year',
issuesperunit => 366,
unitsperissue => 1,
});
# TEST CASE - 1 issue per year
my $subscription = {
periodicity => $freq_1i_1y,
firstacquidate => '1972-02-10',
countissuesperunit => 1,
};
my $frequency = GetSubscriptionFrequency($freq_1i_1y);
is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-09', $frequency), 1, 'Feb 9 still 1' );
is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-10', $frequency), 2, 'Feb 10 goes to 2' );
# TEST CASE - 1 issue per 3 years
$subscription->{periodicity} = $freq_1i_3y;
$subscription->{firstacquidate} = '1972-02-20';
$frequency = GetSubscriptionFrequency($freq_1i_3y);
is( C4::Serials::GetFictiveIssueNumber($subscription, '1975-02-19', $frequency), 1, 'Feb 19, 1975 still 1' );
is( C4::Serials::GetFictiveIssueNumber($subscription, '1975-02-20', $frequency), 2, 'Feb 20, 1975 goes to 2' );
# TEST CASE - 5 issues per year
$subscription->{periodicity} = $freq_5i_1y;
$subscription->{firstacquidate} = '1972-02-29'; #leap year
$subscription->{countissuesperunit} = 1;
$frequency = GetSubscriptionFrequency($freq_5i_1y);
is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-05-11', $frequency), 1, 'May 11 still 1' );
$subscription->{countissuesperunit} = 2;
is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-05-12', $frequency), 2, 'May 12 goes to 2' );
$subscription->{countissuesperunit} = 5;
is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-27', $frequency), 5, 'Feb 27 should still be 5' );
$subscription->{countissuesperunit} = 1;
is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-28', $frequency), 6, 'Feb 28 goes to 6' );
# TEST CASE - 366 issues per year (hypothetical example)
# Testing prevention of divide by zero
$subscription->{periodicity} = $freq_366i_1y;
$subscription->{firstacquidate} = '1972-02-29'; #leap year
$subscription->{countissuesperunit} = 366;
$frequency = GetSubscriptionFrequency($freq_366i_1y);
is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-27', $frequency), 366, 'Feb 27 still at 366' );
is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-28', $frequency), 732, 'Feb 28 goes to 732' );
};
subtest 'Tests for monthly frequencies' => sub {
plan tests => 8;
# First add a few frequencies
my $freq_1i_5m = AddSubscriptionFrequency({
description => "1 issue per 5 months",
unit => 'month',
issuesperunit => 1,
unitsperissue => 5,
});
my $freq_4i_1m = AddSubscriptionFrequency({
description => "4 issue per month",
unit => 'month',
issuesperunit => 4,
unitsperissue => 1,
});
# TEST CASE - 1 issue per 5 months
my $subscription = {
periodicity => $freq_1i_5m,
firstacquidate => '1972-02-10',
countissuesperunit => 1,
};
my $frequency = GetSubscriptionFrequency($freq_1i_5m);
is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-07-09', $frequency), 1, 'Jul 9 still 1' );
is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-07-10', $frequency), 2, 'Jul 10 goes to 2' );
is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-05-09', $frequency), 3, 'May 9 still 3' );
is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-05-10', $frequency), 4, 'May 10 goes to 4' );
# TEST CASE - 4 issue per 1 months
$subscription = {
periodicity => $freq_4i_1m,
firstacquidate => '1972-02-22',
countissuesperunit => 1,
};
$frequency = GetSubscriptionFrequency($freq_4i_1m);
is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-02-28', $frequency), 1, 'Feb 28 still 1' );
$subscription->{countissuesperunit} = 2;
is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-02-29', $frequency), 2, 'Feb 29 goes to 2' );
$subscription->{countissuesperunit} = 4;
is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-21', $frequency), 4, 'Mar 21 still 4' );
$subscription->{countissuesperunit} = 1;
is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-22', $frequency), 5, 'Mar 22 goes to 5' );
};
subtest 'Tests for weekly frequencies' => sub {
plan tests => 4;
# First add a few frequencies
my $freq_1i_7w = AddSubscriptionFrequency({
description => "1 issue per 7 weeks",
unit => 'week',
issuesperunit => 1,
unitsperissue => 7,
});
my $freq_3i_1w = AddSubscriptionFrequency({
description => "3 issues per week",
unit => 'week',
issuesperunit => 3,
unitsperissue => 1,
});
# TEST CASE - 1 issue per 7 weeks
my $subscription = {
periodicity => $freq_1i_7w,
firstacquidate => '1972-02-10',
countissuesperunit => 1,
};
my $frequency = GetSubscriptionFrequency($freq_1i_7w);
is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-29', $frequency), 1, 'Mar 29 still 1' );
is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-30', $frequency), 2, 'Mar 30 goes to 2' );
# TEST CASE - 3 issue per 1 week
$subscription = {
periodicity => $freq_3i_1w,
firstacquidate => '1972-02-03',
countissuesperunit => 1,
};
$subscription->{countissuesperunit} = 3;
$frequency = GetSubscriptionFrequency($freq_3i_1w);
is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-02-09', $frequency), 3, 'Feb 9 still 3' );
$subscription->{countissuesperunit} = 1;
is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-02-10', $frequency), 4, 'Feb 10 goes to 4' );
};
subtest 'Tests for dayly frequencies' => sub {
plan tests => 4;
# First add a few frequencies
my $freq_1i_12d = AddSubscriptionFrequency({
description => "1 issue per 12 days",
unit => 'day',
issuesperunit => 1,
unitsperissue => 12,
});
my $freq_3i_1d = AddSubscriptionFrequency({
description => "3 issues per day",
unit => 'day',
issuesperunit => 3,
unitsperissue => 1,
});
# TEST CASE - 1 issue per 12 days
my $subscription = {
periodicity => $freq_1i_12d,
firstacquidate => '1972-03-16',
countissuesperunit => 1,
};
my $frequency = GetSubscriptionFrequency($freq_1i_12d);
is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-27', $frequency), 1, 'Mar 27 still 1' );
is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-28', $frequency), 2, 'Mar 28 goes to 2' );
# TEST CASE - 3 issue per day
$subscription = {
periodicity => $freq_3i_1d,
firstacquidate => '1972-04-23',
countissuesperunit => 1,
};
$subscription->{countissuesperunit} = 3;
$frequency = GetSubscriptionFrequency($freq_3i_1d);
is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-05-01', $frequency), 27, 'May 1 still 27' );
$subscription->{countissuesperunit} = 1;
is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-05-02', $frequency), 28, 'May 2 goes to 28' );
};
$schema->storage->txn_rollback;