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)
committerFridolin Somers <fridolin.somers@biblibre.com>
Sat, 10 Jul 2021 02:41:20 +0000 (16:41 -1000)
commitccc2327796e9a9f9f1fef1cf705b270db9fd8b5b
tree6fafdd67fecf4e363c84804c4a8b494420d1cccc
parentf006f8db433eb79609244ab800604765fb187c3f
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>
(cherry picked from commit 188479881fdafb6ef77d9e7278738dba372f15c2)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
t/db_dependent/TestBuilder.t
t/lib/TestBuilder.pm