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();
48 my $vendor = $builder->build_object( { class => 'Koha::Acquisition::Booksellers' } );
50 is( $vendor->baskets, 0, 'Vendor has no baskets' );
53 my $basket_1_id = C4::Acquisition::NewBasket( $vendor->id, 'authorizedby1', 'basketname1' );
54 my $basket_2_id = C4::Acquisition::NewBasket( $vendor->id, 'authorizedby2', 'basketname2' );
57 $vendor = Koha::Acquisition::Booksellers->find( $vendor->id );
58 is( $vendor->baskets, 2, 'Vendor has two baskets' );
60 $schema->storage->txn_rollback();
63 subtest '->subscriptions() tests' => sub {
67 $schema->storage->txn_begin();
69 # Delete existing data
70 $schema->resultset('Aqorder')->delete();
71 $schema->resultset('Aqbasket')->delete();
72 Koha::Acquisition::Booksellers->delete();
73 $schema->resultset('Subscription')->delete();
75 my $vendor = $builder->build_object( { class => 'Koha::Acquisition::Booksellers' } );
76 is( $vendor->subscriptions->count, 0, 'Vendor has no subscriptions' );
78 my $dt_today = dt_from_string;
79 my $today = output_pref(
80 { dt => $dt_today, dateformat => 'iso', timeformat => '24hr', dateonly => 1 } );
82 my $dt_today1 = dt_from_string;
83 my $dur5 = DateTime::Duration->new( days => -5 );
84 $dt_today1->add_duration($dur5);
85 my $daysago5 = output_pref(
86 { dt => $dt_today1, dateformat => 'iso', timeformat => '24hr', dateonly => 1 } );
88 my $budgetperiod = C4::Budgets::AddBudgetPeriod(
89 { budget_period_startdate => $daysago5,
90 budget_period_enddate => $today,
91 budget_period_description => "budget desc"
94 my $id_budget = AddBudget(
95 { budget_code => "CODE",
96 budget_amount => "123.132",
97 budget_name => "Budgetname",
98 budget_notes => "This is a note",
99 budget_period_id => $budgetperiod
102 my $bib = MARC::Record->new();
104 MARC::Field->new( '245', ' ', ' ', a => 'Journal of ethnology' ),
105 MARC::Field->new( '500', ' ', ' ', a => 'bib notes' ),
107 my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $bib, '' );
109 # Add two subscriptions
110 my $subscription_1_id = NewSubscription(
111 undef, 'BRANCH2', $vendor->id, undef,
112 $id_budget, $biblionumber, '01-01-2013', undef,
113 undef, undef, undef, undef,
114 undef, undef, undef, undef,
115 undef, 1, "subscription notes", undef,
116 '01-01-2013', undef, undef, undef,
117 'CALL ABC', 0, "intnotes", 0,
118 undef, undef, 0, undef,
122 my @subscriptions = SearchSubscriptions( { biblionumber => $biblionumber } );
123 is( $subscriptions[0]->{publicnotes},
124 'subscription notes',
125 'subscription search results include public notes (bug 10689)'
128 my $id_subscription2 = NewSubscription(
129 undef, 'BRANCH2', $vendor->id, undef,
130 $id_budget, $biblionumber, '01-01-2013', undef,
131 undef, undef, undef, undef,
132 undef, undef, undef, undef,
133 undef, 1, "subscription notes", undef,
134 '01-01-2013', undef, undef, undef,
135 'CALL DEF', 0, "intnotes", 0,
136 undef, undef, 0, undef,
141 $vendor = Koha::Acquisition::Booksellers->find( $vendor->id );
142 is( $vendor->subscriptions->count, 2, 'Vendor has two subscriptions' );
143 foreach my $subscription ( $vendor->subscriptions ) {
144 is( ref($subscription), 'Koha::Subscription', 'Type is correct' );
147 $schema->storage->txn_rollback();
150 subtest '->contacts() tests' => sub {
154 $schema->storage->txn_begin();
156 # Delete existing data
157 $schema->resultset('Aqorder')->delete();
158 $schema->resultset('Aqbasket')->delete();
159 Koha::Acquisition::Booksellers->delete();
160 $schema->resultset('Subscription')->delete();
162 my $vendor = $builder->build_object( { class => 'Koha::Acquisition::Booksellers' } );
164 is( $vendor->contacts->count, 0, 'Vendor has no contacts' );
167 my $contact_1 = $builder->build_object(
168 { class => 'Koha::Acquisition::Bookseller::Contacts',
169 value => { booksellerid => $vendor->id }
172 my $contact_2 = $builder->build_object(
173 { class => 'Koha::Acquisition::Bookseller::Contacts',
174 value => { booksellerid => $vendor->id }
179 $vendor = Koha::Acquisition::Booksellers->find( $vendor->id );
180 is( $vendor->contacts->count, 2, 'Vendor has two contacts' );
181 foreach my $contact ( $vendor->contacts ) {
182 is( ref($contact), 'Koha::Acquisition::Bookseller::Contact', 'Type is correct' );
185 $schema->storage->txn_rollback();