Bug 10298 - t::lib::Mocks tries to deal with syspref but doesn not manage to
Summary: t::lib::Mocks tries to deal with syspref but doesn not manage to
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Test Suite (show other bugs)
Version: Main
Hardware: All All
: P5 - low normal (vote)
Assignee: Jonathan Druart
QA Contact:
URL:
Keywords:
Depends on:
Blocks: 8304 10843
  Show dependency treegraph
 
Reported: 2013-05-21 15:11 UTC by Jonathan Druart
Modified: 2016-10-17 19:18 UTC (History)
5 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Small patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:


Attachments
Bug 10298: Mock C4::Context->preference (3.66 KB, patch)
2013-05-22 09:07 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 10298: Adapt existing code (5.10 KB, patch)
2013-05-22 09:07 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 10298: Followup: Adapt existing code (803 bytes, patch)
2013-05-24 11:34 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 10298: Mock C4::Context->preference (3.65 KB, patch)
2013-05-30 09:27 UTC, Jonathan Druart
Details | Diff | Splinter Review
[SIGNED-OFF] Bug 10298: Mock C4::Context->preference (3.71 KB, patch)
2013-06-14 13:26 UTC, Julian Maurice
Details | Diff | Splinter Review
[SIGNED-OFF] Bug 10298: Adapt existing code (5.16 KB, patch)
2013-06-14 13:26 UTC, Julian Maurice
Details | Diff | Splinter Review
[SIGNED-OFF] Bug 10298: Followup: Adapt existing code (864 bytes, patch)
2013-06-14 13:26 UTC, Julian Maurice
Details | Diff | Splinter Review
Bug 10298: Mock C4::Context->preference (3.76 KB, patch)
2013-08-09 00:06 UTC, Chris Cormack
Details | Diff | Splinter Review
Bug 10298: Adapt existing code (5.28 KB, patch)
2013-08-09 00:07 UTC, Chris Cormack
Details | Diff | Splinter Review
Bug 10298: Followup: Adapt existing code (973 bytes, patch)
2013-08-09 14:40 UTC, Kyle M Hall
Details | Diff | Splinter Review
Bug 10298: Mock C4::Context->preference (3.81 KB, patch)
2013-08-09 14:40 UTC, Kyle M Hall
Details | Diff | Splinter Review
Bug 10298: Adapt existing code (5.35 KB, patch)
2013-08-09 14:41 UTC, Kyle M Hall
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Druart 2013-05-21 15:11:22 UTC

    
Comment 1 Jonathan Druart 2013-05-22 09:07:46 UTC Comment hidden (obsolete)
Comment 2 Jonathan Druart 2013-05-22 09:07:50 UTC Comment hidden (obsolete)
Comment 3 Jonathan Druart 2013-05-24 11:34:14 UTC Comment hidden (obsolete)
Comment 4 Jonathan Druart 2013-05-30 09:27:33 UTC Comment hidden (obsolete)
Comment 5 Julian Maurice 2013-06-14 13:25:33 UTC
$ prove -r t/searchengine                        
t/searchengine/000_conn/conn.t ........... ok   
t/searchengine/001_search/search_base.t .. ok   
t/searchengine/002_index/index_base.t .... IndexRecord called with biblio 2 at /home/koha/src/Koha/SearchEngine/Solr/Index.pm line 35.
t/searchengine/002_index/index_base.t .... ok   
t/searchengine/003_query/buildquery.t .... ok   
t/searchengine/004_config/load_config.t .. ok    
All tests successful.

$ prove t/db_dependent/Circulation_issuingrules.t
t/db_dependent/Circulation_issuingrules.t .. ok          
All tests successful.

$ perl <<EOF                                     
use Modern::Perl;
use t::lib::Mocks;
use C4::Context;

say "initial value for version: " . C4::Context->preference('Version');
say "initial value for language: " . C4::Context->preference('language');
t::lib::Mocks::mock_preference('Version', "new version for testing");
say "version is mocked with: " . C4::Context->preference('Version');
say "language is not yet mocked: " . C4::Context->preference('language');
t::lib::Mocks::mock_preference('language', 'new langage for testing');
t::lib::Mocks::mock_preference('Version', 'another version for testing');
say "version is mocked with another value: " . C4::Context->preference('Version');
say "language is finally mocked: " . C4::Context->preference('language');
EOF
initial value for version: 3.1300007
initial value for language: en,fr-FR
version is mocked with: new version for testing
language is not yet mocked: en,fr-FR
version is mocked with another value: another version for testing
language is finally mocked: new langage for testing

I know these are BibLibre patches but mock_config and mock_preference will be more and more needed in the future to write unit tests and this does not affect Koha behaviour, so I think a QA review will be good enough for those patches to pass.
Signed off.
Comment 6 Julian Maurice 2013-06-14 13:26:11 UTC Comment hidden (obsolete)
Comment 7 Julian Maurice 2013-06-14 13:26:28 UTC Comment hidden (obsolete)
Comment 8 Julian Maurice 2013-06-14 13:26:43 UTC Comment hidden (obsolete)
Comment 9 Katrin Fischer 2013-06-16 09:29:04 UTC
I am a bit torn here. While I don't doubt Julian's sign-off, we have set up the rules to be apply to all. For this reason only, I would like to see another sign-off here. Please don't take it personally, as it's not meant to be.
Comment 10 Chris Cormack 2013-08-09 00:06:59 UTC Comment hidden (obsolete)
Comment 11 Chris Cormack 2013-08-09 00:07:21 UTC Comment hidden (obsolete)
Comment 12 Kyle M Hall 2013-08-09 14:40:39 UTC
Created attachment 20232 [details] [review]
Bug 10298: Followup: Adapt existing code

This unit tests file does not need the t::lib::Mocks::Context module.

To test:
prove t/db_dependent/Circulation_issuingrules.t

Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Passes koha-qa.pl, test checks out.
Comment 13 Kyle M Hall 2013-08-09 14:40:49 UTC
Created attachment 20233 [details] [review]
Bug 10298: Mock C4::Context->preference

t::lib::Mocks::Context tried to deal with preferences but did not manage
to.

This patch removes this module and add 2 routines in t::lib::Mocks in
order to mock C4::context->preference and C4::Context->config.

To test:

===START t/test.pl===

use Modern::Perl;
use t::lib::Mocks;
use C4::Context;

say "initial value for version: " . C4::Context->preference('Version');
say "initial value for language: " . C4::Context->preference('language');
t::lib::Mocks::mock_preference('Version', "new version for testing");
say "version is mocked with: " . C4::Context->preference('Version');
say "language is not yet mocked: " . C4::Context->preference('language');
t::lib::Mocks::mock_preference('language', 'new langage for testing');
t::lib::Mocks::mock_preference('Version', 'another version for testing');
say "version is mocked with another value: " . C4::Context->preference('Version');
say "language is finally mocked: " . C4::Context->preference('language');
===END===

Try to execute this file and check that the output is consistent.

Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>
Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 14 Kyle M Hall 2013-08-09 14:41:06 UTC
Created attachment 20234 [details] [review]
Bug 10298: Adapt existing code

set_solr and set_zebra is not really useful. It is preferable to use
mock_preference directly.

To test:
1/ Launch Solr
2/ prove -r t/searchengine/
It should produce:
% prove -r t/searchengine/
t/searchengine/000_conn/conn.t ........... ok
t/searchengine/001_search/search_base.t .. ok
t/searchengine/002_index/index_base.t .... IndexRecord called with biblio 2
Indexing biblio 2
t/searchengine/002_index/index_base.t .... ok
t/searchengine/003_query/buildquery.t .... ok
t/searchengine/004_config/load_config.t .. ok
All tests successful.
Files=5, Tests=21,  4 wallclock secs ( 0.03 usr  0.01 sys +  2.74 cusr
0.20 csys =  2.98 CPU)
Result: PASS

Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>
Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>

Had to get Solr going again to test this, man .. they could make that
easier

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 15 Galen Charlton 2013-08-09 16:39:03 UTC
Pushed to master.  Thanks, Jonathan!
Comment 16 Tomás Cohen Arazi 2013-12-05 12:51:54 UTC
This patch has been pushed to 3.12.x, will be in 3.12.8.

Thanks Jonathan!