4 use C4::Dates qw(format_date);
5 use C4::Branch qw(GetBranchName);
6 use Test::More tests => 10;
17 use_ok('C4::NewsChannels');
20 my $dbh = C4::Context->dbh;
23 $dbh->{AutoCommit} = 0;
24 $dbh->{RaiseError} = 1;
27 my $rv = add_opac_new(); # intentionally bad
28 ok( $rv == 0, 'Correctly failed on no parameter!' );
30 my $timestamp = '2000-01-01';
31 my ( $timestamp1, $timestamp2 ) = ( $timestamp, $timestamp );
32 my ( $title1, $new1, $lang1, $expirationdate1, $number1 ) =
33 ( 'News Title', '<p>We have some exciting news!</p>', q{}, '2999-12-30', 1 );
38 expirationdate => $expirationdate1,
39 timestamp => $timestamp1,
43 $rv = add_opac_new($href_entry1);
44 ok( $rv == 1, 'Successfully added the first dummy news item!' );
46 my ( $title2, $new2, $lang2, $expirationdate2, $number2 ) =
47 ( 'News Title2', '<p>We have some exciting news!</p>', q{}, '2999-12-31', 1 );
52 expirationdate => $expirationdate2,
53 timestamp => $timestamp2,
56 $rv = add_opac_new($href_entry2);
57 ok( $rv == 1, 'Successfully added the second dummy news item!' );
59 # We need to determine the idnew in a non-MySQLism way.
60 # This should be good enough.
62 q{ SELECT idnew from opac_news WHERE timestamp='2000-01-01' AND expirationdate='2999-12-30'; };
63 my $sth = $dbh->prepare($query);
65 my $idnew1 = $sth->fetchrow;
67 q{ SELECT idnew from opac_news WHERE timestamp='2000-01-01' AND expirationdate='2999-12-31'; };
68 $sth = $dbh->prepare($query);
70 my $idnew2 = $sth->fetchrow;
73 $rv = upd_opac_new(); # intentionally bad parmeters
74 ok( $rv == 0, 'Correctly failed on no parameter!' );
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!' );
82 # Test get_opac_new (single news item)
83 $timestamp1 = format_date($timestamp1);
84 $expirationdate1 = format_date($expirationdate1);
85 $timestamp2 = format_date($timestamp2);
86 $expirationdate2 = format_date($expirationdate2);
88 my $hashref_check = get_opac_new($idnew1);
90 if ( $hashref_check->{title} ne $title1 ) { $failure = $F1; }
91 if ( $hashref_check->{new} ne $new1 ) { $failure = $F2; }
92 if ( $hashref_check->{lang} ne $lang1 ) { $failure = $F3; }
93 if ( $hashref_check->{expirationdate} ne $expirationdate1 ) { $failure = $F4; }
94 if ( $hashref_check->{timestamp} ne $timestamp1 ) { $failure = $F5; }
95 if ( $hashref_check->{number} ne $number1 ) { $failure = $F6; }
96 ok( $failure == 0, "Successfully tested get_opac_new id1 ($failure)!" );
98 # Test get_opac_new (single news item)
99 $hashref_check = get_opac_new($idnew2);
101 if ( $hashref_check->{title} ne $title2 ) { $failure = $F1; }
102 if ( $hashref_check->{new} ne $new2 ) { $failure = $F2; }
103 if ( $hashref_check->{lang} ne $lang2 ) { $failure = $F3; }
104 if ( $hashref_check->{expirationdate} ne $expirationdate2 ) { $failure = $F4; }
105 if ( $hashref_check->{timestamp} ne $timestamp2 ) { $failure = $F5; }
106 if ( $hashref_check->{number} ne $number2 ) { $failure = $F6; }
107 ok( $failure == 0, "Successfully tested get_opac_new id2 ($failure)!" );
109 # Test get_opac_news (multiple news items)
110 my ( $opac_news_count, $arrayref_opac_news ) = get_opac_news( 0, q{} );
111 ok( $opac_news_count >= 2, 'Successfully tested get_opac_news!' );
113 # Test GetNewsToDisplay
114 ( $opac_news_count, $arrayref_opac_news ) = GetNewsToDisplay(q{});
115 ok( $opac_news_count >= 2, 'Successfully tested GetNewsToDisplay!' );