From 132b805d5ba4380159099849cf39b446510b14f9 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Fri, 6 Jul 2018 11:20:47 +0200 Subject: [PATCH] Bug 19915: (QA follow-up) Tidy up GetItemsForInventory.t Standard edits like modules, schema, Koha objects instead of DBIC. Removing unneeded autoflush. Moving initial test to a first subtest. No need to clear issues if you clear items. Adding a FIXME for OldWay; would be nice to remove that code.. Signed-off-by: Marcel de Rooy --- t/db_dependent/Items/GetItemsForInventory.t | 55 +++++++++++++---------------- 1 file changed, 24 insertions(+), 31 deletions(-) diff --git a/t/db_dependent/Items/GetItemsForInventory.t b/t/db_dependent/Items/GetItemsForInventory.t index a09359ada5..a7a8e7039d 100755 --- a/t/db_dependent/Items/GetItemsForInventory.t +++ b/t/db_dependent/Items/GetItemsForInventory.t @@ -18,43 +18,35 @@ # along with Koha; if not, see . use Modern::Perl; -use Test::More tests => 7; +use Test::More tests => 2; + use t::lib::TestBuilder; -use Koha::AuthorisedValues; +use C4::Context; +use C4::Biblio; use C4::ClassSource; +use C4::Items; +use C4::Koha; +use Koha::AuthorisedValues; +use Koha::Database; +use Koha::Items; -$| = 1; - -BEGIN { - use_ok('C4::Context'); - use_ok('C4::Items'); - use_ok('C4::Biblio'); - use_ok('C4::Koha'); -} - -can_ok('C4::Items','GetItemsForInventory'); - -my $dbh = C4::Context->dbh; -$dbh->{AutoCommit} = 0; -$dbh->{RaiseError} = 1; - -my ($oldResults, $oldCount) = OldWay($dbh); -my ($newResults, $newCount) = GetItemsForInventory; +my $schema = Koha::Database->new->schema; +$schema->storage->txn_begin; -is_deeply($newResults,$oldResults,"Inventory results unchanged."); +subtest 'Verify results with OldWay' => sub { + plan tests => 1; -$dbh->rollback; -$dbh->{AutoCommit} = 1; + my ($oldResults, $oldCount) = OldWay(); + my ($newResults, $newCount) = GetItemsForInventory(); + is_deeply($newResults,$oldResults,"Inventory results unchanged."); +}; subtest 'Use cn_sort rather than callnumber to determine correct location' => sub { - plan tests => 1; + my $builder = t::lib::TestBuilder->new; - my $schema = Koha::Database->new->schema; - $schema->storage->txn_begin; - $builder->schema->resultset( 'Issue' )->delete_all; - $builder->schema->resultset( 'Item' )->delete_all; + Koha::Items->delete; my $class_rule = $builder->build({ source => 'ClassSortRule', @@ -80,13 +72,14 @@ subtest 'Use cn_sort rather than callnumber to determine correct location' => su class_source => $class_source->{cn_source}, }); is($item_count,1,"We should return GT95 as between GT90 and GT100"); - $schema->storage->txn_rollback; }; -sub OldWay { - my ($tdbh) = @_; - my $ldbh = $tdbh; +$schema->storage->txn_rollback; + +sub OldWay { # FIXME Do we really still need so much code to check results ?? + my $ldbh = C4::Context->dbh; + my $minlocation = ''; my $maxlocation = ''; my $location = ''; -- 2.11.0