|
Lines 3-12
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 => 8; |
6 |
use Test::More tests => 10; |
|
|
7 |
use Readonly; |
| 8 |
|
| 9 |
Readonly my $F1 => 1; |
| 10 |
Readonly my $F2 => 2; |
| 11 |
Readonly my $F3 => 3; |
| 12 |
Readonly my $F4 => 4; |
| 13 |
Readonly my $F5 => 5; |
| 14 |
Readonly my $F6 => 6; |
| 7 |
|
15 |
|
| 8 |
BEGIN { |
16 |
BEGIN { |
| 9 |
use_ok('C4::NewsChannels'); |
17 |
use_ok('C4::NewsChannels'); |
| 10 |
} |
18 |
} |
| 11 |
|
19 |
|
| 12 |
my $dbh = C4::Context->dbh; |
20 |
my $dbh = C4::Context->dbh; |
|
Lines 16-92
$dbh->{AutoCommit} = 0;
Link Here
|
| 16 |
$dbh->{RaiseError} = 1; |
24 |
$dbh->{RaiseError} = 1; |
| 17 |
|
25 |
|
| 18 |
# Test add_opac_new |
26 |
# Test add_opac_new |
|
|
27 |
my $rv = add_opac_new(); # intentionally bad |
| 28 |
ok( $rv == 0, 'Correctly failed on no parameter!' ); |
| 29 |
|
| 19 |
my $timestamp = '2000-01-01'; |
30 |
my $timestamp = '2000-01-01'; |
| 20 |
my ( $timestamp1, $timestamp2 ) = ( $timestamp, $timestamp ); |
31 |
my ( $timestamp1, $timestamp2 ) = ( $timestamp, $timestamp ); |
| 21 |
my ($title1, $new1, |
32 |
my ( $title1, $new1, $lang1, $expirationdate1, $number1 ) = |
| 22 |
$lang1, $expirationdate1, $number1) = |
33 |
( 'News Title', '<p>We have some exciting news!</p>', q{}, '2999-12-30', 1 ); |
| 23 |
( 'News Title', '<p>We have some exciting news!</p>', |
34 |
my $href_entry1 = { |
| 24 |
'', '2999-12-30', 1 ); |
35 |
title => $title1, |
| 25 |
my $rv = add_opac_new( $title1, $new1, $lang1, $expirationdate1, $timestamp1, $number1 ); |
36 |
new => $new1, |
| 26 |
ok($rv==1,"Successfully added the first dummy news item!"); |
37 |
lang => $lang1, |
| 27 |
|
38 |
expirationdate => $expirationdate1, |
| 28 |
my ($title2, $new2, |
39 |
timestamp => $timestamp1, |
| 29 |
$lang2, $expirationdate2, $number2) = |
40 |
number => $number1, |
| 30 |
( 'News Title2', '<p>We have some exciting news!</p>', |
41 |
}; |
| 31 |
'', '2999-12-31', 1 ); |
42 |
|
| 32 |
$rv = add_opac_new( $title2, $new2, $lang2, $expirationdate2, $timestamp2, $number2 ); |
43 |
$rv = add_opac_new($href_entry1); |
| 33 |
ok($rv==1,"Successfully added the second dummy news item!"); |
44 |
ok( $rv == 1, 'Successfully added the first dummy news item!' ); |
|
|
45 |
|
| 46 |
my ( $title2, $new2, $lang2, $expirationdate2, $number2 ) = |
| 47 |
( 'News Title2', '<p>We have some exciting news!</p>', q{}, '2999-12-31', 1 ); |
| 48 |
my $href_entry2 = { |
| 49 |
title => $title2, |
| 50 |
new => $new2, |
| 51 |
lang => $lang2, |
| 52 |
expirationdate => $expirationdate2, |
| 53 |
timestamp => $timestamp2, |
| 54 |
number => $number2, |
| 55 |
}; |
| 56 |
$rv = add_opac_new($href_entry2); |
| 57 |
ok( $rv == 1, 'Successfully added the second dummy news item!' ); |
| 34 |
|
58 |
|
| 35 |
# We need to determine the idnew in a non-MySQLism way. |
59 |
# We need to determine the idnew in a non-MySQLism way. |
| 36 |
# This should be good enough. |
60 |
# This should be good enough. |
| 37 |
my $sth = $dbh->prepare(q{ |
61 |
my $query = |
| 38 |
SELECT idnew from opac_news |
62 |
q{ SELECT idnew from opac_news WHERE timestamp='2000-01-01' AND expirationdate='2999-12-30'; }; |
| 39 |
WHERE timestamp='2000-01-01' AND |
63 |
my $sth = $dbh->prepare($query); |
| 40 |
expirationdate='2999-12-30'; |
|
|
| 41 |
}); |
| 42 |
$sth->execute(); |
64 |
$sth->execute(); |
| 43 |
my $idnew1 = $sth->fetchrow; |
65 |
my $idnew1 = $sth->fetchrow; |
| 44 |
$sth = $dbh->prepare(q{ |
66 |
$query = |
| 45 |
SELECT idnew from opac_news |
67 |
q{ SELECT idnew from opac_news WHERE timestamp='2000-01-01' AND expirationdate='2999-12-31'; }; |
| 46 |
WHERE timestamp='2000-01-01' AND |
68 |
$sth = $dbh->prepare($query); |
| 47 |
expirationdate='2999-12-31'; |
|
|
| 48 |
}); |
| 49 |
$sth->execute(); |
69 |
$sth->execute(); |
| 50 |
my $idnew2 = $sth->fetchrow; |
70 |
my $idnew2 = $sth->fetchrow; |
| 51 |
|
71 |
|
| 52 |
# Test upd_opac_new |
72 |
# Test upd_opac_new |
| 53 |
$new2 = '<p>Update! There is no news!</p>'; |
73 |
$rv = upd_opac_new(); # intentionally bad parmeters |
| 54 |
$rv = upd_opac_new( $idnew2, $title2, $new2, $lang2, $expirationdate2, $timestamp2, $number2 ); |
74 |
ok( $rv == 0, 'Correctly failed on no parameter!' ); |
| 55 |
ok($rv==1,"Successfully updated second dummy news item!"); |
75 |
|
|
|
76 |
$new2 = '<p>Update! There is no news!</p>'; |
| 77 |
$href_entry2->{new} = $new2; |
| 78 |
$href_entry2->{idnew} = $idnew2; |
| 79 |
$rv = upd_opac_new($href_entry2); |
| 80 |
ok( $rv == 1, 'Successfully updated second dummy news item!' ); |
| 56 |
|
81 |
|
| 57 |
# Test get_opac_new (single news item) |
82 |
# Test get_opac_new (single news item) |
| 58 |
$timestamp1 = format_date( $timestamp1 ); |
83 |
$timestamp1 = format_date($timestamp1); |
| 59 |
$expirationdate1 = format_date( $expirationdate1 ); |
84 |
$expirationdate1 = format_date($expirationdate1); |
| 60 |
$timestamp2 = format_date( $timestamp2 ); |
85 |
$timestamp2 = format_date($timestamp2); |
| 61 |
$expirationdate2 = format_date( $expirationdate2 ); |
86 |
$expirationdate2 = format_date($expirationdate2); |
| 62 |
|
87 |
|
| 63 |
my $hashref_check = get_opac_new($idnew1); |
88 |
my $hashref_check = get_opac_new($idnew1); |
| 64 |
my $failure = 0; |
89 |
my $failure = 0; |
| 65 |
if ($hashref_check->{title} ne $title1) { $failure = 1; } |
90 |
if ( $hashref_check->{title} ne $title1 ) { $failure = $F1; } |
| 66 |
if ($hashref_check->{new} ne $new1) { $failure = 1; } |
91 |
if ( $hashref_check->{new} ne $new1 ) { $failure = $F2; } |
| 67 |
if ($hashref_check->{lang} ne $lang1) { $failure = 1; } |
92 |
if ( $hashref_check->{lang} ne $lang1 ) { $failure = $F3; } |
| 68 |
if ($hashref_check->{expirationdate} ne $expirationdate1) { $failure = 1; } |
93 |
if ( $hashref_check->{expirationdate} ne $expirationdate1 ) { $failure = $F4; } |
| 69 |
if ($hashref_check->{timestamp} ne $timestamp1) { $failure = 1; } |
94 |
if ( $hashref_check->{timestamp} ne $timestamp1 ) { $failure = $F5; } |
| 70 |
if ($hashref_check->{number} ne $number1) { $failure = 1; } |
95 |
if ( $hashref_check->{number} ne $number1 ) { $failure = $F6; } |
| 71 |
ok($failure==0,"Successfully tested get_opac_new id1!"); |
96 |
ok( $failure == 0, "Successfully tested get_opac_new id1 ($failure)!" ); |
| 72 |
|
97 |
|
| 73 |
# Test get_opac_new (single news item) |
98 |
# Test get_opac_new (single news item) |
| 74 |
$hashref_check = get_opac_new($idnew2); |
99 |
$hashref_check = get_opac_new($idnew2); |
| 75 |
$failure = 0; |
100 |
$failure = 0; |
| 76 |
if ($hashref_check->{title} ne $title2) { $failure = 1; } |
101 |
if ( $hashref_check->{title} ne $title2 ) { $failure = $F1; } |
| 77 |
if ($hashref_check->{new} ne $new2) { $failure = 1; } |
102 |
if ( $hashref_check->{new} ne $new2 ) { $failure = $F2; } |
| 78 |
if ($hashref_check->{lang} ne $lang2) { $failure = 1; } |
103 |
if ( $hashref_check->{lang} ne $lang2 ) { $failure = $F3; } |
| 79 |
if ($hashref_check->{expirationdate} ne $expirationdate2) { $failure = 1; } |
104 |
if ( $hashref_check->{expirationdate} ne $expirationdate2 ) { $failure = $F4; } |
| 80 |
if ($hashref_check->{timestamp} ne $timestamp2) { $failure = 1; } |
105 |
if ( $hashref_check->{timestamp} ne $timestamp2 ) { $failure = $F5; } |
| 81 |
if ($hashref_check->{number} ne $number2) { $failure = 1; } |
106 |
if ( $hashref_check->{number} ne $number2 ) { $failure = $F6; } |
| 82 |
ok($failure==0,"Successfully tested get_opac_new id2!"); |
107 |
ok( $failure == 0, "Successfully tested get_opac_new id2 ($failure)!" ); |
| 83 |
|
108 |
|
| 84 |
# Test get_opac_news (multiple news items) |
109 |
# Test get_opac_news (multiple news items) |
| 85 |
my ($opac_news_count, $arrayref_opac_news) = get_opac_news(0,''); |
110 |
my ( $opac_news_count, $arrayref_opac_news ) = get_opac_news( 0, q{} ); |
| 86 |
ok($opac_news_count>=2,"Successfully tested get_opac_news!"); |
111 |
ok( $opac_news_count >= 2, 'Successfully tested get_opac_news!' ); |
| 87 |
|
112 |
|
| 88 |
# Test GetNewsToDisplay |
113 |
# Test GetNewsToDisplay |
| 89 |
($opac_news_count, $arrayref_opac_news) = GetNewsToDisplay(''); |
114 |
( $opac_news_count, $arrayref_opac_news ) = GetNewsToDisplay(q{}); |
| 90 |
ok($opac_news_count>=2,"Successfully tested GetNewsToDisplay!"); |
115 |
ok( $opac_news_count >= 2, 'Successfully tested GetNewsToDisplay!' ); |
| 91 |
|
116 |
|
| 92 |
$dbh->rollback; |
117 |
$dbh->rollback; |