Bug 31134

Summary: t/Ediorder.t tests failing on 22.05.02
Product: Koha Reporter: Aleisha Amohia <aleisha>
Component: AcquisitionsAssignee: Martin Renvoize <martin.renvoize>
Status: CLOSED FIXED QA Contact: Testopia <testopia>
Severity: critical    
Priority: P5 - low CC: arthur.suzuki, chris, jonathan.druart, lucas, wainuiwitikapark
Version: 22.05   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
22.11.00, 22.05.05
Bug Depends on: 30135    
Bug Blocks:    
Attachments: Bug 31134: Mock EdifactLSQ for t/Edifact.t
Bug 31134: Mock EdifactLSQ for t/Edifact.t
Bug 31134: Mock EdifactLSQ for t/Edifact.t

Description Aleisha Amohia 2022-07-12 02:09:30 UTC
Bug 30135 might have introduced a flaw in the tests - when we try to install Koha 22.05.02 and run t/ediorder.t, it fails with this output:

vagrant@kohadevbox:kohaclone((v22.05.02))$ sudo koha-shell kohadev
kohadev-koha@kohadevbox:/home/vagrant/kohaclone$ prove t/Ediorder.t
t/Ediorder.t .. 1/13 Use of uninitialized value $lsq_field in hash element at /home/vagrant/kohaclone/Koha/Edifact/Order.pm line 563.
Use of uninitialized value $lsq_field in hash element at /home/vagrant/kohaclone/Koha/Edifact/Order.pm line 563.
t/Ediorder.t .. 11/13 
#   Failed test 'Single Gir field OK'
#   at t/Ediorder.t line 104.
#          got: 'GIR+001+BUDGET:LFN+BRANCH:LLO+TYPE:LST+CALL:LSM'
#     expected: 'GIR+001+BUDGET:LFN+BRANCH:LLO+TYPE:LST+LOCATION:LSQ+CALL:LSM'
Use of uninitialized value $lsq_field in hash element at /home/vagrant/kohaclone/Koha/Edifact/Order.pm line 563.
Use of uninitialized value $lsq_field in hash element at /home/vagrant/kohaclone/Koha/Edifact/Order.pm line 563.
$VAR1 = 'GIR+001+BUDGET:LFN+BRANCH:LLO+TYPE:LST+CALL:LSM+S_I:LVT';
$VAR2 = 'GIR+002+BUDGET:LFN+BRANCH:LLO+TYPE:LST+CALL:LSM+S_I:LVT';
Use of uninitialized value $got in string eq at (eval in cmp_ok) t/Ediorder.t line 119.

#   Failed test 'First part of split Gir field OK'
#   at t/Ediorder.t line 119.
#          got: undef
#     expected: 'GIR+002+BUDGET:LFN+BRANCH:LLO+TYPE:LST+LOCATION:LSQ+CALL:LSM'
Use of uninitialized value $got in string eq at (eval in cmp_ok) t/Ediorder.t line 125.

#   Failed test 'Second part of split GIR field OK'
#   at t/Ediorder.t line 125.
#          got: undef
#     expected: 'GIR+002+S_I:LVT'
# Looks like you failed 3 tests of 13.
t/Ediorder.t .. Dubious, test returned 3 (wstat 768, 0x300)
Failed 3/13 subtests 

Test Summary Report
-------------------
t/Ediorder.t (Wstat: 768 Tests: 13 Failed: 3)
  Failed tests:  11-13
  Non-zero exit status: 3
Files=1, Tests=13,  2 wallclock secs ( 0.02 usr  0.00 sys +  1.40 cusr  0.10 csys =  1.52 CPU)
Result: FAIL
Comment 1 Jonathan Druart 2022-07-12 10:10:55 UTC
% git checkout v22.05.02)
% reset_all
% prove t/Ediorder.t

All tests successful.

Works for me. And Jenkins is happy as well.
Comment 2 Chris Cormack 2022-07-13 00:40:25 UTC
Ok If I checkout the branch it fails

   Failed test 'Single Gir field OK'
#   at t/Ediorder.t line 104.
#          got: 'GIR+001+BUDGET:LFN+BRANCH:LLO+TYPE:LST+CALL:LSM'
#     expected: 'GIR+001+BUDGET:LFN+BRANCH:LLO+TYPE:LST+LOCATION:LSQ+CALL:LSM'
Use of uninitialized value $lsq_field in hash element at /home/vagrant/kohaclone/Koha/Edifact/Order.pm line 563.
Use of uninitialized value $lsq_field in hash element at /home/vagrant/kohaclone/Koha/Edifact/Order.pm line 563.
Use of uninitialized value $got in string eq at (eval in cmp_ok) t/Ediorder.t line 117.

#   Failed test 'First part of split Gir field OK'
#   at t/Ediorder.t line 117.
#          got: undef
#     expected: 'GIR+002+BUDGET:LFN+BRANCH:LLO+TYPE:LST+LOCATION:LSQ+CALL:LSM'
Use of uninitialized value $got in string eq at (eval in cmp_ok) t/Ediorder.t line 123.

#   Failed test 'Second part of split GIR field OK'
#   at t/Ediorder.t line 123.
#          got: undef
#     expected: 'GIR+002+S_I:LVT'
# Looks like you failed 3 tests of 13.

This is because this test is now db_dependent 
Koha/Edifact/Order.pm:    my $lsq_field = C4::Context->preference('EdifactLSQ');


So it needs to probably be moved out of t, or that syspref needs to be mocked. The reason it works is if that syspref is set location. 

If I set the syspref to collection, the tests fail, if i set it location the tests pass.  
The problem is then when you are building a package you dont have a database, the t/ tests should all pass without relying on a syspref fetched from a db.

Chris
Comment 3 Jonathan Druart 2022-07-14 10:56:53 UTC
Martin, can you have a look at this?
Comment 4 Martin Renvoize 2022-07-14 11:06:34 UTC
Created attachment 137710 [details] [review]
Bug 31134: Mock EdifactLSQ for t/Edifact.t

This patch adds a mock for the EdifactLSQ preference so we can
consistently pass when a database is not available.
Comment 5 Martin Renvoize 2022-07-14 11:07:39 UTC
Thanks for drawing my attention to this one.. should work with the patch attached :)
Comment 6 Kyle M Hall 2022-07-14 11:14:55 UTC
Created attachment 137711 [details] [review]
Bug 31134: Mock EdifactLSQ for t/Edifact.t

This patch adds a mock for the EdifactLSQ preference so we can
consistently pass when a database is not available.

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 7 Jonathan Druart 2022-07-14 12:18:18 UTC
Created attachment 137714 [details] [review]
Bug 31134: Mock EdifactLSQ for t/Edifact.t

This patch adds a mock for the EdifactLSQ preference so we can
consistently pass when a database is not available.

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 8 Tomás Cohen Arazi 2022-07-18 13:31:44 UTC
Pushed to master for 22.11.

Nice work everyone, thanks!
Comment 9 Lucas Gass 2022-08-23 16:12:24 UTC
Backported to 22.05.x for 22.05.05
Comment 10 Arthur Suzuki 2022-08-26 08:19:47 UTC
depends on 30135 not released in 21.11.x. won't backport.