Bugzilla – Attachment 102517 Details for
Bug 16371
Quote of the Day (QOTD) for the staff interface
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 16371: Rework tests
0003-Bug-16371-Rework-tests.patch (text/plain), 3.69 KB, created by
Emmi Takkinen
on 2020-04-07 13:31:06 UTC
(
hide
)
Description:
Bug 16371: Rework tests
Filename:
MIME Type:
Creator:
Emmi Takkinen
Created:
2020-04-07 13:31:06 UTC
Size:
3.69 KB
patch
obsolete
>From 3756ee47b01d0736250f678824c222c03fe20a34 Mon Sep 17 00:00:00 2001 >From: Emmi Takkinen <emmi.takkinen@outlook.com> >Date: Tue, 7 Apr 2020 16:17:19 +0300 >Subject: [PATCH 3/3] Bug 16371: Rework tests > >Use TestBuilder and 'mock_preferences' in tests. > >To test, prove t/db_dependent/Koha/GetDailyQuoteForInterface.t > >Sponsored-by: Koha-Suomi Oy >--- > .../Koha/GetDailyQuoteForInterface.t | 58 +++++++++++-------- > 1 file changed, 34 insertions(+), 24 deletions(-) > >diff --git a/t/db_dependent/Koha/GetDailyQuoteForInterface.t b/t/db_dependent/Koha/GetDailyQuoteForInterface.t >index 65d886df91..da4507df55 100644 >--- a/t/db_dependent/Koha/GetDailyQuoteForInterface.t >+++ b/t/db_dependent/Koha/GetDailyQuoteForInterface.t >@@ -2,51 +2,61 @@ > > use Modern::Perl; > use Test::More; >-use Test::More tests => 1; >+use Test::More tests => 3; > use Try::Tiny; > > use C4::Koha; >+use Koha::Database; > >-my $dbh = C4::Context->dbh; >+use t::lib::TestBuilder; >+use t::lib::Mocks; > >-# Start transaction >-$dbh->{RaiseError} = 1; >-# Setup stage >-$dbh->do("DELETE FROM quotes"); >-##populate test context >-$dbh->do("INSERT INTO `quotes` VALUES >- (10,'Dusk And Her Embrace','Unfurl thy limbs breathless succubus<br/>How the full embosomed fog<br/>Imparts the night to us....','0000-00-00 00:00:00'); >-"); >+BEGIN { >+ use_ok('C4::Koha'); >+} >+ >+can_ok('C4::Koha', qw( GetDailyQuoteForInterface )); >+ >+my $schema = Koha::Database->new->schema; >+$schema->storage->txn_begin; >+ >+my $builder = t::lib::TestBuilder->new; >+my $test_quote = $builder->build({ >+ source => 'Quote', >+ value => { >+ source => 'Dusk And Her Embrace', >+ text => 'Unfurl thy limbs breathless succubus<br/>How the full embosomed fog<br/>Imparts the night to us....', >+ } >+}); > > my $expected_quote = { >- id => 10, > source => 'Dusk And Her Embrace', > text => 'Unfurl thy limbs breathless succubus<br/>How the full embosomed fog<br/>Imparts the night to us....', >- timestamp => '0000-00-00 00:00:00', > }; > >+t::lib::Mocks::mock_preference('QuoteOfTheDay', ''); >+ >+subtest "GetDailyQuoteForInterface" => sub { >+ >+ plan tests => 3; > >-subtest "GetDailyQuoteForInterface", \&GetDailyQuoteForInterfaceTest; >-sub GetDailyQuoteForInterfaceTest { > my ($quote); > > ##Set interface and get nothing because syspref is not set. > C4::Context->interface('opac'); >- $quote = C4::Koha::GetDailyQuoteForInterface(id => 10); >+ $quote = C4::Koha::GetDailyQuoteForInterface(id => $test_quote->{id}); > ok(not($quote), "'QuoteOfTheDay'-syspref not set so nothing returned"); > > ##Set 'QuoteOfTheDay'-syspref to not include current interface 'opac' >- C4::Context->set_preference('QuoteOfTheDay', 'intra commandline sip2 api yo-mama'); >- $quote = C4::Koha::GetDailyQuoteForInterface(id => 10); >+ t::lib::Mocks::mock_preference('QuoteOfTheDay', 'intra commandline sip2 api yo-mama'); >+ $quote = C4::Koha::GetDailyQuoteForInterface(id => $test_quote->{id}); > ok(not($quote), "'QuoteOfTheDay'-syspref doesn't include 'opac'"); > > ##Set 'QuoteOfTheDay'-syspref to include current interface 'opac' >- C4::Context->set_preference('QuoteOfTheDay', 'intraopaccommandline'); >- $quote = C4::Koha::GetDailyQuoteForInterface(id => 10); >- is_deeply($quote, $expected_quote, "Got the expected quote"); >+ t::lib::Mocks::mock_preference('QuoteOfTheDay', 'intraopaccommandline'); >+ $quote = C4::Koha::GetDailyQuoteForInterface(id => $test_quote->{id}); >+ is($quote->{text}, $expected_quote->{text}, "Got the expected quote"); > >-} >+}; > >-# teardown >-C4::Context->set_preference('QuoteOfTheDay', undef); >-$dbh->do("DELETE FROM quotes"); >\ No newline at end of file >+$schema->storage->txn_rollback; >\ No newline at end of file >-- >2.17.1 >
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 16371
:
102515
|
102516
|
102517
|
102969
|
103019
|
103329
|
103330
|
103331
|
103332
|
103333
|
103334
|
103732
|
103973
|
103974
|
103975
|
103976
|
103977
|
103978
|
103979
|
106818
|
106819
|
106820
|
106858
|
106859
|
106860
|
106861
|
106862
|
106863
|
106864
|
106865
|
106866
|
106867
|
106868
|
106894
|
106895
|
106896
|
106897
|
106898
|
106899
|
106900
|
106901
|
106902
|
106903
|
108097
|
108098
|
108160
|
108163