View | Details | Raw Unified | Return to bug 17562
Collapse All | Expand All

(-)a/t/db_dependent/Acquisition.t (-449 / +1 lines)
Lines 19-25 use Modern::Perl; Link Here
19
19
20
use POSIX qw(strftime);
20
use POSIX qw(strftime);
21
21
22
use Test::More tests => 92;
22
use Test::More tests => 65;
23
use Koha::Database;
23
use Koha::Database;
24
24
25
BEGIN {
25
BEGIN {
Lines 273-665 for ( 0 .. 4 ) { Link Here
273
    $order_content[$_]->{str}->{ordernumber} = $ordernumbers[$_];
273
    $order_content[$_]->{str}->{ordernumber} = $ordernumbers[$_];
274
}
274
}
275
275
276
# Test UT sub _check_fields_of_order
277
278
my (
279
    $test_missing_fields,   $test_extra_fields,
280
    $test_different_fields, $test_nbr_fields
281
  )
282
  = _check_fields_of_order(
283
    [qw /a b c d e/],
284
    { str => { a => "bla", b => "105" }, num => { c => 15.12 } },
285
    { a => "blabla", f => "f", b => "105", c => 15.1200, g => '' }
286
  );
287
ok(
288
    (
289
              ( $test_nbr_fields == 5 )
290
          and ( join( " ", sort @$test_missing_fields ) eq 'd e' )
291
          and ( join( " ", sort @$test_extra_fields )   eq 'f g' )
292
          and ( join( " ", @$test_different_fields )    eq 'a' )
293
    ),
294
    "_check_fields_of_order can check an order (test 1)"
295
);
296
(
297
    $test_missing_fields,   $test_extra_fields,
298
    $test_different_fields, $test_nbr_fields
299
  )
300
  = _check_fields_of_order(
301
    [qw /a b c /],
302
    { str => { a => "bla", b => "105" }, num => { c => 15.00 } },
303
    { a => "bla", b => "105", c => 15 }
304
  );
305
ok(
306
    (
307
              ( $test_nbr_fields == 3 )
308
          and ( scalar @$test_missing_fields == 0 )
309
          and ( scalar @$test_extra_fields == 0 )
310
          and ( scalar @$test_different_fields == 0 )
311
    ),
312
    "_check_fields_of_order can check an order (test 2)"
313
);
314
(
315
    $test_missing_fields,   $test_extra_fields,
316
    $test_different_fields, $test_nbr_fields
317
  )
318
  = _check_fields_of_order(
319
    [qw /a b c d e/],
320
    { str => { a => "bla", b => "105" }, num => { c => 15.12 } },
321
    { a => "blabla", b => "105", c => 15, d => "error" }
322
  );
323
ok(
324
    (
325
              ( $test_nbr_fields == 4 )
326
          and ( join( " ", sort @$test_missing_fields ) eq 'e' )
327
          and ( scalar @$test_extra_fields == 0 )
328
          and ( join( " ", @$test_different_fields ) eq 'a c' )
329
    ),
330
    "_check_fields_of_order can check an order (test 3)"
331
);
332
333
#
334
# test GetOrder
335
#
336
337
my @expectedfields = qw(
338
  order_internalnote
339
  order_vendornote
340
  ordernumber
341
  biblionumber
342
  entrydate
343
  quantity
344
  currency
345
  listprice
346
  datereceived
347
  invoiceid
348
  freight
349
  unitprice
350
  unitprice_tax_included
351
  unitprice_tax_excluded
352
  quantityreceived
353
  datecancellationprinted
354
  purchaseordernumber
355
  basketno
356
  timestamp
357
  rrp
358
  rrp_tax_included
359
  rrp_tax_excluded
360
  ecost
361
  ecost_tax_included
362
  ecost_tax_excluded
363
  unitpricesupplier
364
  unitpricelib
365
  tax_rate
366
  tax_value
367
  discount
368
  budget_id
369
  budgetdate
370
  sort1
371
  sort2
372
  sort1_authcat
373
  sort2_authcat
374
  uncertainprice
375
  claims_count
376
  claimed_date
377
  subscriptionid
378
  parent_ordernumber
379
  orderstatus
380
  line_item_id
381
  suppliers_reference_number
382
  suppliers_reference_qualifier
383
  suppliers_report
384
  title
385
  author
386
  basketname
387
  branchcode
388
  publicationyear
389
  copyrightdate
390
  editionstatement
391
  isbn
392
  ean
393
  seriestitle
394
  publishercode
395
  publisher
396
  budget
397
  supplier
398
  supplierid
399
  estimateddeliverydate
400
  orderdate
401
  quantity_to_receive
402
  subtotal
403
  latesince
404
  cancellationreason
405
);
406
(
407
    $test_missing_fields,   $test_extra_fields,
408
    $test_different_fields, $test_nbr_fields
409
  )
410
  = _check_fields_of_order( \@expectedfields, $order_content[0],
411
    GetOrder( $ordernumbers[0] ) );
412
is(
413
    $test_nbr_fields,
414
    scalar @expectedfields,
415
    "GetOrder gets an order with the right number of fields"
416
);
417
is( join( " ", @$test_missing_fields ),
418
    '', "GetOrder gets an order with no missing fields" );
419
is( join( " ", @$test_extra_fields ),
420
    '', "GetOrder gets an order with no unexpected fields" );
421
is( join( " ", @$test_different_fields ),
422
    '', "GetOrder gets an order with the right content in every fields" );
423
424
#
425
# Test GetOrders
426
#
427
428
my @base_expectedfields = qw(
429
  order_internalnote
430
  order_vendornote
431
  notes
432
  ordernumber
433
  ecost
434
  ecost_tax_included
435
  ecost_tax_excluded
436
  uncertainprice
437
  url
438
  isbn
439
  copyrightdate
440
  serial
441
  cn_suffix
442
  cn_item
443
  marcxml
444
  freight
445
  cn_class
446
  title
447
  pages
448
  budget_encumb
449
  budget_name
450
  number
451
  itemtype
452
  totalissues
453
  author
454
  budget_permission
455
  parent_ordernumber
456
  size
457
  claims_count
458
  currency
459
  seriestitle
460
  timestamp
461
  editionstatement
462
  budget_parent_id
463
  publishercode
464
  unitprice
465
  unitprice_tax_included
466
  unitprice_tax_excluded
467
  collectionvolume
468
  budget_amount
469
  budget_owner_id
470
  datecreated
471
  claimed_date
472
  subscriptionid
473
  editionresponsibility
474
  sort2
475
  volumedate
476
  budget_id
477
  illus
478
  ean
479
  biblioitemnumber
480
  datereceived
481
  orderstatus
482
  line_item_id
483
  suppliers_reference_number
484
  suppliers_reference_qualifier
485
  suppliers_report
486
  agerestriction
487
  budget_branchcode
488
  tax_rate
489
  tax_value
490
  listprice
491
  budget_code
492
  budgetdate
493
  basketno
494
  discount
495
  abstract
496
  collectionissn
497
  publicationyear
498
  collectiontitle
499
  invoiceid
500
  place
501
  issn
502
  quantityreceived
503
  entrydate
504
  cn_source
505
  sort1_authcat
506
  budget_notes
507
  biblionumber
508
  unititle
509
  sort2_authcat
510
  budget_expend
511
  rrp
512
  rrp_tax_included
513
  rrp_tax_excluded
514
  cn_sort
515
  lccn
516
  sort1
517
  volume
518
  purchaseordernumber
519
  quantity
520
  budget_period_id
521
  frameworkcode
522
  volumedesc
523
  datecancellationprinted
524
  cancellationreason
525
);
526
@expectedfields =
527
  ( @base_expectedfields,
528
    ( 'transferred_from_timestamp', 'transferred_from' ) );
529
is( GetOrders(), undef, "GetOrders with no params returns undef" );
530
DelOrder( $order_content[3]->{str}->{biblionumber}, $ordernumbers[3] );
276
DelOrder( $order_content[3]->{str}->{biblionumber}, $ordernumbers[3] );
531
my @get_orders = GetOrders($basketno);
532
(
533
    $test_missing_fields,   $test_extra_fields,
534
    $test_different_fields, $test_nbr_fields
535
  )
536
  = _check_fields_of_orders( \@expectedfields, \@order_content, \@get_orders );
537
is(
538
    $$test_nbr_fields[0],
539
    scalar @expectedfields,
540
    "GetOrders gets orders with the right number of fields"
541
);
542
is( join( " ", @$test_missing_fields ),
543
    '', "GetOrders gets orders with no missing fields" );
544
is( join( " ", @$test_extra_fields ),
545
    '', "GetOrders gets orders with no unexpected fields" );
546
is( join( " ", @$test_different_fields ),
547
    '', "GetOrders gets orders with the right content in every fields" );
548
ok(
549
    (
550
        ( scalar @get_orders == 4 )
551
          and !grep ( $_->{ordernumber} eq $ordernumbers[3], @get_orders )
552
    ),
553
    "GetOrders only gets non-cancelled orders"
554
);
555
556
#
557
# Test GetOrders { cancelled => 1 }
558
#
559
560
@expectedfields =
561
  ( @base_expectedfields, ( 'transferred_to_timestamp', 'transferred_to' ) );
562
@get_orders = GetOrders($basketno, { cancelled => 1 });
563
(
564
    $test_missing_fields,   $test_extra_fields,
565
    $test_different_fields, $test_nbr_fields
566
  )
567
  = _check_fields_of_orders( \@expectedfields, \@order_content, \@get_orders );
568
is(
569
    $$test_nbr_fields[0],
570
    scalar @expectedfields,
571
    "GetOrders { cancelled => 1 } gets orders with the right number of fields"
572
);
573
is( join( " ", @$test_missing_fields ),
574
    '', "GetOrders { cancelled => 1 } gets orders with no missing fields" );
575
is( join( " ", @$test_extra_fields ),
576
    '', "GetOrders { cancelled => 1 } gets orders with no unexpected fields" );
577
is( join( " ", @$test_different_fields ),
578
    '',
579
    "GetOrders { cancelled => 1 } gets orders with the right content in every fields" );
580
ok(
581
    (
582
        ( scalar @get_orders == 1 )
583
          and grep ( $_->{ordernumber} eq $ordernumbers[3], @get_orders )
584
    ),
585
    "GetOrders { cancelled => 1 } only gets cancelled orders"
586
);
587
588
#
589
# Test SearchOrders
590
#
591
592
@expectedfields = qw (
593
  order_internalnote
594
  order_vendornote
595
  notes
596
  basketgroupid
597
  basketgroupname
598
  firstname
599
  biblioitemnumber
600
  ecost
601
  ecost_tax_included
602
  ecost_tax_excluded
603
  uncertainprice
604
  creationdate
605
  datereceived
606
  orderstatus
607
  line_item_id
608
  suppliers_reference_number
609
  suppliers_reference_qualifier
610
  suppliers_report
611
  isbn
612
  copyrightdate
613
  tax_rate
614
  tax_value
615
  serial
616
  listprice
617
  budgetdate
618
  basketno
619
  discount
620
  surname
621
  freight
622
  abstract
623
  title
624
  closedate
625
  basketname
626
  invoiceid
627
  author
628
  parent_ordernumber
629
  claims_count
630
  entrydate
631
  currency
632
  quantityreceived
633
  seriestitle
634
  sort1_authcat
635
  timestamp
636
  biblionumber
637
  unititle
638
  sort2_authcat
639
  rrp
640
  rrp_tax_included
641
  rrp_tax_excluded
642
  unitprice
643
  unitprice_tax_included
644
  unitprice_tax_excluded
645
  sort1
646
  ordernumber
647
  datecreated
648
  purchaseordernumber
649
  quantity
650
  claimed_date
651
  subscriptionid
652
  frameworkcode
653
  sort2
654
  datecancellationprinted
655
  budget_id
656
  authorisedby
657
  booksellerid
658
  cancellationreason
659
);
660
661
# note that authorisedby was added to the return of SearchOrder by the
662
# patch for bug 11777
663
277
664
my $invoiceid = AddInvoice(
278
my $invoiceid = AddInvoice(
665
    invoicenumber => 'invoice',
279
    invoicenumber => 'invoice',
Lines 684-706 my $search_orders = SearchOrders({ Link Here
684
    basketno     => $basketno
298
    basketno     => $basketno
685
});
299
});
686
isa_ok( $search_orders, 'ARRAY' );
300
isa_ok( $search_orders, 'ARRAY' );
687
(
688
    $test_missing_fields,   $test_extra_fields,
689
    $test_different_fields, $test_nbr_fields
690
  )
691
  = _check_fields_of_orders( \@expectedfields, \@order_content,
692
    $search_orders );
693
is(
694
    $$test_nbr_fields[0],
695
    scalar @expectedfields,
696
    "SearchOrders gets orders with the right number of fields"
697
);
698
is( join( " ", @$test_missing_fields ),
699
    '', "SearchOrders gets orders with no missing fields" );
700
is( join( " ", @$test_extra_fields ),
701
    '', "SearchOrders gets orders with no unexpected fields" );
702
is( join( " ", @$test_different_fields ),
703
    '', "SearchOrders gets orders with the right content in every fields" );
704
ok(
301
ok(
705
    (
302
    (
706
        ( scalar @$search_orders == 4 )
303
        ( scalar @$search_orders == 4 )
Lines 755-788 is( scalar (@$search_orders), 0, "SearchOrders takes into account the biblionumb Link Here
755
ok( GetBudgetByOrderNumber( $ordernumbers[0] )->{'budget_id'} eq $budgetid,
352
ok( GetBudgetByOrderNumber( $ordernumbers[0] )->{'budget_id'} eq $budgetid,
756
    "GetBudgetByOrderNumber returns expected budget" );
353
    "GetBudgetByOrderNumber returns expected budget" );
757
354
758
#
759
# Test GetLateOrders
760
#
761
762
@expectedfields = qw (
763
  orderdate
764
  author
765
  budget
766
  supplierid
767
  claims_count
768
  supplier
769
  publisher
770
  ordernumber
771
  quantity
772
  basketno
773
  claimed_date
774
  branch
775
  estimateddeliverydate
776
  title
777
  publicationyear
778
  unitpricelib
779
  unitpricesupplier
780
  subtotal
781
  latesince
782
  basketname
783
  basketgroupid
784
  basketgroupname
785
);
786
my @lateorders = GetLateOrders(0);
355
my @lateorders = GetLateOrders(0);
787
is( scalar grep ( $_->{basketno} eq $basketno, @lateorders ),
356
is( scalar grep ( $_->{basketno} eq $basketno, @lateorders ),
788
    0, "GetLateOrders does not get orders from opened baskets" );
357
    0, "GetLateOrders does not get orders from opened baskets" );
Lines 794-815 ok( !grep ( $_->{ordernumber} eq $ordernumbers[3], @lateorders ), Link Here
794
    "GetLateOrders does not gets cancelled orders" );
363
    "GetLateOrders does not gets cancelled orders" );
795
ok( !grep ( $_->{ordernumber} eq $ordernumbers[4], @lateorders ),
364
ok( !grep ( $_->{ordernumber} eq $ordernumbers[4], @lateorders ),
796
    "GetLateOrders does not gets reveived orders" );
365
    "GetLateOrders does not gets reveived orders" );
797
(
798
    $test_missing_fields,   $test_extra_fields,
799
    $test_different_fields, $test_nbr_fields
800
  )
801
  = _check_fields_of_orders( \@expectedfields, \@order_content, \@lateorders );
802
is(
803
    $$test_nbr_fields[0],
804
    scalar @expectedfields,
805
    "GetLateOrders gets orders with the right number of fields"
806
);
807
is( join( " ", @$test_missing_fields ),
808
    '', "GetLateOrders gets orders with no missing fields" );
809
is( join( " ", @$test_extra_fields ),
810
    '', "GetLateOrders gets orders with no unexpected fields" );
811
is( join( " ", @$test_different_fields ),
812
    '', "GetLateOrders gets orders with the right content in every fields" );
813
366
814
$search_orders = SearchOrders({
367
$search_orders = SearchOrders({
815
    booksellerid => $booksellerid,
368
    booksellerid => $booksellerid,
816
- 

Return to bug 17562