Bug 28479: Use primary keys to check object existence in TestBuilder
authorJoonas Kylmälä <joonas.kylmala@helsinki.fi>
Fri, 28 May 2021 10:33:24 +0000 (13:33 +0300)
committerKyle M Hall <kyle@bywatersolutions.com>
Fri, 2 Jul 2021 12:54:39 +0000 (08:54 -0400)
commit188479881fdafb6ef77d9e7278738dba372f15c2
treecc04ed5d2614e265b4f6136344d2eab54a3e0872
parent839f61cf9783594e1be26db97dde3d278030ee4a
Bug 28479: Use primary keys to check object existence in TestBuilder

The TestBuilder::build_object function used any foreign keys to check
whether an object already exists or not. This brought incorrectly
results of unrelated objects because using any other keys other than
primary keys don't guarantee our results to point to one single
object. For example, as is put here in the unit test, if you created
two items with the same biblionumber and then tried to create a hold
using build_object() we were using the biblionumber to check whether
an item was linked to the hold already. Thus, we were checking whether
a random item was already linked to the hold instead of the one we
wanted either by passing it explicitly to build_object() or the one
build_object() created implicitly. This also resulted in following
warnings when there were more than one match:

DBIx::Class::Storage::DBI::select_single(): Query returned more than
one row.  SQL that returns multiple rows is DEPRECATED for ->find and
->single at /kohadevbox/koha/t/lib/TestBuilder.pm line 235

To test:
 $ prove t/db_dependent

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
t/db_dependent/TestBuilder.t
t/lib/TestBuilder.pm