Bugzilla – Attachment 9724 Details for
Bug 7977
Add a "Quote-of-the-day" feature to the OPAC homepage
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 7977: Adding Daily Quotes Tests to Koha.t test suite; also fixing sort order on quote selection SQL
Bug-7977-Adding-Daily-Quotes-Tests-to-Kohat-test-s.patch (text/plain), 7.09 KB, created by
Mason James
on 2012-05-22 23:57:18 UTC
(
hide
)
Description:
Bug 7977: Adding Daily Quotes Tests to Koha.t test suite; also fixing sort order on quote selection SQL
Filename:
MIME Type:
Creator:
Mason James
Created:
2012-05-22 23:57:18 UTC
Size:
7.09 KB
patch
obsolete
>From d734228598583c75dc4e1d216e61fc1c6cae612b Mon Sep 17 00:00:00 2001 >From: Chris Nighswonger <cnighswonger@foundations.edu> >Date: Mon, 7 May 2012 14:53:50 -0400 >Subject: [PATCH] Bug 7977: Adding Daily Quotes Tests to Koha.t test suite; also fixing sort order on quote selection SQL >Content-Type: text/plain; charset="utf-8" >http://koha-community.org > >Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com> >Signed-off-by: Mason James <mtj@kohaaloha.com> >--- > C4/Koha.pm | 2 +- > t/db_dependent/Koha.t | 116 ++++++++++++++++++++++++++++++++++++------------- > 2 files changed, 86 insertions(+), 32 deletions(-) > >diff --git a/C4/Koha.pm b/C4/Koha.pm >index 2bd1550..ebb3eed 100644 >--- a/C4/Koha.pm >+++ b/C4/Koha.pm >@@ -1347,7 +1347,7 @@ sub GetDailyQuote { > # Fall through... we also return a random quote as a catch-all if all else fails > } > else { >- $query = 'SELECT * FROM quotes WHERE timestamp LIKE CONCAT(CURRENT_DATE,\'%\') ORDER BY timestamp LIMIT 0,1'; >+ $query = 'SELECT * FROM quotes WHERE timestamp LIKE CONCAT(CURRENT_DATE,\'%\') ORDER BY timestamp DESC LIMIT 0,1'; > $sth = $dbh->prepare($query); > $sth->execute(); > $quote = $sth->fetchrow_hashref(); >diff --git a/t/db_dependent/Koha.t b/t/db_dependent/Koha.t >index 378a0c1..e53e936 100644 >--- a/t/db_dependent/Koha.t >+++ b/t/db_dependent/Koha.t >@@ -7,51 +7,105 @@ use strict; > use warnings; > use C4::Context; > >-use Test::More tests => 8; >+use Test::More tests => 4; >+use DateTime::Format::MySQL; >+ >+eval {use Test::Deep;}; > > BEGIN { >- use_ok('C4::Koha'); >+ use_ok('C4::Koha', qw( :DEFAULT GetDailyQuote )); > use_ok('C4::Members'); > } > >-my $data = { >- category => 'CATEGORY', >- authorised_value => 'AUTHORISED_VALUE', >- lib => 'LIB', >- lib_opac => 'LIBOPAC', >- imageurl => 'IMAGEURL' >-}; >- > my $dbh = C4::Context->dbh; > >+subtest 'Authorized Values Tests' => sub { >+ plan tests => 6; >+ >+ my $data = { >+ category => 'CATEGORY', >+ authorised_value => 'AUTHORISED_VALUE', >+ lib => 'LIB', >+ lib_opac => 'LIBOPAC', >+ imageurl => 'IMAGEURL' >+ }; >+ >+ > # Insert an entry into authorised_value table >-my $query = "INSERT INTO authorised_values (category, authorised_value, lib, lib_opac, imageurl) VALUES (?,?,?,?,?);"; >-my $sth = $dbh->prepare($query); >-my $insert_success = $sth->execute($data->{category}, $data->{authorised_value}, $data->{lib}, $data->{lib_opac}, $data->{imageurl}); >-ok($insert_success, "Insert data in database"); >+ my $query = "INSERT INTO authorised_values (category, authorised_value, lib, lib_opac, imageurl) VALUES (?,?,?,?,?);"; >+ my $sth = $dbh->prepare($query); >+ my $insert_success = $sth->execute($data->{category}, $data->{authorised_value}, $data->{lib}, $data->{lib_opac}, $data->{imageurl}); >+ ok($insert_success, "Insert data in database"); > > > # Tests >-SKIP: { >- skip "INSERT failed", 5 unless $insert_success; >- >- is ( GetAuthorisedValueByCode($data->{category}, $data->{authorised_value}), $data->{lib}, "GetAuthorisedValueByCode" ); >- is ( GetKohaImageurlFromAuthorisedValues($data->{category}, $data->{lib}), $data->{imageurl}, "GetKohaImageurlFromAuthorisedValues" ); >+ SKIP: { >+ skip "INSERT failed", 5 unless $insert_success; > >- my $sortdet=C4::Members::GetSortDetails("lost", "3"); >- is ($sortdet, "Lost and Paid For", "lost and paid works"); >+ is ( GetAuthorisedValueByCode($data->{category}, $data->{authorised_value}), $data->{lib}, "GetAuthorisedValueByCode" ); >+ is ( GetKohaImageurlFromAuthorisedValues($data->{category}, $data->{lib}), $data->{imageurl}, "GetKohaImageurlFromAuthorisedValues" ); > >- my $sortdet2=C4::Members::GetSortDetails("loc", "child"); >- is ($sortdet2, "Children's Area", "Child area works"); >+ my $sortdet=C4::Members::GetSortDetails("lost", "3"); >+ is ($sortdet, "Lost and Paid For", "lost and paid works"); > >- my $sortdet3=C4::Members::GetSortDetails("withdrawn", "1"); >- is ($sortdet3, "Withdrawn", "Withdrawn works"); >-} >+ my $sortdet2=C4::Members::GetSortDetails("loc", "child"); >+ is ($sortdet2, "Children's Area", "Child area works"); >+ >+ my $sortdet3=C4::Members::GetSortDetails("withdrawn", "1"); >+ is ($sortdet3, "Withdrawn", "Withdrawn works"); >+ } > > # Clean up >-if($insert_success){ >- $query = "DELETE FROM authorised_values WHERE category=? AND authorised_value=? AND lib=? AND lib_opac=? AND imageurl=?;"; >- $sth = $dbh->prepare($query); >- $sth->execute($data->{category}, $data->{authorised_value}, $data->{lib}, $data->{lib_opac}, $data->{imageurl}); >-} >+ if($insert_success){ >+ $query = "DELETE FROM authorised_values WHERE category=? AND authorised_value=? AND lib=? AND lib_opac=? AND imageurl=?;"; >+ $sth = $dbh->prepare($query); >+ $sth->execute($data->{category}, $data->{authorised_value}, $data->{lib}, $data->{lib_opac}, $data->{imageurl}); >+ } >+}; >+### test for C4::Koha->GetDailyQuote() >+SKIP: >+ { >+ 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'); >+ >+ 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}'), #'0000-00-00 00:00:00', >+ }; >+ >+# 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 random quote retrieval >+ >+ $quote = GetDailyQuote('random'=>1); >+ ok ($quote, "Got a random quote."); >+ >+# 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(DateTime->now), $expected_quote->{'id'}); >+ >+ DateTime::Format::MySQL->format_datetime(DateTime->now) =~ m/(\d{4}-\d{2}-\d{2})/; >+ $expected_quote->{'timestamp'} = re("^$1"); >+ >+# $expected_quote->{'timestamp'} = DateTime::Format::MySQL->format_datetime(DateTime->now); # 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.'); >+ } >+ }; >+} >-- >1.7.2.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 7977
:
9310
|
9321
|
9323
|
9324
|
9325
|
9326
|
9327
|
9328
|
9338
|
9343
|
9373
|
9376
|
9377
|
9378
|
9392
|
9405
|
9406
|
9407
|
9408
|
9409
|
9433
|
9434
|
9435
|
9441
|
9442
|
9443
|
9447
|
9473
|
9474
|
9475
|
9476
|
9477
|
9478
|
9479
|
9480
|
9481
|
9482
|
9483
|
9484
|
9485
|
9486
|
9503
|
9504
|
9505
|
9510
|
9517
|
9521
|
9529
|
9530
|
9531
|
9682
|
9683
|
9711
|
9712
|
9713
|
9714
|
9715
|
9716
|
9717
|
9718
|
9719
|
9720
|
9721
|
9722
|
9723
| 9724 |
9725
|
9726
|
9727
|
9728
|
9729
|
9730
|
9731
|
9732