Bug 10333

Summary: UT: Labels/t_Batch.t needs to create its own data
Product: Koha Reporter: Jonathan Druart <jonathan.druart>
Component: Test SuiteAssignee: Jonathan Druart <jonathan.druart>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P5 - low CC: gmcharlt, kyle, srdjan, tomascohen
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: Small patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:
Bug Depends on:    
Bug Blocks: 10273    
Attachments: Bug 10333: Labels/t_Batch.t needs to create its own data
Bug 10333: Labels/t_Batch.t needs to create its own data
Bug 10333: Labels/t_Batch.t needs to create its own data
Bug 10333: remove_item should be called just one time
Bug 10333: Labels/t_Batch.t needs to create its own data
[PASSED QA] Bug 10333: Labels/t_Batch.t needs to create its own data

Description Jonathan Druart 2013-05-24 12:51:48 UTC
t/db_dependent/Labels/t_Batch.t depends on the Jenkins database.
We should create the data we want and delete them at the end.
Comment 1 Jonathan Druart 2013-05-24 12:53:56 UTC Comment hidden (obsolete)
Comment 2 Chris Cormack 2013-05-24 23:21:28 UTC Comment hidden (obsolete)
Comment 3 Kyle M Hall (khall) 2013-06-21 13:17:11 UTC
With this patch, the tests now assume that the home and holding branch are in 952 a and b. While this is the Koha default, it's not necessarily true.

I think it would be better to get the values for these fields using GetMarcFromKohaField().
Comment 4 Jonathan Druart 2013-06-24 07:33:43 UTC Comment hidden (obsolete)
Comment 5 Kyle M Hall (khall) 2013-07-02 17:04:12 UTC
Looks like this patch needs re-signed off.
Comment 6 Srdjan Jankovic 2013-08-02 03:30:26 UTC
# Testing Batch->get_attr() method.
# Testing Batch->add_item() method.
# Testing Batch->retrieve() method.

#   Failed test at t/db_dependent/Labels/t_Batch.t line 100.
#     Structures begin differing at:
#          $got = '-2'
#     $expected = C4::Labels::Batch=HASH(0x3aaa5b8)
# Retrieved batch object FAILED to verify.
# Testing Batch->remove_item() method.

#   Failed test at t/db_dependent/Labels/t_Batch.t line 109.
#     Structures begin differing at:
#          $got = '-2'
#     $expected = C4::Labels::Batch=HASH(0x3aaa5b8)
# Updated batch object FAILED to verify.
# Testing Batch->delete() method.
# Looks like you planned 33 tests but ran 13.

Do I need some setup first?
Comment 7 Jonathan Druart 2013-08-12 14:56:06 UTC
(In reply to Srdjan Jankovic from comment #6)
> Do I need some setup first?

No, this should be done by this unit tests file.
Comment 8 Jonathan Druart 2013-08-12 15:08:56 UTC Comment hidden (obsolete)
Comment 9 Srdjan Jankovic 2013-08-14 01:40:02 UTC
# Testing Batch->new() method.
# Testing Batch->get_attr() method.
# Testing Batch->add_item() method.
Use of uninitialized value $encoding in string eq at C4/Biblio.pm line 3281.
Use of uninitialized value $encoding in pattern match (m//) at C4/Biblio.pm line 3301.
# Testing Batch->retrieve() method.

#   Failed test at t/db_dependent/Labels/t_Batch.t line 100.
#     Structures begin differing at:
#          $got = '-2'
#     $expected = C4::Labels::Batch=HASH(0x2df33c0)
# Retrieved batch object FAILED to verify.
# Testing Batch->remove_item() method.

#   Failed test at t/db_dependent/Labels/t_Batch.t line 108.
#     Structures begin differing at:
#          $got = '-2'
#     $expected = C4::Labels::Batch=HASH(0x2df33c0)
# Updated batch object FAILED to verify.
# Testing Batch->delete() method.
# Looks like you planned 24 tests but ran 14.
# Looks like you failed 2 tests of 14 run.
Comment 10 Jonathan Druart 2013-08-14 07:40:33 UTC
(In reply to Srdjan Jankovic from comment #9)
> Use of uninitialized value $encoding in string eq at C4/Biblio.pm line 3281.
> Use of uninitialized value $encoding in pattern match (m//) at C4/Biblio.pm
> line 3301.

I have no idea where is the problem. But there 2 lines intrigues me. $encoding is C4::Context->preference("marcflavour"). Don't you have the marcflavour syspref in your DB?
Comment 11 Srdjan Jankovic 2013-08-14 23:45:01 UTC
Yes, I was doing something else and removed the syspref erroneously. When I put it back there are no warnings.
But the test failures stayed. Do you need any more details eg table dumps?
Comment 12 Jonathan Druart 2013-08-16 08:24:11 UTC
(In reply to Srdjan Jankovic from comment #11)
> Yes, I was doing something else and removed the syspref erroneously. When I
> put it back there are no warnings.
> But the test failures stayed. Do you need any more details eg table dumps?

I read the code but I have no idea why they don't pass.
First step, the batch is created and the batch_id is backed-up into the $batch_id var. Items are added to the batch and the retrieve method returns -2 if the batch does not contain items.

Maybe could you warn the $batch_id var (l. 56)? Should be > 1.
To check if items have been added could be interesting too (SELECT * FROM creator_batches WHERE batch_id = $batch_id).
Comment 13 Srdjan Jankovic 2013-08-19 02:48:57 UTC Comment hidden (obsolete)
Comment 14 Srdjan Jankovic 2013-08-19 02:54:05 UTC
C4::Items::AddItemBatchFromMarc was failing (no records returned), I had no CPL branches. You may wish to add some check there, but om if you don't (it's that testing data bug request that is still being discussed).
Comment 15 Katrin Fischer 2013-08-25 17:26:59 UTC
Created attachment 20593 [details] [review]
[PASSED QA] Bug 10333: Labels/t_Batch.t needs to create its own data

prove t/db_dependent/Labels/t_Batch.t
db_dependent/Labels/t_Batch.t .. 1/33 # Testing Batch->new() method.
db_dependent/Labels/t_Batch.t .. ok
All tests successful.
Files=1, Tests=33,  1 wallclock secs ( 0.03 usr  0.00 sys +  0.34 cusr
0.00 csys =  0.37 CPU)
Result: PASS

Signed-off-by: Srdjan <srdjan@catalyst.net.nz>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Comment 16 Galen Charlton 2013-09-08 02:07:37 UTC
Pushed to master.  Thanks, Jonathan!
Comment 17 Tomás Cohen Arazi (tcohen) 2013-10-08 17:58:55 UTC
This patch has been pushed to 3.12.x, will be in 3.12.6.

Thanks Jonathan!