|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
# Copyright Vaara-kirjastot 2015 |
| 4 |
# |
| 5 |
# This file is part of Koha. |
| 6 |
# |
| 7 |
# Koha is free software; you can redistribute it and/or modify it under the |
| 8 |
# terms of the GNU General Public License as published by the Free Software |
| 9 |
# Foundation; either version 3 of the License, or (at your option) any later |
| 10 |
# version. |
| 11 |
# |
| 12 |
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
| 13 |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
| 14 |
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License along |
| 17 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
| 18 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 |
# |
| 20 |
|
| 21 |
use Modern::Perl; |
| 22 |
|
| 23 |
use Test::More; |
| 24 |
use DateTime; |
| 25 |
|
| 26 |
use Koha::DateUtils; |
| 27 |
|
| 28 |
use t::lib::TestObjects::ObjectFactory; |
| 29 |
use t::lib::TestObjects::BorrowerFactory; |
| 30 |
use Koha::Borrowers; |
| 31 |
use t::lib::TestObjects::ItemFactory; |
| 32 |
use Koha::Items; |
| 33 |
use t::lib::TestObjects::BiblioFactory; |
| 34 |
use Koha::Biblios; |
| 35 |
use t::lib::TestObjects::CheckoutFactory; |
| 36 |
use Koha::Checkouts; |
| 37 |
use t::lib::TestObjects::LetterTemplateFactory; |
| 38 |
use Koha::LetterTemplates; |
| 39 |
use t::lib::TestObjects::Acquisition::Bookseller::ContactFactory; |
| 40 |
use Koha::Acquisition::Bookseller::Contacts; |
| 41 |
use t::lib::TestObjects::Acquisition::BooksellerFactory; |
| 42 |
use Koha::Acquisition::Booksellers; |
| 43 |
use t::lib::TestObjects::Serial::SubscriptionFactory; |
| 44 |
use Koha::Serial::Subscriptions; |
| 45 |
use Koha::Serial::Subscription::Frequencies; |
| 46 |
use Koha::Serial::Subscription::Numberpatterns; |
| 47 |
use Koha::Serial::Serials; |
| 48 |
use t::lib::TestObjects::SystemPreferenceFactory; |
| 49 |
use C4::Context; |
| 50 |
|
| 51 |
|
| 52 |
my $testContext = {}; #Gather all created Objects here so we can finally remove them all. |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
########## Serial subtests ########## |
| 57 |
subtest 't::lib::TestObjects::Serial' => sub { |
| 58 |
my ($subscriptions, $subscription, $frequency, $numberpattern, $biblio, $borrower, $bookseller, $items, $serials); |
| 59 |
my $subtestContext = {}; |
| 60 |
my $dontDeleteTestContext = {}; |
| 61 |
##Create and delete |
| 62 |
$subscriptions = t::lib::TestObjects::Serial::SubscriptionFactory->createTestGroup([ |
| 63 |
{internalnotes => 'TESTDEFAULTS', |
| 64 |
receiveSerials => 3}, |
| 65 |
], undef, $subtestContext); |
| 66 |
$subscription = Koha::Serial::Subscriptions->find( $subscriptions->{'TESTDEFAULTS'}->subscriptionid ); |
| 67 |
$frequency = $subscription->periodicity(); |
| 68 |
$numberpattern = $subscription->numberpattern(); |
| 69 |
$biblio = $subscription->biblio(); |
| 70 |
$borrower = $subscription->borrower(); |
| 71 |
$bookseller = $subscription->bookseller(); |
| 72 |
$items = $subscription->items(); |
| 73 |
$serials = $subscription->serials(); |
| 74 |
ok(($subscriptions->{'TESTDEFAULTS'}->callnumber eq $subscription->callnumber && |
| 75 |
$subscriptions->{'TESTDEFAULTS'}->subscriptionid eq $subscription->subscriptionid), |
| 76 |
"Default Subscription created."); |
| 77 |
ok($subscriptions->{'TESTDEFAULTS'}->numberpattern->label eq $numberpattern->label, |
| 78 |
"Default Numberpattern '".$numberpattern->label."' used."); |
| 79 |
ok($subscriptions->{'TESTDEFAULTS'}->periodicity->description eq $frequency->description, |
| 80 |
"Default Periodicity '".$frequency->description."' used."); |
| 81 |
ok($subscriptions->{'TESTDEFAULTS'}->biblio->title eq $biblio->title, |
| 82 |
"Default Biblio '".$biblio->title."' created."); |
| 83 |
ok($subscriptions->{'TESTDEFAULTS'}->bookseller->name eq $bookseller->name, |
| 84 |
"Default Bookseller '".$bookseller->name."' created."); |
| 85 |
ok($serials->[0]->isa('Koha::Serial::Serial') && $serials->[0]->serialseq eq 'Vol. 2015, Number 1, Issue 1' && |
| 86 |
$serials->[1]->isa('Koha::Serial::Serial') && $serials->[1]->serialseq eq 'Vol. 2015, Number 1, Issue 2' && |
| 87 |
$serials->[2]->isa('Koha::Serial::Serial') && $serials->[2]->serialseq eq 'Vol. 2015, Number 1, Issue 3' && |
| 88 |
$serials->[3]->isa('Koha::Serial::Serial') && $serials->[3]->serialseq eq 'Vol. 2015, Number 1, Issue 4' |
| 89 |
, "Got 4 default Serials"); |
| 90 |
ok($items->[0]->isa('Koha::Item') && $items->[0]->enumchron eq 'Vol. 2015, Number 1, Issue 1' && |
| 91 |
$items->[1]->isa('Koha::Item') && $items->[1]->enumchron eq 'Vol. 2015, Number 1, Issue 2' && |
| 92 |
$items->[2]->isa('Koha::Item') && $items->[2]->enumchron eq 'Vol. 2015, Number 1, Issue 3' |
| 93 |
, "Received 3 default Serial Items"); |
| 94 |
|
| 95 |
t::lib::TestObjects::ObjectFactory->tearDownTestContext($subtestContext); |
| 96 |
$subscription = Koha::Serial::Subscriptions->find( $subscriptions->{'TESTDEFAULTS'}->subscriptionid ); |
| 97 |
ok(not(defined($subscription)), "Default Subscription deleted."); |
| 98 |
$biblio = Koha::Biblios->find( $biblio->id ); |
| 99 |
ok(not(defined($biblio)), "Default Biblio deleted."); |
| 100 |
$borrower = Koha::Borrowers->find( $borrower->id ); |
| 101 |
ok(not(defined($borrower)), "Default Borrower deleted."); |
| 102 |
$bookseller = Koha::Acquisition::Booksellers->find( $bookseller->id ); |
| 103 |
ok(not(defined($bookseller)), "Default Bookseller deleted."); |
| 104 |
$frequency = Koha::Serial::Subscription::Frequencies->find( $frequency->id ); |
| 105 |
ok($frequency, "Attached Frequency not deleted."); |
| 106 |
$numberpattern = Koha::Serial::Subscription::Numberpatterns->find( $numberpattern->id ); |
| 107 |
ok($numberpattern, "Attached Numbering Pattern not deleted."); |
| 108 |
$serials = [Koha::Serial::Serials->search({ subscriptionid => $serials->[0]->subscriptionid})]; |
| 109 |
$items = [Koha::Items->search({"-or" => [{itemnumber => $items->[0]->itemnumber}, |
| 110 |
{itemnumber => $items->[1]->itemnumber}, |
| 111 |
{itemnumber => $items->[2]->itemnumber}, |
| 112 |
]})]; |
| 113 |
ok(not($serials->[0] && |
| 114 |
$serials->[1] && |
| 115 |
$serials->[2] && |
| 116 |
$serials->[3]) |
| 117 |
, "4 default Serials deleted."); |
| 118 |
ok(not($items->[0] && |
| 119 |
$items->[1] && |
| 120 |
$items->[2]) |
| 121 |
, "3 default Serial Items deleted"); |
| 122 |
|
| 123 |
### TESTING NOT DELETING A GIVEN BIBLIO OR BORROWER ### |
| 124 |
my $biblios = t::lib::TestObjects::BiblioFactory->createTestGroup([ |
| 125 |
{'biblio.title' => 'I wish I met your mother', |
| 126 |
'biblio.author' => 'Pertti Kurikka', |
| 127 |
'biblio.copyrightdate' => '1960', |
| 128 |
'biblioitems.isbn' => '9519671580', |
| 129 |
'biblioitems.itemtype' => 'BK', |
| 130 |
}, |
| 131 |
], 'biblioitems.isbn', $dontDeleteTestContext); |
| 132 |
my $borrowers = t::lib::TestObjects::BorrowerFactory->createTestGroup([ |
| 133 |
{firstname => 'Olli-Antti', |
| 134 |
surname => 'Kivi', |
| 135 |
cardnumber => '11A001', |
| 136 |
branchcode => 'CPL', |
| 137 |
}, |
| 138 |
], undef, $dontDeleteTestContext); |
| 139 |
my $booksellers = t::lib::TestObjects::Acquisition::BooksellerFactory->createTestGroup([{ |
| 140 |
name => "Undeletable Magazine vendor"}], |
| 141 |
undef, $dontDeleteTestContext); |
| 142 |
$subscriptions = t::lib::TestObjects::Serial::SubscriptionFactory->createTestGroup([ |
| 143 |
{internalnotes => 'TESTDEFAULTS', |
| 144 |
biblio => $biblios->{'9519671580'}->{biblionumber}, |
| 145 |
librarian => $borrowers->{'11A001'}, |
| 146 |
aqbookseller => $booksellers->{"Undeletable Magazine vendor"}, |
| 147 |
}, |
| 148 |
], undef, $subtestContext); |
| 149 |
$subscription = Koha::Serial::Subscriptions->find( $subscriptions->{'TESTDEFAULTS'}->subscriptionid ); |
| 150 |
$biblio = $subscription->biblio(); |
| 151 |
$borrower = $subscription->borrower(); |
| 152 |
$bookseller = $subscription->bookseller(); |
| 153 |
t::lib::TestObjects::ObjectFactory->tearDownTestContext($subtestContext); |
| 154 |
$biblio = Koha::Biblios->find( $biblio->id ); |
| 155 |
ok(defined($biblio), "Attached Biblio not deleted."); |
| 156 |
$borrower = Koha::Borrowers->find( $borrower->id ); |
| 157 |
ok(defined($borrower), "Attached Borrower not deleted."); |
| 158 |
$bookseller = Koha::Acquisition::Booksellers->find( $bookseller->id ); |
| 159 |
ok(defined($bookseller), "Attached Bookseller not deleted."); |
| 160 |
t::lib::TestObjects::ObjectFactory->tearDownTestContext($dontDeleteTestContext); |
| 161 |
}; |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
########## Acquisition subtests ########## |
| 166 |
subtest 't::lib::TestObjects::Acquisition' => sub { |
| 167 |
my ($booksellers, $bookseller, $contacts, $contact); |
| 168 |
my $subtestContext = {}; |
| 169 |
##Create and delete |
| 170 |
$booksellers = t::lib::TestObjects::Acquisition::BooksellerFactory->createTestGroup([{}], undef, $subtestContext); |
| 171 |
$bookseller = Koha::Acquisition::Booksellers->find({name => 'Bookselling Vendor'}); |
| 172 |
$contact = Koha::Acquisition::Bookseller::Contacts->find({name => 'Julius Augustus Caesar'}); |
| 173 |
ok(($booksellers->{'Bookselling Vendor'}->name eq 'Bookselling Vendor' && |
| 174 |
$bookseller->name eq 'Bookselling Vendor'), |
| 175 |
"Default Bookseller 'Bookselling Vendor' created."); |
| 176 |
ok(($booksellers->{'Bookselling Vendor'}->{contacts}->{'Julius Augustus Caesar'}->name eq 'Julius Augustus Caesar' && |
| 177 |
$contact->name eq 'Julius Augustus Caesar'), |
| 178 |
"Default Contact 'Julius Augustus Caesar' created."); |
| 179 |
|
| 180 |
$contacts = t::lib::TestObjects::Acquisition::Bookseller::ContactFactory->createTestGroup([ |
| 181 |
{name => 'Hippocrates', |
| 182 |
booksellerid => $booksellers->{'Bookselling Vendor'}->id}] |
| 183 |
, undef, $subtestContext); |
| 184 |
$contact = Koha::Acquisition::Bookseller::Contacts->find({name => 'Hippocrates'}); |
| 185 |
ok(($contacts->{'Hippocrates'}->name, 'Hippocrates' && |
| 186 |
$contact->name eq 'Hippocrates'), |
| 187 |
"Contact 'Hippocrates' created."); |
| 188 |
|
| 189 |
t::lib::TestObjects::ObjectFactory->tearDownTestContext($subtestContext); |
| 190 |
$contact = Koha::Acquisition::Bookseller::Contacts->find({name => 'Julius Augustus Caesar'}); |
| 191 |
ok(not(defined($contact)), "Contact 'Julius Augustus Caesar' deleted."); |
| 192 |
$contact = Koha::Acquisition::Bookseller::Contacts->find({name => 'Hippocrates'}); |
| 193 |
ok(not(defined($contact)), "Contact 'Hippocrates' deleted."); |
| 194 |
$bookseller = Koha::Acquisition::Booksellers->find({name => 'Bookselling Vendor'}); |
| 195 |
ok(not(defined($bookseller)), "Bookseller 'Bookselling Vendor' deleted."); |
| 196 |
}; |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
########## BorrowerFactory subtests ########## |
| 201 |
subtest 't::lib::TestObjects::BorrowerFactory' => sub { |
| 202 |
my $subtestContext = {}; |
| 203 |
##Create and Delete. Add one |
| 204 |
my $f = t::lib::TestObjects::BorrowerFactory->new(); |
| 205 |
my $objects = $f->createTestGroup([ |
| 206 |
{firstname => 'Olli-Antti', |
| 207 |
surname => 'Kivi', |
| 208 |
cardnumber => '11A001', |
| 209 |
branchcode => 'CPL', |
| 210 |
}, |
| 211 |
], undef, $subtestContext, undef, $testContext); |
| 212 |
is($objects->{'11A001'}->cardnumber, '11A001', "Borrower '11A001'."); |
| 213 |
##Add one more to test incrementing the subtestContext. |
| 214 |
$objects = $f->createTestGroup([ |
| 215 |
{firstname => 'Olli-Antti2', |
| 216 |
surname => 'Kivi2', |
| 217 |
cardnumber => '11A002', |
| 218 |
branchcode => 'FFL', |
| 219 |
}, |
| 220 |
], undef, $subtestContext, undef, $testContext); |
| 221 |
is($subtestContext->{borrower}->{'11A001'}->cardnumber, '11A001', "Borrower '11A001' from \$subtestContext."); #From subtestContext |
| 222 |
is($objects->{'11A002'}->branchcode, 'FFL', "Borrower '11A002'."); #from just created hash. |
| 223 |
|
| 224 |
##Delete objects |
| 225 |
t::lib::TestObjects::ObjectFactory->tearDownTestContext($subtestContext); |
| 226 |
my $object11A001 = Koha::Borrowers->find({cardnumber => '11A001'}); |
| 227 |
ok (not($object11A001), "Borrower '11A001' deleted"); |
| 228 |
my $object11A002 = Koha::Borrowers->find({cardnumber => '11A002'}); |
| 229 |
ok (not($object11A002), "Borrower '11A002' deleted"); |
| 230 |
|
| 231 |
#Prepare for global autoremoval. |
| 232 |
$objects = $f->createTestGroup([ |
| 233 |
{firstname => 'Olli-Antti', |
| 234 |
surname => 'Kivi', |
| 235 |
cardnumber => '11A001', |
| 236 |
branchcode => 'CPL', |
| 237 |
}, |
| 238 |
{firstname => 'Olli-Antti2', |
| 239 |
surname => 'Kivi2', |
| 240 |
cardnumber => '11A002', |
| 241 |
branchcode => 'FFL', |
| 242 |
}, |
| 243 |
], undef, undef, undef, $testContext); |
| 244 |
}; |
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
########## BiblioFactory and ItemFactory subtests ########## |
| 249 |
subtest 't::lib::TestObjects::BiblioFactory and ::ItemFactory' => sub { |
| 250 |
my $subtestContext = {}; |
| 251 |
##Create and Delete. Add one |
| 252 |
my $biblios = t::lib::TestObjects::BiblioFactory->createTestGroup([ |
| 253 |
{'biblio.title' => 'I wish I met your mother', |
| 254 |
'biblio.author' => 'Pertti Kurikka', |
| 255 |
'biblio.copyrightdate' => '1960', |
| 256 |
'biblioitems.isbn' => '9519671580', |
| 257 |
'biblioitems.itemtype' => 'BK', |
| 258 |
}, |
| 259 |
], 'biblioitems.isbn', $subtestContext, undef, $testContext); |
| 260 |
my $objects = t::lib::TestObjects::ItemFactory->createTestGroup([ |
| 261 |
{biblionumber => $biblios->{9519671580}->{biblionumber}, |
| 262 |
barcode => '167Nabe0001', |
| 263 |
homebranch => 'CPL', |
| 264 |
holdingbranch => 'CPL', |
| 265 |
price => '0.50', |
| 266 |
replacementprice => '0.50', |
| 267 |
itype => 'BK', |
| 268 |
biblioisbn => '9519671580', |
| 269 |
itemcallnumber => 'PK 84.2', |
| 270 |
}, |
| 271 |
], 'barcode', $subtestContext, undef, $testContext); |
| 272 |
|
| 273 |
is($objects->{'167Nabe0001'}->barcode, '167Nabe0001', "Item '167Nabe0001'."); |
| 274 |
##Add one more to test incrementing the subtestContext. |
| 275 |
$objects = t::lib::TestObjects::ItemFactory->createTestGroup([ |
| 276 |
{biblionumber => $biblios->{9519671580}->{biblionumber}, |
| 277 |
barcode => '167Nabe0002', |
| 278 |
homebranch => 'CPL', |
| 279 |
holdingbranch => 'FFL', |
| 280 |
price => '3.50', |
| 281 |
replacementprice => '3.50', |
| 282 |
itype => 'BK', |
| 283 |
biblioisbn => '9519671580', |
| 284 |
itemcallnumber => 'JK 84.2', |
| 285 |
}, |
| 286 |
], 'barcode', $subtestContext, undef, $testContext); |
| 287 |
|
| 288 |
is($subtestContext->{item}->{'167Nabe0001'}->barcode, '167Nabe0001', "Item '167Nabe0001' from \$subtestContext."); |
| 289 |
is($objects->{'167Nabe0002'}->holdingbranch, 'FFL', "Item '167Nabe0002'."); |
| 290 |
is(ref($biblios->{9519671580}), 'MARC::Record', "Biblio 'I wish I met your mother'."); |
| 291 |
|
| 292 |
##Delete objects |
| 293 |
t::lib::TestObjects::ObjectFactory->tearDownTestContext($subtestContext); |
| 294 |
my $object1 = Koha::Items->find({barcode => '167Nabe0001'}); |
| 295 |
ok (not($object1), "Item '167Nabe0001' deleted"); |
| 296 |
my $object2 = Koha::Items->find({barcode => '167Nabe0002'}); |
| 297 |
ok (not($object2), "Item '167Nabe0002' deleted"); |
| 298 |
my $object3 = Koha::Biblios->find({title => 'I wish I met your mother', author => "Pertti Kurikka"}); |
| 299 |
ok (not($object2), "Biblio 'I wish I met your mother' deleted"); |
| 300 |
}; |
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
########## CheckoutFactory subtests ########## |
| 305 |
subtest 't::lib::TestObjects::CheckoutFactory' => sub { |
| 306 |
my $subtestContext = {}; |
| 307 |
##Create and Delete using dependencies in the $testContext instantiated in previous subtests. |
| 308 |
my $biblios = t::lib::TestObjects::BiblioFactory->createTestGroup([ |
| 309 |
{'biblio.title' => 'I wish I met your mother', |
| 310 |
'biblio.author' => 'Pertti Kurikka', |
| 311 |
'biblio.copyrightdate' => '1960', |
| 312 |
'biblioitems.isbn' => '9519671580', |
| 313 |
'biblioitems.itemtype' => 'BK', |
| 314 |
}, |
| 315 |
], 'biblioitems.isbn', undef, undef, $subtestContext); |
| 316 |
my $items = t::lib::TestObjects::ItemFactory->createTestGroup([ |
| 317 |
{biblionumber => $biblios->{9519671580}->{biblionumber}, |
| 318 |
barcode => '167Nabe0001', |
| 319 |
homebranch => 'CPL', |
| 320 |
holdingbranch => 'CPL', |
| 321 |
price => '0.50', |
| 322 |
replacementprice => '0.50', |
| 323 |
itype => 'BK', |
| 324 |
biblioisbn => '9519671580', |
| 325 |
itemcallnumber => 'PK 84.2', |
| 326 |
}, |
| 327 |
{biblionumber => $biblios->{9519671580}->{biblionumber}, |
| 328 |
barcode => '167Nabe0002', |
| 329 |
homebranch => 'CPL', |
| 330 |
holdingbranch => 'FFL', |
| 331 |
price => '3.50', |
| 332 |
replacementprice => '3.50', |
| 333 |
itype => 'BK', |
| 334 |
biblioisbn => '9519671580', |
| 335 |
itemcallnumber => 'JK 84.2', |
| 336 |
}, |
| 337 |
], 'barcode', undef, undef, $subtestContext); |
| 338 |
my $objects = t::lib::TestObjects::CheckoutFactory->createTestGroup([ |
| 339 |
{ |
| 340 |
cardnumber => '11A001', |
| 341 |
barcode => '167Nabe0001', |
| 342 |
daysOverdue => 7, |
| 343 |
daysAgoCheckedout => 28, |
| 344 |
}, |
| 345 |
{ |
| 346 |
cardnumber => '11A002', |
| 347 |
barcode => '167Nabe0002', |
| 348 |
daysOverdue => -7, |
| 349 |
daysAgoCheckedout => 14, |
| 350 |
checkoutBranchRule => 'holdingbranch', |
| 351 |
}, |
| 352 |
], undef, undef, undef, undef); |
| 353 |
|
| 354 |
is($objects->{'11A001-167Nabe0001'}->branchcode, |
| 355 |
'CPL', |
| 356 |
"Checkout '11A001-167Nabe0001' checked out from the default context branch 'CPL'."); |
| 357 |
is($objects->{'11A002-167Nabe0002'}->branchcode, |
| 358 |
'FFL', |
| 359 |
"Checkout '11A002-167Nabe0002' checked out from the holdingbranch 'FFL'."); |
| 360 |
is(Koha::DateUtils::dt_from_string($objects->{'11A001-167Nabe0001'}->issuedate)->day(), |
| 361 |
DateTime->now(time_zone => C4::Context->tz())->subtract(days => '28')->day() |
| 362 |
, "Checkout '11A001-167Nabe0001', adjusted issuedates match."); |
| 363 |
is(Koha::DateUtils::dt_from_string($objects->{'11A002-167Nabe0002'}->date_due)->day(), |
| 364 |
DateTime->now(time_zone => C4::Context->tz())->subtract(days => '-7')->day() |
| 365 |
, "Checkout '11A002-167Nabe0002', adjusted date_dues match."); |
| 366 |
|
| 367 |
t::lib::TestObjects::CheckoutFactory->deleteTestGroup($objects); |
| 368 |
my $object1 = Koha::Checkouts->find({borrowernumber => $objects->{'11A001-167Nabe0001'}->borrowernumber, |
| 369 |
itemnumber => $objects->{'11A001-167Nabe0001'}->itemnumber}); |
| 370 |
ok (not($object1), "Checkout '11A001-167Nabe0001' deleted"); |
| 371 |
my $object2 = Koha::Checkouts->find({borrowernumber => $objects->{'11A002-167Nabe0002'}->borrowernumber, |
| 372 |
itemnumber => $objects->{'11A002-167Nabe0002'}->itemnumber}); |
| 373 |
ok (not($object2), "Checkout '11A002-167Nabe0002' deleted"); |
| 374 |
}; |
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
########## LetterTemplateFactory subtests ########## |
| 379 |
subtest 't::lib::TestObjects::LetterTemplateFactory' => sub { |
| 380 |
my $subtestContext = {}; |
| 381 |
##Create and Delete using dependencies in the $testContext instantiated in previous subtests. |
| 382 |
my $f = t::lib::TestObjects::LetterTemplateFactory->new(); |
| 383 |
my $hashLT = {letter_id => 'circulation-ODUE1-CPL-print', |
| 384 |
module => 'circulation', |
| 385 |
code => 'ODUE1', |
| 386 |
branchcode => 'CPL', |
| 387 |
name => 'Notice1', |
| 388 |
is_html => undef, |
| 389 |
title => 'Notice1', |
| 390 |
message_transport_type => 'print', |
| 391 |
content => '<item>Barcode: <<items.barcode>>, bring it back!</item>', |
| 392 |
}; |
| 393 |
my $objects = $f->createTestGroup([ |
| 394 |
$hashLT, |
| 395 |
], undef, undef, undef, undef); |
| 396 |
|
| 397 |
my $letterTemplate = Koha::LetterTemplates->find($hashLT); |
| 398 |
is($objects->{'circulation-ODUE1-CPL-print'}->name, $letterTemplate->name, "LetterTemplate 'circulation-ODUE1-CPL-print'"); |
| 399 |
|
| 400 |
#Delete them |
| 401 |
$f->deleteTestGroup($objects); |
| 402 |
$letterTemplate = Koha::LetterTemplates->find($hashLT); |
| 403 |
ok(not(defined($letterTemplate)), "LetterTemplate 'circulation-ODUE1-CPL-print' deleted"); |
| 404 |
}; |
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
########## SystemPreferenceFactory subtests ########## |
| 409 |
subtest 't::lib::TestObjects::SystemPreferenceFactory' => sub { |
| 410 |
my $subtestContext = {}; |
| 411 |
|
| 412 |
# take syspref 'opacuserlogin' and save its current value |
| 413 |
my $current_pref_value = C4::Context->preference("opacuserlogin"); |
| 414 |
|
| 415 |
is($current_pref_value, $current_pref_value, "System Preference 'opacuserlogin' original value '".(($current_pref_value) ? $current_pref_value : 0)."'"); |
| 416 |
|
| 417 |
# reverse the value for testing |
| 418 |
my $pref_new_value = !$current_pref_value; |
| 419 |
|
| 420 |
|
| 421 |
my $objects = t::lib::TestObjects::SystemPreferenceFactory->createTestGroup([ |
| 422 |
{preference => 'opacuserlogin', |
| 423 |
value => $pref_new_value # set the reversed value |
| 424 |
}, |
| 425 |
], undef, $subtestContext, undef, undef); |
| 426 |
|
| 427 |
is(C4::Context->preference("opacuserlogin"), $pref_new_value, "System Preference opacuserlogin reversed to '".(($pref_new_value) ? $pref_new_value:0)."'"); |
| 428 |
|
| 429 |
# let's change it again to test that only the original preference value is saved |
| 430 |
$objects = t::lib::TestObjects::SystemPreferenceFactory->createTestGroup([ |
| 431 |
{preference => 'opacuserlogin', |
| 432 |
value => 2 # set the reversed value |
| 433 |
}, |
| 434 |
], undef, $subtestContext, undef, undef); |
| 435 |
|
| 436 |
is(C4::Context->preference("opacuserlogin"), 2, "System Preference opacuserlogin set to '2'"); |
| 437 |
|
| 438 |
#Delete them |
| 439 |
t::lib::TestObjects::ObjectFactory->tearDownTestContext($subtestContext); |
| 440 |
is(C4::Context->preference("opacuserlogin"), $current_pref_value, "System Preference opacuserlogin restored to '".(($current_pref_value) ? $current_pref_value:0)."' after test group deletion"); |
| 441 |
}; |
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
########## Global test context subtests ########## |
| 446 |
subtest 't::lib::TestObjects::ObjectFactory clearing global test context' => sub { |
| 447 |
my $object11A001 = Koha::Borrowers->find({cardnumber => '11A001'}); |
| 448 |
ok ($object11A001, "Global Borrower '11A001' exists"); |
| 449 |
my $object11A002 = Koha::Borrowers->find({cardnumber => '11A002'}); |
| 450 |
ok ($object11A002, "Global Borrower '11A002' exists"); |
| 451 |
|
| 452 |
my $object1 = Koha::Items->find({barcode => '167Nabe0001'}); |
| 453 |
ok ($object1, "Global Item '167Nabe0001' exists"); |
| 454 |
my $object2 = Koha::Items->find({barcode => '167Nabe0002'}); |
| 455 |
ok ($object2, "Global Item '167Nabe0002' exists"); |
| 456 |
my $object3 = Koha::Biblios->find({title => 'I wish I met your mother', author => "Pertti Kurikka"}); |
| 457 |
ok ($object2, "Global Biblio 'I wish I met your mother' exists"); |
| 458 |
|
| 459 |
t::lib::TestObjects::ObjectFactory->tearDownTestContext($testContext); |
| 460 |
|
| 461 |
$object11A001 = Koha::Borrowers->find({cardnumber => '11A001'}); |
| 462 |
ok (not($object11A001), "Global Borrower '11A001' deleted"); |
| 463 |
$object11A002 = Koha::Borrowers->find({cardnumber => '11A002'}); |
| 464 |
ok (not($object11A002), "Global Borrower '11A002' deleted"); |
| 465 |
|
| 466 |
$object1 = Koha::Items->find({barcode => '167Nabe0001'}); |
| 467 |
ok (not($object1), "Global Item '167Nabe0001' deleted"); |
| 468 |
$object2 = Koha::Items->find({barcode => '167Nabe0002'}); |
| 469 |
ok (not($object2), "Global Item '167Nabe0002' deleted"); |
| 470 |
$object3 = Koha::Biblios->find({title => 'I wish I met your mother', author => "Pertti Kurikka"}); |
| 471 |
ok (not($object2), "Global Biblio 'I wish I met your mother' deleted"); |
| 472 |
}; |
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
done_testing(); |
| 477 |
|
| 478 |
1; |