From bd3273cfbc785fe1b729197303703cf43ccafdef Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 6 Nov 2020 14:42:42 +0000 Subject: [PATCH] Bug 24786: (QA follow-up) Ensure tests pass with existing data The tests for Koha::Template::Plugin::Registers assumed that no registers were pre-set in the database. This patch updates the test to ignore pre-existing data or take it into account in totals. --- .../Koha/Template/Plugin/Registers.t | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/t/db_dependent/Koha/Template/Plugin/Registers.t b/t/db_dependent/Koha/Template/Plugin/Registers.t index 7bc36e47d9..912e5b85f8 100755 --- a/t/db_dependent/Koha/Template/Plugin/Registers.t +++ b/t/db_dependent/Koha/Template/Plugin/Registers.t @@ -70,6 +70,11 @@ subtest 'all() tests' => sub { $schema->storage->txn_begin; + my $count = Koha::Cash::Registers->search({ archived => 0 })->count; + my $max_register = Koha::Cash::Registers->search( {}, + { order_by => { '-desc' => 'id' }, rows => 1 } )->single; + my $max_id = $max_register ? $max_register->id : 0; + my $library1 = $builder->build_object( { class => 'Koha::Libraries' @@ -80,7 +85,8 @@ subtest 'all() tests' => sub { class => 'Koha::Cash::Registers', value => { branch => $library1->branchcode, - branch_default => 0 + branch_default => 0, + archived => 0 } } ); @@ -89,7 +95,8 @@ subtest 'all() tests' => sub { class => 'Koha::Cash::Registers', value => { branch => $library1->branchcode, - branch_default => 1 + branch_default => 1, + archived => 0 } } ); @@ -103,7 +110,8 @@ subtest 'all() tests' => sub { { class => 'Koha::Cash::Registers', value => { - branch => $library2->branchcode + branch => $library2->branchcode, + archived => 0 } } ); @@ -114,8 +122,9 @@ subtest 'all() tests' => sub { my $result = $plugin->all; is( ref($result), 'ARRAY', "Return arrayref (no userenv, no filters)" ); is( scalar( @{$result} ), - 3, "Array contains all 3 registers (no userenv, no filters)" ); + 3 + $count, "Array contains all test registers (no userenv, no filters)" ); for my $register ( @{$result} ) { + next if $register->{id} <= $max_id; is( $register->{selected}, 0, "Register is not selected (no userenv)" ); } @@ -128,8 +137,9 @@ subtest 'all() tests' => sub { is( ref($result), 'ARRAY', "Return arrayref (userenv: branchcode, no filters)" ); is( scalar( @{$result} ), - 3, "Array contains all 3 registers (userenv: branchcode, no filters)" ); + 3 + $count, "Array contains all test registers (userenv: branchcode, no filters)" ); for my $register ( @{$result} ) { + next if $register->{id} <= $max_id; is( $register->{selected}, 0, "Register is not selected (userenv: branchcode, no filters)" ); } -- 2.20.1