+ if($insert_success){
+ my $query = "DELETE FROM authorised_values WHERE category=? AND authorised_value=? AND lib=? AND lib_opac=? AND imageurl=?;";
+ my $sth = $dbh->prepare($query);
+ $sth->execute($data->{category}, $data->{authorised_value}, $data->{lib}, $data->{lib_opac}, $data->{imageurl});
+ }
+
+ SKIP: {
+ eval { require Test::Deep; import Test::Deep; };
+ skip "Test::Deep required to run the GetAuthorisedValues() tests.", 2 if $@;
+ Koha::AuthorisedValueCategory->new({ category_name => 'BUG10656' })->store;
+ Koha::AuthorisedValue->new(
+ { category => 'BUG10656',
+ authorised_value => 'ZZZ',
+ lib => 'Z_STAFF',
+ lib_opac => 'A_PUBLIC',
+ imageurl => ''
+ }
+ )->store;
+ Koha::AuthorisedValue->new(
+ { category => 'BUG10656',
+ authorised_value => 'AAA',
+ lib => 'A_STAFF',
+ lib_opac => 'Z_PUBLIC',
+ imageurl => ''
+ }
+ )->store;
+
+ # the next one sets lib_opac to NULL; in that case, the staff
+ # display value is meant to be used.
+ Koha::AuthorisedValue->new(
+ { category => 'BUG10656',
+ authorised_value => 'DDD',
+ lib => 'D_STAFF',
+ lib_opac => undef,
+ imageurl => ''
+ }
+ )->store;
+
+ my $authvals = GetAuthorisedValues('BUG10656');
+ cmp_deeply(
+ $authvals,
+ [
+ {
+ id => ignore(),
+ category => 'BUG10656',
+ authorised_value => 'AAA',
+ lib => 'A_STAFF',
+ lib_opac => 'Z_PUBLIC',
+ imageurl => '',
+ },
+ {
+ id => ignore(),
+ category => 'BUG10656',
+ authorised_value => 'DDD',
+ lib => 'D_STAFF',
+ lib_opac => undef,
+ imageurl => '',
+ },
+ {
+ id => ignore(),
+ category => 'BUG10656',
+ authorised_value => 'ZZZ',
+ lib => 'Z_STAFF',
+ lib_opac => 'A_PUBLIC',
+ imageurl => '',
+ },
+ ],
+ 'list of authorised values in staff mode sorted by staff label (bug 10656)'
+ );
+ $authvals = GetAuthorisedValues('BUG10656', 1);
+ cmp_deeply(
+ $authvals,
+ [
+ {
+ id => ignore(),
+ category => 'BUG10656',
+ authorised_value => 'ZZZ',
+ lib => 'A_PUBLIC',
+ lib_opac => 'A_PUBLIC',
+ imageurl => '',
+ },
+ {
+ id => ignore(),
+ category => 'BUG10656',
+ authorised_value => 'DDD',
+ lib => 'D_STAFF',
+ lib_opac => undef,
+ imageurl => '',
+ },
+ {
+ id => ignore(),
+ category => 'BUG10656',
+ authorised_value => 'AAA',
+ lib => 'Z_PUBLIC',
+ lib_opac => 'Z_PUBLIC',
+ imageurl => '',
+ },
+ ],
+ 'list of authorised values in OPAC mode sorted by OPAC label (bug 10656)'
+ );
+ }
+
+};
+
+### test for C4::Koha->GetDailyQuote()
+SKIP:
+ {
+ eval { require Test::Deep; import Test::Deep; };
+ skip "Test::Deep required to run the GetDailyQuote tests.", 1 if $@;
+
+ subtest 'Daily Quotes Test' => sub {
+ plan tests => 4;
+
+ SKIP: {
+
+ skip "C4::Koha can't \'GetDailyQuote\'!", 3 unless can_ok('C4::Koha','GetDailyQuote');
+
+# Fill the quote table with the default needed and a spare
+$dbh->do("DELETE FROM quotes WHERE id=3 OR id=25;");
+my $sql = "INSERT INTO quotes (id,source,text,timestamp) VALUES
+(25,'Richard Nixon','When the President does it, that means that it is not illegal.',NOW()),
+(3,'Abraham Lincoln','Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.',NOW());";
+$dbh->do($sql);
+
+ my $expected_quote = {
+ id => 3,
+ source => 'Abraham Lincoln',
+ text => 'Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.',
+ timestamp => re('\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}'), #'YYYY-MM-DD HH:MM:SS'
+ };
+
+# test quote retrieval based on id
+
+ my $quote = GetDailyQuote('id'=>3);
+ cmp_deeply ($quote, $expected_quote, "Got a quote based on id.") or
+ diag('Be sure to run this test on a clean install of sample data.');
+
+# test quote retrieval based on today's date
+
+ my $query = 'UPDATE quotes SET timestamp = ? WHERE id = ?';
+ my $sth = C4::Context->dbh->prepare($query);
+ $sth->execute(DateTime::Format::MySQL->format_datetime( dt_from_string() ), $expected_quote->{'id'});
+
+ DateTime::Format::MySQL->format_datetime( dt_from_string() ) =~ m/(\d{4}-\d{2}-\d{2})/;
+ $expected_quote->{'timestamp'} = re("^$1");
+
+# $expected_quote->{'timestamp'} = DateTime::Format::MySQL->format_datetime( dt_from_string() ); # update the timestamp of expected quote data
+
+ $quote = GetDailyQuote(); # this is the "default" mode of selection
+ cmp_deeply ($quote, $expected_quote, "Got a quote based on today's date.") or
+ diag('Be sure to run this test on a clean install of sample data.');
+
+# test random quote retrieval
+
+ $quote = GetDailyQuote('random'=>1);
+ ok ($quote, "Got a random quote.");
+ }
+ };