|
Line 0
Link Here
|
|
|
1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
# Copyright KohaSuomi 2016 |
| 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 |
|
| 25 |
=head |
| 26 |
|
| 27 |
This is the old objectFactories.t which was split to pieces. |
| 28 |
Put each TestObjectFactory's tests to its own separate file. |
| 29 |
|
| 30 |
=cut |
| 31 |
|
| 32 |
use DateTime; |
| 33 |
|
| 34 |
use Koha::DateUtils; |
| 35 |
|
| 36 |
use t::lib::TestObjects::ObjectFactory; |
| 37 |
use t::lib::TestObjects::Serial::SubscriptionFactory; |
| 38 |
use Koha::Serials; |
| 39 |
use Koha::Subscriptions; |
| 40 |
use t::lib::TestObjects::PatronFactory; |
| 41 |
use Koha::Patrons; |
| 42 |
use t::lib::TestObjects::ItemFactory; |
| 43 |
use Koha::Items; |
| 44 |
use t::lib::TestObjects::BiblioFactory; |
| 45 |
use Koha::Biblios; |
| 46 |
use t::lib::TestObjects::CheckoutFactory; |
| 47 |
use Koha::Checkouts; |
| 48 |
use t::lib::TestObjects::LetterTemplateFactory; |
| 49 |
use Koha::Notice::Templates; |
| 50 |
use t::lib::TestObjects::FileFactory; |
| 51 |
use File::Slurp; |
| 52 |
use File::Fu::File; |
| 53 |
use t::lib::TestObjects::SystemPreferenceFactory; |
| 54 |
use t::lib::TestObjects::MessageQueueFactory; |
| 55 |
use C4::Letters; |
| 56 |
use t::lib::TestObjects::HoldFactory; |
| 57 |
use C4::Context; |
| 58 |
|
| 59 |
|
| 60 |
my $testContext = {}; #Gather all created Objects here so we can finally remove them all. |
| 61 |
my $now = DateTime->now(time_zone => C4::Context->tz()); |
| 62 |
my $year = $now->year(); |
| 63 |
|
| 64 |
|
| 65 |
########## SubscriptionFactory subtests ########## |
| 66 |
subtest "t::lib::TestObjects::SubscriptionFactory" => \&testSubscriptionFactory; |
| 67 |
sub testSubscriptionFactory { |
| 68 |
my $subtestContext = {}; |
| 69 |
my $biblionumber; #Get the biblionumber the test Subscription is for. |
| 70 |
|
| 71 |
eval { |
| 72 |
my $subscription = t::lib::TestObjects::Serial::SubscriptionFactory->createTestGroup( |
| 73 |
{internalnotes => 'TSUB1', |
| 74 |
receiveSerials => 5, |
| 75 |
staffdisplaycount => 10, |
| 76 |
opacdisplaycount => 15, |
| 77 |
}, |
| 78 |
undef, $subtestContext); |
| 79 |
$biblionumber = $subscription->biblionumber; |
| 80 |
|
| 81 |
C4::Context->interface('opac'); |
| 82 |
is($subscription->opacdisplaycount, |
| 83 |
15, |
| 84 |
"Get opacdisplaycount."); |
| 85 |
C4::Context->interface('opac'); |
| 86 |
is($subscription->staffdisplaycount, |
| 87 |
10, |
| 88 |
"Get staffdisplaycount."); |
| 89 |
|
| 90 |
my $serials = Koha::Serials->search({ |
| 91 |
subscriptionid => $subscription->subscriptionid |
| 92 |
})->as_list; |
| 93 |
ok($serials->[0]->serialseq_x == $year && |
| 94 |
$serials->[0]->serialseq_y == 1 && |
| 95 |
$serials->[0]->serialseq_z == 1, |
| 96 |
"Patterns x,y,z set for the first serial."); |
| 97 |
ok($serials->[2]->serialseq_x == $year && |
| 98 |
$serials->[2]->serialseq_y == 1 && |
| 99 |
$serials->[2]->serialseq_z == 3, |
| 100 |
"Patterns x,y,z set for the third serial."); |
| 101 |
ok($serials->[4]->serialseq_x == $year && |
| 102 |
$serials->[4]->serialseq_y == 2 && |
| 103 |
$serials->[4]->serialseq_z == 1, |
| 104 |
"Patterns x,y,z set for the fifth serial."); |
| 105 |
|
| 106 |
my @items = Koha::Items->search({biblionumber => $biblionumber}); |
| 107 |
is(scalar(@items), 5, "Created Items while receiving Serials"); |
| 108 |
}; |
| 109 |
if ($@) { |
| 110 |
ok(0, "Subtest crashed with error:\n$@\n"); |
| 111 |
} |
| 112 |
|
| 113 |
t::lib::TestObjects::ObjectFactory->tearDownTestContext($subtestContext); |
| 114 |
|
| 115 |
my @items = Koha::Items->search({biblionumber => $biblionumber}); |
| 116 |
is(scalar(@items), 0, "Created Items torn down"); |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
########## HoldFactory subtests ########## |
| 122 |
subtest 't::lib::TestObjects::HoldFactory' => \&testHoldFactory; |
| 123 |
sub testHoldFactory { |
| 124 |
my $subtestContext = {}; |
| 125 |
##Create and Delete using dependencies in the $testContext instantiated in previous subtests. |
| 126 |
my $hold = t::lib::TestObjects::HoldFactory->createTestGroup( |
| 127 |
{cardnumber => '1A01', |
| 128 |
isbn => '971', |
| 129 |
barcode => '1N01', |
| 130 |
branchcode => 'CPL', |
| 131 |
waitingdate => '2015-01-15', |
| 132 |
}, |
| 133 |
['cardnumber','isbn','barcode'], $subtestContext); |
| 134 |
|
| 135 |
is($hold->{branchcode}, |
| 136 |
'CPL', |
| 137 |
"Hold '1A01-971-1N01' pickup location is 'CPL'."); |
| 138 |
is($hold->{waitingdate}, |
| 139 |
'2015-01-15', |
| 140 |
"Hold '1A01-971-1N01' waiting date is '2015-01-15'."); |
| 141 |
|
| 142 |
#using the default test hold identifier reservenotes to distinguish hard-to-identify holds. |
| 143 |
my $holds2 = t::lib::TestObjects::HoldFactory->createTestGroup([ |
| 144 |
{cardnumber => '1A01', |
| 145 |
isbn => '971', |
| 146 |
barcode => '1N02', |
| 147 |
branchcode => 'CPL', |
| 148 |
reservenotes => 'nice hold', |
| 149 |
}, |
| 150 |
{cardnumber => '1A01', |
| 151 |
barcode => '1N03', |
| 152 |
isbn => '971', |
| 153 |
branchcode => 'CPL', |
| 154 |
reservenotes => 'better hold', |
| 155 |
}, |
| 156 |
], undef, $subtestContext); |
| 157 |
|
| 158 |
is($holds2->{'nice hold'}->{branchcode}, |
| 159 |
'CPL', |
| 160 |
"Hold 'nice hold' pickup location is 'CPL'."); |
| 161 |
is($holds2->{'nice hold'}->{borrower}->cardnumber, |
| 162 |
'1A01', |
| 163 |
"Hold 'nice hold' cardnumber is '1A01'."); |
| 164 |
is($holds2->{'better hold'}->{isbn}, |
| 165 |
'971', |
| 166 |
"Hold 'better hold' isbn '971'."); |
| 167 |
|
| 168 |
t::lib::TestObjects::HoldFactory->deleteTestGroup($subtestContext->{hold}); |
| 169 |
|
| 170 |
my $holds_deleted = Koha::Holds->search({biblionumber => $hold->{biblio}->{biblionumber}}); |
| 171 |
ok (not($holds_deleted->count), "Holds deleted"); |
| 172 |
}; |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
########## FileFactory subtests ########## |
| 177 |
subtest 't::lib::TestObjects::FileFactory' => \&testFileFactory; |
| 178 |
sub testFileFactory { |
| 179 |
my ($files); |
| 180 |
my $subtestContext = {}; |
| 181 |
|
| 182 |
$files = t::lib::TestObjects::FileFactory->createTestGroup([ |
| 183 |
{'filepath' => 'atomicupdate', |
| 184 |
'filename' => '#30-RabiesIsMyDog.pl', |
| 185 |
'content' => 'print "Mermaids are my only love\nI never let them down";', |
| 186 |
}, |
| 187 |
{'filepath' => 'atomicupdate', |
| 188 |
'filename' => '#31-FrogsArePeopleToo.pl', |
| 189 |
'content' => 'print "Listen to the Maker!";', |
| 190 |
}, |
| 191 |
{'filepath' => 'atomicupdate', |
| 192 |
'filename' => '#32-AnimalLover.pl', |
| 193 |
'content' => "print 'Do not hurt them!;", |
| 194 |
}, |
| 195 |
], undef, $subtestContext); |
| 196 |
|
| 197 |
my $file30content = File::Slurp::read_file( $files->{'#30-RabiesIsMyDog.pl'}->absolutely ); |
| 198 |
ok($file30content =~ m/Mermaids are my only love/, |
| 199 |
"'#30-RabiesIsMyDog.pl' created and content matches"); |
| 200 |
my $file31content = File::Slurp::read_file( $files->{'#31-FrogsArePeopleToo.pl'}->absolutely ); |
| 201 |
ok($file31content =~ m/Listen to the Maker!/, |
| 202 |
"'#31-FrogsArePeopleToo.pl' created and content matches"); |
| 203 |
my $file32content = File::Slurp::read_file( $files->{'#32-AnimalLover.pl'}->absolutely ); |
| 204 |
ok($file32content =~ m/Do not hurt them!/, |
| 205 |
"'#32-AnimalLover.pl' created and content matches"); |
| 206 |
|
| 207 |
##addToContext() test, create new file |
| 208 |
my $dir = $files->{'#32-AnimalLover.pl'}->dirname(); |
| 209 |
my $file = File::Fu::File->new("$dir/addToContext.txt"); |
| 210 |
$file->touch; |
| 211 |
t::lib::TestObjects::FileFactory->addToContext($file, undef, $subtestContext); |
| 212 |
ok($file->e, |
| 213 |
"'addToContext.txt' created"); |
| 214 |
|
| 215 |
t::lib::TestObjects::ObjectFactory->tearDownTestContext($subtestContext); |
| 216 |
|
| 217 |
ok(not(-e $files->{'#30-RabiesIsMyDog.pl'}->absolutely), |
| 218 |
"'#30-RabiesIsMyDog.pl' deleted"); |
| 219 |
ok(not(-e $files->{'#31-FrogsArePeopleToo.pl'}->absolutely), |
| 220 |
"'#31-FrogsArePeopleToo.pl' deleted"); |
| 221 |
ok(not(-e $files->{'#32-AnimalLover.pl'}->absolutely), |
| 222 |
"'#32-AnimalLover.pl' deleted"); |
| 223 |
ok(not(-e $file->absolutely), |
| 224 |
"'addToContext.txt' deleted"); |
| 225 |
}; |
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
########## PatronFactory subtests ########## |
| 230 |
subtest 't::lib::TestObjects::PatronFactory' => \&testPatronFactory; |
| 231 |
sub testPatronFactory { |
| 232 |
my $subtestContext = {}; |
| 233 |
##Create and Delete. Add one |
| 234 |
my $f = t::lib::TestObjects::PatronFactory->new(); |
| 235 |
my $objects = $f->createTestGroup([ |
| 236 |
{firstname => 'Olli-Antti', |
| 237 |
surname => 'Kivi', |
| 238 |
cardnumber => '11A001', |
| 239 |
branchcode => 'CPL', |
| 240 |
}, |
| 241 |
], undef, $subtestContext, undef, $testContext); |
| 242 |
is($objects->{'11A001'}->cardnumber, '11A001', "Patron '11A001'."); |
| 243 |
##Add one more to test incrementing the subtestContext. |
| 244 |
$objects = $f->createTestGroup([ |
| 245 |
{firstname => 'Olli-Antti2', |
| 246 |
surname => 'Kivi2', |
| 247 |
cardnumber => '11A002', |
| 248 |
branchcode => 'FFL', |
| 249 |
}, |
| 250 |
], undef, $subtestContext, undef, $testContext); |
| 251 |
is($subtestContext->{patron}->{'11A001'}->cardnumber, '11A001', "Patron '11A001' from \$subtestContext."); #From subtestContext |
| 252 |
is($objects->{'11A002'}->branchcode, 'FFL', "Patron '11A002'."); #from just created hash. |
| 253 |
|
| 254 |
##Delete objects |
| 255 |
t::lib::TestObjects::ObjectFactory->tearDownTestContext($subtestContext); |
| 256 |
foreach my $cn (('11A001', '11A002')) { |
| 257 |
ok (not(Koha::Patrons->find({cardnumber => $cn})), |
| 258 |
"Patron '11A001' deleted"); |
| 259 |
} |
| 260 |
|
| 261 |
#Prepare for global autoremoval. |
| 262 |
$objects = $f->createTestGroup([ |
| 263 |
{firstname => 'Olli-Antti', |
| 264 |
surname => 'Kivi', |
| 265 |
cardnumber => '11A001', |
| 266 |
branchcode => 'CPL', |
| 267 |
}, |
| 268 |
{firstname => 'Olli-Antti2', |
| 269 |
surname => 'Kivi2', |
| 270 |
cardnumber => '11A002', |
| 271 |
branchcode => 'FFL', |
| 272 |
}, |
| 273 |
], undef, undef, undef, $testContext); |
| 274 |
}; |
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
########## BiblioFactory and ItemFactory subtests ########## |
| 279 |
subtest 't::lib::TestObjects::BiblioFactory and ::ItemFactory' => \&testBiblioItemFactories; |
| 280 |
sub testBiblioItemFactories { |
| 281 |
my $subtestContext = {}; |
| 282 |
##Create and Delete. Add one |
| 283 |
my $biblios = t::lib::TestObjects::BiblioFactory->createTestGroup([ |
| 284 |
{'biblio.title' => 'I wish I met your mother', |
| 285 |
'biblio.author' => 'Pertti Kurikka', |
| 286 |
'biblio.copyrightdate' => '1960', |
| 287 |
'biblioitems.isbn' => '9519671580', |
| 288 |
'biblioitems.itemtype' => 'BK', |
| 289 |
}, |
| 290 |
], 'biblioitems.isbn', $subtestContext, undef, $testContext); |
| 291 |
my $objects = t::lib::TestObjects::ItemFactory->createTestGroup([ |
| 292 |
{biblionumber => $biblios->{9519671580}->{biblionumber}, |
| 293 |
barcode => '167Nabe0001', |
| 294 |
homebranch => 'CPL', |
| 295 |
holdingbranch => 'CPL', |
| 296 |
price => '0.50', |
| 297 |
replacementprice => '0.50', |
| 298 |
itype => 'BK', |
| 299 |
biblioisbn => '9519671580', |
| 300 |
itemcallnumber => 'PK 84.2', |
| 301 |
}, |
| 302 |
], 'barcode', $subtestContext, undef, $testContext); |
| 303 |
|
| 304 |
is($objects->{'167Nabe0001'}->barcode, '167Nabe0001', "Item '167Nabe0001'."); |
| 305 |
##Add one more to test incrementing the subtestContext. |
| 306 |
$objects = t::lib::TestObjects::ItemFactory->createTestGroup([ |
| 307 |
{biblionumber => $biblios->{9519671580}->{biblionumber}, |
| 308 |
barcode => '167Nabe0002', |
| 309 |
homebranch => 'CPL', |
| 310 |
holdingbranch => 'FFL', |
| 311 |
price => '3.50', |
| 312 |
replacementprice => '3.50', |
| 313 |
itype => 'BK', |
| 314 |
biblioisbn => '9519671580', |
| 315 |
itemcallnumber => 'JK 84.2', |
| 316 |
}, |
| 317 |
], 'barcode', $subtestContext, undef, $testContext); |
| 318 |
|
| 319 |
is($subtestContext->{item}->{'167Nabe0001'}->barcode, '167Nabe0001', "Item '167Nabe0001' from \$subtestContext."); |
| 320 |
is($objects->{'167Nabe0002'}->holdingbranch, 'FFL', "Item '167Nabe0002'."); |
| 321 |
is(ref($biblios->{9519671580}), 'MARC::Record', "Biblio 'I wish I met your mother'."); |
| 322 |
|
| 323 |
##Delete objects |
| 324 |
t::lib::TestObjects::ObjectFactory->tearDownTestContext($subtestContext); |
| 325 |
my $object1 = Koha::Items->find({barcode => '167Nabe0001'}); |
| 326 |
ok (not($object1), "Item '167Nabe0001' deleted"); |
| 327 |
my $object2 = Koha::Items->find({barcode => '167Nabe0002'}); |
| 328 |
ok (not($object2), "Item '167Nabe0002' deleted"); |
| 329 |
my $object3 = Koha::Biblios->find({title => 'I wish I met your mother', author => "Pertti Kurikka"}); |
| 330 |
ok (not($object2), "Biblio 'I wish I met your mother' deleted"); |
| 331 |
}; |
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
########## CheckoutFactory subtests ########## |
| 336 |
subtest 't::lib::TestObjects::CheckoutFactory' => \&testCheckoutFactory; |
| 337 |
sub testCheckoutFactory { |
| 338 |
my $subtestContext = {}; |
| 339 |
##Create and Delete using dependencies in the $testContext instantiated in previous subtests. |
| 340 |
my $biblios = t::lib::TestObjects::BiblioFactory->createTestGroup([ |
| 341 |
{'biblio.title' => 'I wish I met your mother', |
| 342 |
'biblio.author' => 'Pertti Kurikka', |
| 343 |
'biblio.copyrightdate' => '1960', |
| 344 |
'biblioitems.isbn' => '9519671580', |
| 345 |
'biblioitems.itemtype' => 'BK', |
| 346 |
}, |
| 347 |
], 'biblioitems.isbn', undef, undef, $subtestContext); |
| 348 |
my $items = t::lib::TestObjects::ItemFactory->createTestGroup([ |
| 349 |
{biblionumber => $biblios->{9519671580}->{biblionumber}, |
| 350 |
barcode => '167Nabe0001', |
| 351 |
homebranch => 'CPL', |
| 352 |
holdingbranch => 'CPL', |
| 353 |
price => '0.50', |
| 354 |
replacementprice => '0.50', |
| 355 |
itype => 'BK', |
| 356 |
biblioisbn => '9519671580', |
| 357 |
itemcallnumber => 'PK 84.2', |
| 358 |
}, |
| 359 |
{biblionumber => $biblios->{9519671580}->{biblionumber}, |
| 360 |
barcode => '167Nabe0002', |
| 361 |
homebranch => 'CPL', |
| 362 |
holdingbranch => 'FFL', |
| 363 |
price => '3.50', |
| 364 |
replacementprice => '3.50', |
| 365 |
itype => 'BK', |
| 366 |
biblioisbn => '9519671580', |
| 367 |
itemcallnumber => 'JK 84.2', |
| 368 |
}, |
| 369 |
], 'barcode', undef, undef, $subtestContext); |
| 370 |
my $objects = t::lib::TestObjects::CheckoutFactory->createTestGroup([ |
| 371 |
{ |
| 372 |
cardnumber => '11A001', |
| 373 |
barcode => '167Nabe0001', |
| 374 |
daysOverdue => 7, |
| 375 |
daysAgoCheckedout => 28, |
| 376 |
}, |
| 377 |
{ |
| 378 |
cardnumber => '11A002', |
| 379 |
barcode => '167Nabe0002', |
| 380 |
daysOverdue => -7, |
| 381 |
daysAgoCheckedout => 14, |
| 382 |
checkoutBranchRule => 'holdingbranch', |
| 383 |
}, |
| 384 |
], undef, undef, undef, undef); |
| 385 |
|
| 386 |
is($objects->{'11A001-167Nabe0001'}->branchcode, |
| 387 |
'CPL', |
| 388 |
"Checkout '11A001-167Nabe0001' checked out from the default context branch 'CPL'."); |
| 389 |
is($objects->{'11A002-167Nabe0002'}->branchcode, |
| 390 |
'FFL', |
| 391 |
"Checkout '11A002-167Nabe0002' checked out from the holdingbranch 'FFL'."); |
| 392 |
is(Koha::DateUtils::dt_from_string($objects->{'11A001-167Nabe0001'}->issuedate)->day(), |
| 393 |
DateTime->now(time_zone => C4::Context->tz())->subtract(days => '28')->day() |
| 394 |
, "Checkout '11A001-167Nabe0001', adjusted issuedates match."); |
| 395 |
is(Koha::DateUtils::dt_from_string($objects->{'11A002-167Nabe0002'}->date_due)->day(), |
| 396 |
DateTime->now(time_zone => C4::Context->tz())->subtract(days => '-7')->day() |
| 397 |
, "Checkout '11A002-167Nabe0002', adjusted date_dues match."); |
| 398 |
|
| 399 |
t::lib::TestObjects::CheckoutFactory->deleteTestGroup($objects); |
| 400 |
my $object1 = Koha::Checkouts->find({borrowernumber => $objects->{'11A001-167Nabe0001'}->borrowernumber, |
| 401 |
itemnumber => $objects->{'11A001-167Nabe0001'}->itemnumber}); |
| 402 |
ok (not($object1), "Checkout '11A001-167Nabe0001' deleted"); |
| 403 |
my $object2 = Koha::Checkouts->find({borrowernumber => $objects->{'11A002-167Nabe0002'}->borrowernumber, |
| 404 |
itemnumber => $objects->{'11A002-167Nabe0002'}->itemnumber}); |
| 405 |
ok (not($object2), "Checkout '11A002-167Nabe0002' deleted"); |
| 406 |
}; |
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
########## LetterTemplateFactory subtests ########## |
| 411 |
subtest 't::lib::TestObjects::LetterTemplateFactory' => \&testLetterTemplateFactory; |
| 412 |
sub testLetterTemplateFactory { |
| 413 |
my $subtestContext = {}; |
| 414 |
##Create and Delete using dependencies in the $testContext instantiated in previous subtests. |
| 415 |
my $f = t::lib::TestObjects::LetterTemplateFactory->new(); |
| 416 |
my $hashLT = {letter_id => 'circulation-ODUE1-CPL-print', |
| 417 |
module => 'circulation', |
| 418 |
code => 'ODUE1', |
| 419 |
branchcode => 'CPL', |
| 420 |
name => 'Notice1', |
| 421 |
is_html => undef, |
| 422 |
title => 'Notice1', |
| 423 |
message_transport_type => 'print', |
| 424 |
content => '<item>Barcode: <<items.barcode>>, bring it back!</item>', |
| 425 |
}; |
| 426 |
my $objects = $f->createTestGroup([ |
| 427 |
$hashLT, |
| 428 |
], undef, undef, undef, undef); |
| 429 |
|
| 430 |
my $letterTemplate = Koha::Notice::Templates->find($hashLT); |
| 431 |
is($objects->{'circulation-ODUE1-CPL-print'}->name, $letterTemplate->name, "LetterTemplate 'circulation-ODUE1-CPL-print'"); |
| 432 |
|
| 433 |
#Delete them |
| 434 |
$f->deleteTestGroup($objects); |
| 435 |
$letterTemplate = Koha::Notice::Templates->find($hashLT); |
| 436 |
ok(not(defined($letterTemplate)), "LetterTemplate 'circulation-ODUE1-CPL-print' deleted"); |
| 437 |
}; |
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
########## SystemPreferenceFactory subtests ########## |
| 442 |
subtest 't::lib::TestObjects::SystemPreferenceFactory' => \&testSystemPreferenceFactory; |
| 443 |
sub testSystemPreferenceFactory { |
| 444 |
my $subtestContext = {}; |
| 445 |
|
| 446 |
# take syspref 'opacuserlogin' and save its current value |
| 447 |
my $current_pref_value = C4::Context->preference("opacuserlogin"); |
| 448 |
|
| 449 |
is($current_pref_value, $current_pref_value, "System Preference 'opacuserlogin' original value '".(($current_pref_value) ? $current_pref_value : 0)."'"); |
| 450 |
|
| 451 |
# reverse the value for testing |
| 452 |
my $pref_new_value = !$current_pref_value || 0; |
| 453 |
|
| 454 |
my $objects = t::lib::TestObjects::SystemPreferenceFactory->createTestGroup([ |
| 455 |
{preference => 'opacuserlogin', |
| 456 |
value => $pref_new_value # set the reversed value |
| 457 |
}, |
| 458 |
], undef, $subtestContext, undef, undef); |
| 459 |
|
| 460 |
is(C4::Context->preference("opacuserlogin"), $pref_new_value, "System Preference opacuserlogin reversed to '".(($pref_new_value) ? $pref_new_value:0)."'"); |
| 461 |
|
| 462 |
# let's change it again to test that only the original preference value is saved |
| 463 |
$objects = t::lib::TestObjects::SystemPreferenceFactory->createTestGroup([ |
| 464 |
{preference => 'opacuserlogin', |
| 465 |
value => 2 # set the reversed value |
| 466 |
}, |
| 467 |
], undef, $subtestContext, undef, undef); |
| 468 |
|
| 469 |
is(C4::Context->preference("opacuserlogin"), 2, "System Preference opacuserlogin set to '2'"); |
| 470 |
|
| 471 |
#Delete them |
| 472 |
t::lib::TestObjects::ObjectFactory->tearDownTestContext($subtestContext); |
| 473 |
is(C4::Context->preference("opacuserlogin"), $current_pref_value, "System Preference opacuserlogin restored to '".(($current_pref_value) ? $current_pref_value:0)."' after test group deletion"); |
| 474 |
}; |
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
########## MessageQueueFactory subtests ########## |
| 479 |
subtest 't::lib::TestObjects::MessageQueueFactory' => \&testMessageQueueFactory; |
| 480 |
sub testMessageQueueFactory { |
| 481 |
my $subtestContext = {}; |
| 482 |
|
| 483 |
#Check if the precondition Patron exists, it shouldn't |
| 484 |
my $f = t::lib::TestObjects::PatronFactory->new(); |
| 485 |
my $objects = $f->createTestGroup([ |
| 486 |
{firstname => 'Olli-Antti', |
| 487 |
surname => 'Kivi', |
| 488 |
cardnumber => '1A23', |
| 489 |
branchcode => 'CPL', |
| 490 |
}, |
| 491 |
], undef, $subtestContext, undef, $testContext); |
| 492 |
|
| 493 |
#Create the MessageQueue |
| 494 |
my $messages = t::lib::TestObjects::MessageQueueFactory->createTestGroup([{ |
| 495 |
subject => "The quick brown fox", |
| 496 |
content => "Jumps over the lazy dog.", |
| 497 |
cardnumber => '1A23', |
| 498 |
message_transport_type => 'sms', |
| 499 |
from_address => '11A001@example.com', |
| 500 |
}, |
| 501 |
|
| 502 |
], undef, $subtestContext); |
| 503 |
|
| 504 |
# check that the message exists in queue |
| 505 |
my $queued_messages = C4::Letters->_get_unsent_messages(); |
| 506 |
|
| 507 |
my $found_testMessage = 0; |
| 508 |
foreach my $message (@$queued_messages){ |
| 509 |
if ($message->{from_address} eq '11A001@example.com'){ |
| 510 |
$found_testMessage = 1; |
| 511 |
last; |
| 512 |
} |
| 513 |
} |
| 514 |
|
| 515 |
ok($found_testMessage, 'MessageQueue \'11A001@example.com\', message_queue match.'); |
| 516 |
|
| 517 |
# delete the queued message |
| 518 |
t::lib::TestObjects::MessageQueueFactory->deleteTestGroup($messages); |
| 519 |
|
| 520 |
# confirm the deletion |
| 521 |
$queued_messages = C4::Letters->_get_unsent_messages(); |
| 522 |
|
| 523 |
$found_testMessage = 0; |
| 524 |
foreach my $message (@$queued_messages){ |
| 525 |
if ($message->{from_address} eq '11A001@example.com'){ |
| 526 |
$found_testMessage = 1; |
| 527 |
last; |
| 528 |
} |
| 529 |
} |
| 530 |
|
| 531 |
is($found_testMessage, 0, 'MessageQueue \'11A001@example.com\', deleted.'); |
| 532 |
|
| 533 |
#Delete them |
| 534 |
t::lib::TestObjects::ObjectFactory->tearDownTestContext($subtestContext); |
| 535 |
}; |
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
########## Global test context subtests ########## |
| 540 |
subtest 't::lib::TestObjects::ObjectFactory clearing global test context' => \&testGlobalSubtestContext; |
| 541 |
sub testGlobalSubtestContext { |
| 542 |
my $object11A001 = Koha::Patrons->find({cardnumber => '11A001'}); |
| 543 |
ok ($object11A001, "Global Patron '11A001' exists"); |
| 544 |
my $object11A002 = Koha::Patrons->find({cardnumber => '11A002'}); |
| 545 |
ok ($object11A002, "Global Patron '11A002' exists"); |
| 546 |
|
| 547 |
my $object1 = Koha::Items->find({barcode => '167Nabe0001'}); |
| 548 |
ok ($object1, "Global Item '167Nabe0001' exists"); |
| 549 |
my $object2 = Koha::Items->find({barcode => '167Nabe0002'}); |
| 550 |
ok ($object2, "Global Item '167Nabe0002' exists"); |
| 551 |
my $object3 = Koha::Biblios->find({title => 'I wish I met your mother', author => "Pertti Kurikka"}); |
| 552 |
ok ($object2, "Global Biblio 'I wish I met your mother' exists"); |
| 553 |
|
| 554 |
t::lib::TestObjects::ObjectFactory->tearDownTestContext($testContext); |
| 555 |
|
| 556 |
$object11A001 = Koha::Patrons->find({cardnumber => '11A001'}); |
| 557 |
ok (not($object11A001), "Global Patron '11A001' deleted"); |
| 558 |
$object11A002 = Koha::Patrons->find({cardnumber => '11A002'}); |
| 559 |
ok (not($object11A002), "Global Patron '11A002' deleted"); |
| 560 |
|
| 561 |
$object1 = Koha::Items->find({barcode => '167Nabe0001'}); |
| 562 |
ok (not($object1), "Global Item '167Nabe0001' deleted"); |
| 563 |
$object2 = Koha::Items->find({barcode => '167Nabe0002'}); |
| 564 |
ok (not($object2), "Global Item '167Nabe0002' deleted"); |
| 565 |
$object3 = Koha::Biblios->find({title => 'I wish I met your mother', author => "Pertti Kurikka"}); |
| 566 |
ok (not($object2), "Global Biblio 'I wish I met your mother' deleted"); |
| 567 |
}; |
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
done_testing(); |
| 572 |
=cut |
| 573 |
|
| 574 |
ok(1,"TODO:: Write test context interaction tests"); |
| 575 |
done_testing(); |