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

(-)a/t/db_dependent/NewsChannels.t (-2 / +44 lines)
Lines 3-9 Link Here
3
use Modern::Perl;
3
use Modern::Perl;
4
use C4::Dates qw(format_date);
4
use C4::Dates qw(format_date);
5
use C4::Branch qw(GetBranchName);
5
use C4::Branch qw(GetBranchName);
6
use Test::More tests => 10;
6
use Test::More tests => 11;
7
7
8
BEGIN {
8
BEGIN {
9
    use_ok('C4::NewsChannels');
9
    use_ok('C4::NewsChannels');
Lines 22-27 if ( !GetBranchName($addbra) ) { Link Here
22
        undef, ( $addbra, "$addbra branch" ) );
22
        undef, ( $addbra, "$addbra branch" ) );
23
}
23
}
24
24
25
# Add CAT1, if it doesn't exist.
26
my $addcat = 'CAT1';
27
{
28
    my $sth = $dbh->prepare( q{ SELECT categorycode FROM categories WHERE categorycode = ? } );
29
    $sth->execute ( $addcat );
30
    if ( not defined $sth->fetchrow () ) {
31
        diag("Category $addcat not found, inserting");
32
        $dbh->do( q{ INSERT INTO categories (categorycode,description) VALUES (?,?) },
33
            undef, ( $addcat, "$addcat description") );
34
    }
35
}
36
37
# Add a test user if not already present.
38
my $addbrwr = 'BRWR1';
39
my $brwrnmbr;
40
{
41
    my $query =
42
        q{ SELECT borrowernumber from borrowers WHERE surname = ? AND branchcode = ? AND categorycode = ? };
43
    my $sth = $dbh->prepare( $query );
44
    $sth->execute( ($addbrwr, $addbra, $addcat) );
45
    $brwrnmbr = $sth->fetchrow;
46
47
    # Not found, let us insert it.
48
    if ( not defined $brwrnmbr ) {
49
        diag("Borrower $addbrwr not found, inserting");
50
        $dbh->do( q{ INSERT INTO borrowers (surname, address, city, branchcode, categorycode) VALUES (?, ?, ?, ?, ?) },
51
            undef, ($addbrwr, '(test) address', '(test) city', $addbra, $addcat) );
52
53
        # Retrieve the njew borrower number.
54
        $query =
55
            q{ SELECT borrowernumber from borrowers WHERE surname = ? AND branchcode = ? AND categorycode = ? };
56
        my $sth = $dbh->prepare( $query );
57
        $sth->execute( ($addbrwr, $addbra, $addcat) );
58
        $brwrnmbr = $sth->fetchrow;
59
    }
60
}
61
62
# Must have valid borrower number, or tests are meaningless.
63
ok ( defined $brwrnmbr );
64
25
# Test add_opac_new
65
# Test add_opac_new
26
my $rv = add_opac_new();    # intentionally bad
66
my $rv = add_opac_new();    # intentionally bad
27
ok( $rv == 0, 'Correctly failed on no parameter!' );
67
ok( $rv == 0, 'Correctly failed on no parameter!' );
Lines 52-57 my $href_entry2 = { Link Here
52
    expirationdate => $expirationdate2,
92
    expirationdate => $expirationdate2,
53
    timestamp      => $timestamp2,
93
    timestamp      => $timestamp2,
54
    number         => $number2,
94
    number         => $number2,
95
    borrowernumber => $brwrnmbr,
55
    branchcode     => 'LIB1',
96
    branchcode     => 'LIB1',
56
};
97
};
57
$rv = add_opac_new($href_entry2);
98
$rv = add_opac_new($href_entry2);
Lines 95-100 is_deeply( Link Here
95
        expirationdate => $expirationdate1,
136
        expirationdate => $expirationdate1,
96
        timestamp      => $timestamp1,
137
        timestamp      => $timestamp1,
97
        number         => $number1,
138
        number         => $number1,
139
        borrowernumber => undef,
98
        idnew          => $idnew1,
140
        idnew          => $idnew1,
99
        branchname     => "$addbra branch",
141
        branchname     => "$addbra branch",
100
        branchcode     => $addbra,
142
        branchcode     => $addbra,
Lines 117-122 is_deeply( Link Here
117
        expirationdate => $expirationdate2,
159
        expirationdate => $expirationdate2,
118
        timestamp      => $timestamp2,
160
        timestamp      => $timestamp2,
119
        number         => $number2,
161
        number         => $number2,
162
        borrowernumber => $brwrnmbr,
120
        idnew          => $idnew2,
163
        idnew          => $idnew2,
121
        branchname     => "$addbra branch",
164
        branchname     => "$addbra branch",
122
        branchcode     => $addbra,
165
        branchcode     => $addbra,
123
- 

Return to bug 14247