3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Test::More tests => 3;
22 use t::lib::TestBuilder;
29 use Koha::Acquisition::Booksellers;
33 my $schema = Koha::Database->schema();
34 my $builder = t::lib::TestBuilder->new;
36 subtest '->baskets() tests' => sub {
40 $schema->storage->txn_begin();
42 # Delete existing data
43 $schema->resultset('Aqorder')->delete();
44 $schema->resultset('Aqbasket')->delete();
45 Koha::Acquisition::Booksellers->delete();
46 $schema->resultset('Subscription')->delete();
47 my $patron = $builder->build_object({ class => 'Koha::Patrons' });
49 my $vendor = $builder->build_object( { class => 'Koha::Acquisition::Booksellers' } );
51 is( $vendor->baskets, 0, 'Vendor has no baskets' );
54 my $basket_1_id = C4::Acquisition::NewBasket( $vendor->id, $patron->borrowernumber, 'basketname1' );
55 my $basket_2_id = C4::Acquisition::NewBasket( $vendor->id, $patron->borrowernumber, 'basketname2' );
58 $vendor = Koha::Acquisition::Booksellers->find( $vendor->id );
59 is( $vendor->baskets, 2, 'Vendor has two baskets' );
61 $schema->storage->txn_rollback();
64 subtest '->subscriptions() tests' => sub {
68 $schema->storage->txn_begin();
70 # Delete existing data
71 $schema->resultset('Aqorder')->delete();
72 $schema->resultset('Aqbasket')->delete();
73 Koha::Acquisition::Booksellers->delete();
74 $schema->resultset('Subscription')->delete();
76 my $vendor = $builder->build_object( { class => 'Koha::Acquisition::Booksellers' } );
77 is( $vendor->subscriptions->count, 0, 'Vendor has no subscriptions' );
79 my $dt_today = dt_from_string;
80 my $today = output_pref(
81 { dt => $dt_today, dateformat => 'iso', timeformat => '24hr', dateonly => 1 } );
83 my $dt_today1 = dt_from_string;
84 my $dur5 = DateTime::Duration->new( days => -5 );
85 $dt_today1->add_duration($dur5);
86 my $daysago5 = output_pref(
87 { dt => $dt_today1, dateformat => 'iso', timeformat => '24hr', dateonly => 1 } );
89 my $budgetperiod = C4::Budgets::AddBudgetPeriod(
90 { budget_period_startdate => $daysago5,
91 budget_period_enddate => $today,
92 budget_period_description => "budget desc"
95 my $id_budget = AddBudget(
96 { budget_code => "CODE",
97 budget_amount => "123.132",
98 budget_name => "Budgetname",
99 budget_notes => "This is a note",
100 budget_period_id => $budgetperiod
103 my $bib = MARC::Record->new();
105 MARC::Field->new( '245', ' ', ' ', a => 'Journal of ethnology' ),
106 MARC::Field->new( '500', ' ', ' ', a => 'bib notes' ),
108 my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $bib, '' );
110 # Add two subscriptions
111 my $subscription_1_id = NewSubscription(
112 undef, 'BRANCH2', $vendor->id, undef,
113 $id_budget, $biblionumber, '2013-01-01', undef,
114 undef, undef, undef, undef,
115 undef, undef, undef, undef,
116 undef, 1, "subscription notes", undef,
117 '2013-01-01', undef, undef, undef,
118 'CALL ABC', 0, "intnotes", 0,
119 undef, undef, 0, undef,
123 my @subscriptions = SearchSubscriptions( { biblionumber => $biblionumber } );
124 is( $subscriptions[0]->{publicnotes},
125 'subscription notes',
126 'subscription search results include public notes (bug 10689)'
129 my $id_subscription2 = NewSubscription(
130 undef, 'BRANCH2', $vendor->id, undef,
131 $id_budget, $biblionumber, '2013-01-01', undef,
132 undef, undef, undef, undef,
133 undef, undef, undef, undef,
134 undef, 1, "subscription notes", undef,
135 '2013-01-01', undef, undef, undef,
136 'CALL DEF', 0, "intnotes", 0,
137 undef, undef, 0, undef,
142 $vendor = Koha::Acquisition::Booksellers->find( $vendor->id );
143 is( $vendor->subscriptions->count, 2, 'Vendor has two subscriptions' );
144 foreach my $subscription ( $vendor->subscriptions ) {
145 is( ref($subscription), 'Koha::Subscription', 'Type is correct' );
148 $schema->storage->txn_rollback();
151 subtest '->contacts() tests' => sub {
155 $schema->storage->txn_begin();
157 # Delete existing data
158 $schema->resultset('Aqorder')->delete();
159 $schema->resultset('Aqbasket')->delete();
160 Koha::Acquisition::Booksellers->delete();
161 $schema->resultset('Subscription')->delete();
163 my $vendor = $builder->build_object( { class => 'Koha::Acquisition::Booksellers' } );
165 is( $vendor->contacts->count, 0, 'Vendor has no contacts' );
168 my $contact_1 = $builder->build_object(
169 { class => 'Koha::Acquisition::Bookseller::Contacts',
170 value => { booksellerid => $vendor->id }
173 my $contact_2 = $builder->build_object(
174 { class => 'Koha::Acquisition::Bookseller::Contacts',
175 value => { booksellerid => $vendor->id }
180 $vendor = Koha::Acquisition::Booksellers->find( $vendor->id );
181 is( $vendor->contacts->count, 2, 'Vendor has two contacts' );
182 foreach my $contact ( $vendor->contacts ) {
183 is( ref($contact), 'Koha::Acquisition::Bookseller::Contact', 'Type is correct' );
186 $schema->storage->txn_rollback();