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

(-)a/t/db_dependent/Koha/Patrons.t (-1 / +66 lines)
Lines 19-27 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 12;
22
use Test::More tests => 13;
23
use Test::Warn;
23
use Test::Warn;
24
use DateTime;
24
25
26
use C4::Biblio;
25
use C4::Members;
27
use C4::Members;
26
use C4::Circulation;
28
use C4::Circulation;
27
29
Lines 513-518 subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub { Link Here
513
    Koha::Patrons->find( $userenv_patron->{borrowernumber})->delete;
515
    Koha::Patrons->find( $userenv_patron->{borrowernumber})->delete;
514
};
516
};
515
517
518
subtest 'get_overdues' => sub {
519
    plan tests => 3;
520
521
    my $library = $builder->build( { source => 'Branch' } );
522
    my ($biblionumber_1) = AddBiblio( MARC::Record->new, '' );
523
    my $item_1 = $builder->build(
524
        {
525
            source => 'Item',
526
            value  => {
527
                homebranch    => $library->{branchcode},
528
                holdingbranch => $library->{branchcode},
529
                biblionumber  => $biblionumber_1
530
            }
531
        }
532
    );
533
    my $item_2 = $builder->build(
534
        {
535
            source => 'Item',
536
            value  => {
537
                homebranch    => $library->{branchcode},
538
                holdingbranch => $library->{branchcode},
539
                biblionumber  => $biblionumber_1
540
            }
541
        }
542
    );
543
    my ($biblionumber_2) = AddBiblio( MARC::Record->new, '' );
544
    my $item_3 = $builder->build(
545
        {
546
            source => 'Item',
547
            value  => {
548
                homebranch    => $library->{branchcode},
549
                holdingbranch => $library->{branchcode},
550
                biblionumber  => $biblionumber_2
551
            }
552
        }
553
    );
554
    my $patron = $builder->build(
555
        {
556
            source => 'Borrower',
557
            value  => { branchcode => $library->{branchcode} }
558
        }
559
    );
560
561
    # Not sure how this is useful, but AddIssue pass this variable to different other subroutines
562
    $patron = GetMember( borrowernumber => $patron->{borrowernumber} );
563
564
    my $module = new Test::MockModule('C4::Context');
565
    $module->mock( 'userenv', sub { { branch => $library->{branchcode} } } );
566
567
    AddIssue( $patron, $item_1->{barcode}, DateTime->now->subtract( days => 1 ) );
568
    AddIssue( $patron, $item_2->{barcode}, DateTime->now->subtract( days => 5 ) );
569
    AddIssue( $patron, $item_3->{barcode} );
570
571
    my $overdues = C4::Members::GetOverduesForPatron( $patron->{borrowernumber} );
572
    is( @$overdues, 2, 'GetOverduesForPatron should return the correct number of elements' );
573
    is( $overdues->[0]->{itemnumber}, $item_1->{itemnumber}, 'The issue should be returned in the same order as they have been done, first is correct' );
574
    is( $overdues->[1]->{itemnumber}, $item_2->{itemnumber}, 'The issue should be returned in the same order as they have been done, second is correct' );
575
576
    # Clean stuffs
577
    Koha::Issues->search( { borrowernumber => $patron->{borrowernumber} } )->delete;
578
    Koha::Patrons->find( $patron->{borrowernumber} )->delete;
579
};
580
516
$retrieved_patron_1->delete;
581
$retrieved_patron_1->delete;
517
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' );
582
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' );
518
583
(-)a/t/db_dependent/Members/GetOverdues.t (-63 lines)
Lines 1-62 Link Here
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
5
use Test::More tests => 3;
6
use Test::MockModule;
7
8
use C4::Biblio;
9
use C4::Items;
10
use C4::Members;
11
use C4::Circulation;
12
use Koha::Libraries;
13
use MARC::Record;
14
15
my $dbh = C4::Context->dbh;
16
$dbh->{AutoCommit} = 0;
17
$dbh->{RaiseError} = 1;
18
19
$dbh->do(q|DELETE FROM issues|);
20
$dbh->do(q|DELETE FROM borrowers|);
21
$dbh->do(q|DELETE FROM items|);
22
$dbh->do(q|DELETE FROM branches|);
23
$dbh->do(q|DELETE FROM biblio|);
24
$dbh->do(q|DELETE FROM categories|);
25
26
my $branchcode = 'B';
27
Koha::Library->new( { branchcode => $branchcode, branchname => 'Branch' } )->store;
28
29
my $categorycode = 'C';
30
$dbh->do( "INSERT INTO categories(categorycode) VALUES(?)",
31
    undef, $categorycode );
32
33
my %item_branch_infos = (
34
    homebranch    => $branchcode,
35
    holdingbranch => $branchcode,
36
);
37
38
my ($biblionumber1) = AddBiblio( MARC::Record->new, '' );
39
my $itemnumber1 =
40
  AddItem( { barcode => '0101', %item_branch_infos }, $biblionumber1 );
41
my $itemnumber2 =
42
  AddItem( { barcode => '0102', %item_branch_infos }, $biblionumber1 );
43
44
my ($biblionumber2) = AddBiblio( MARC::Record->new, '' );
45
my $itemnumber3 =
46
  AddItem( { barcode => '0103', %item_branch_infos }, $biblionumber2 );
47
48
my $borrowernumber =
49
  AddMember( categorycode => $categorycode, branchcode => $branchcode );
50
my $borrower = GetMember( borrowernumber => $borrowernumber );
51
52
my $module = new Test::MockModule('C4::Context');
53
$module->mock( 'userenv', sub { { branch => $branchcode } } );
54
55
AddIssue( $borrower, '0101', DateTime->now->subtract( days =>  1 ) );
56
AddIssue( $borrower, '0102', DateTime->now->subtract( days =>  5 ) );
57
AddIssue( $borrower, '0103' );
58
59
my $overdues = C4::Members::GetOverduesForPatron( $borrowernumber );
60
is( @$overdues, 2, 'GetOverduesForPatron returns the correct number of elements' );
61
is( $overdues->[0]->{itemnumber}, $itemnumber1, 'First overdue is correct' );
62
is( $overdues->[1]->{itemnumber}, $itemnumber2, 'Second overdue is correct' );
63
- 

Return to bug 17553