9 use Test::More tests => 4;
12 use_ok('C4::NewsChannels');
15 my $schema = Koha::Database->new->schema;
16 $schema->storage->txn_begin;
17 my $dbh = C4::Context->dbh;
19 # Add LIB1, if it doesn't exist.
21 unless ( Koha::Libraries->find($addbra) ) {
22 $dbh->do( q{ INSERT INTO branches (branchcode,branchname) VALUES (?,?) },
23 undef, ( $addbra, "$addbra branch" ) );
26 # Add CAT1, if it doesn't exist.
29 my $sth = $dbh->prepare( q{ SELECT categorycode FROM categories WHERE categorycode = ? } );
30 $sth->execute ( $addcat );
31 if ( not defined $sth->fetchrow () ) {
32 $dbh->do( q{ INSERT INTO categories (categorycode,description) VALUES (?,?) },
33 undef, ( $addcat, "$addcat description") );
37 # Add a test user if not already present.
38 my $addbrwr = 'BRWR1';
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;
47 # Not found, let us insert it.
48 if ( not defined $brwrnmbr ) {
49 $dbh->do( q{ INSERT INTO borrowers (surname, address, city, branchcode, categorycode) VALUES (?, ?, ?, ?, ?) },
50 undef, ($addbrwr, '(test) address', '(test) city', $addbra, $addcat) );
52 # Retrieve the njew borrower number.
54 q{ SELECT borrowernumber from borrowers WHERE surname = ? AND branchcode = ? AND categorycode = ? };
55 my $sth = $dbh->prepare( $query );
56 $sth->execute( ($addbrwr, $addbra, $addcat) );
57 $brwrnmbr = $sth->fetchrow;
61 # Must have valid borrower number, or tests are meaningless.
62 ok ( defined $brwrnmbr );
64 # Test GetNewsToDisplay
65 my ( $opac_news_count, $arrayref_opac_news ) = GetNewsToDisplay( q{}, 'LIB1' );
66 ok( $opac_news_count >= 2, 'Successfully tested GetNewsToDisplay for LIB1!' );