Description
Jonathan Druart
2013-05-21 15:11:22 UTC
Created attachment 18301 [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. Created attachment 18302 [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 Created attachment 18376 [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 Created attachment 18504 [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. $ 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. Created attachment 19009 [details] [review] [SIGNED-OFF] Bug 10298: Mock C4::Context->preference Created attachment 19010 [details] [review] [SIGNED-OFF] Bug 10298: Adapt existing code Created attachment 19011 [details] [review] [SIGNED-OFF] Bug 10298: Followup: Adapt existing code 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. Created attachment 20206 [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> Created attachment 20207 [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 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. 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> 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> Pushed to master. Thanks, Jonathan! This patch has been pushed to 3.12.x, will be in 3.12.8. Thanks Jonathan! |