From 1010def8ffdd1d5656f7f3e3509fc4a61de21566 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Tue, 29 Mar 2016 15:32:24 +0200 Subject: [PATCH] Bug 16155: Adjust a few other tests Content-Type: text/plain; charset=utf-8 Accounts.t: Only added a line that ensures the MPL branch exists. AnonymiseIssueHistory.t: Only add a branch to work with CalcFine.t: Remove default issuing rule and add one instead of updating. Holds.t: Add category S in case it would not exist. MoveItemFromBiblio.t: Replace last _fk construction. Test plan: Run these tests. (See note). Git grep for only_fk, {_fk} and TestBuilder::default_value. Note: Holds.t does not pass. Tests 9 and 39 fail, but they did already. not ok 9 - GetReservesFromItemnumber should return a valid borrowernumber not ok 39 - Test AlterPriority(), move to bottom So this test needs attention, but on another report please :) --- t/db_dependent/Accounts.t | 7 +++---- t/db_dependent/Circulation/AnonymiseIssueHistory.t | 11 ++++++++--- t/db_dependent/Circulation/CalcFine.t | 7 +++++++ t/db_dependent/Holds.t | 6 ++++++ t/db_dependent/Items/MoveItemFromBiblio.t | 11 +++++++++-- 5 files changed, 33 insertions(+), 9 deletions(-) diff --git a/t/db_dependent/Accounts.t b/t/db_dependent/Accounts.t index ee92a48..4bad302 100644 --- a/t/db_dependent/Accounts.t +++ b/t/db_dependent/Accounts.t @@ -52,11 +52,10 @@ my $schema = Koha::Database->new->schema; $schema->storage->txn_begin; my $dbh = C4::Context->dbh; +# this test needs a MPL branch; also create another one my $builder = t::lib::TestBuilder->new(); - -my $library = $builder->build({ - source => 'Branch', -}); +$builder->build({ source => 'Branch', value => { branchcode => 'MPL' }}); +my $library = $builder->build({ source => 'Branch' }); $dbh->do(q|DELETE FROM accountlines|); $dbh->do(q|DELETE FROM issues|); diff --git a/t/db_dependent/Circulation/AnonymiseIssueHistory.t b/t/db_dependent/Circulation/AnonymiseIssueHistory.t index f6ab089..a171897 100644 --- a/t/db_dependent/Circulation/AnonymiseIssueHistory.t +++ b/t/db_dependent/Circulation/AnonymiseIssueHistory.t @@ -35,14 +35,19 @@ $schema->storage->txn_begin; my $builder = t::lib::TestBuilder->new; # TODO create a subroutine in t::lib::Mocks -my $userenv_patron = $builder->build( { source => 'Borrower', }, ); +my $branch = $builder->build({ source => 'Branch' }); +my $userenv_patron = $builder->build({ + source => 'Borrower', + value => { branchcode => $branch->{branchcode} }, +}); C4::Context->_new_userenv('DUMMY SESSION'); C4::Context->set_userenv( $userenv_patron->{borrowernumber}, $userenv_patron->{userid}, 'usercnum', 'First name', 'Surname', - $userenv_patron->{_fk}{branchcode}{branchcode}, - $userenv_patron->{_fk}{branchcode}{branchname}, 0 + $branch->{branchcode}, + $branch->{branchname}, + 0, ); my $anonymous = $builder->build( { source => 'Borrower', }, ); diff --git a/t/db_dependent/Circulation/CalcFine.t b/t/db_dependent/Circulation/CalcFine.t index 66f2d71..862673f 100644 --- a/t/db_dependent/Circulation/CalcFine.t +++ b/t/db_dependent/Circulation/CalcFine.t @@ -65,6 +65,13 @@ my $item = $builder->build( subtest 'Test basic functionality' => sub { plan tests => 1; + + my $rule = $builder->schema->resultset('Issuingrule')->find({ + branchcode => '*', + categorycode => '*', + itemtype => '*', + }); + $rule->delete if $rule; my $issuingrule = $builder->build( { source => 'Issuingrule', diff --git a/t/db_dependent/Holds.t b/t/db_dependent/Holds.t index 4ba95df..4cbf48e 100755 --- a/t/db_dependent/Holds.t +++ b/t/db_dependent/Holds.t @@ -34,6 +34,12 @@ my $dbh = C4::Context->dbh; my $branch_1 = $builder->build({ source => 'Branch' })->{ branchcode }; my $branch_2 = $builder->build({ source => 'Branch' })->{ branchcode }; +# This test assumes we have a category S. This statement helps. +$builder->build({ + source => 'Category', + value => { categorycode => 'S', category_type => 'S' }, +}); + my $borrowers_count = 5; $dbh->do('DELETE FROM itemtypes'); diff --git a/t/db_dependent/Items/MoveItemFromBiblio.t b/t/db_dependent/Items/MoveItemFromBiblio.t index b5cbdd3..29078ca 100644 --- a/t/db_dependent/Items/MoveItemFromBiblio.t +++ b/t/db_dependent/Items/MoveItemFromBiblio.t @@ -23,14 +23,21 @@ use C4::Reserves; use Koha::Database; use t::lib::TestBuilder; +use Data::Dumper qw|Dumper|; my $schema = Koha::Database->new->schema; $schema->storage->txn_begin; my $builder = t::lib::TestBuilder->new; # NOTE This is a trick, if we want to populate the biblioitems table, we should not create a Biblio but a Biblioitem -my $from_biblio = $builder->build( { source => 'Biblioitem', } )->{_fk}{biblionumber}; -my $to_biblio = $builder->build( { source => 'Biblioitem', } )->{_fk}{biblionumber}; +my $param = { source => 'Biblioitem' }; +my $from_biblio = { + biblionumber => $builder->build($param)->{biblionumber}, +}; +my $to_biblio = { + biblionumber => $builder->build($param)->{biblionumber}, +}; + my $item1 = $builder->build( { source => 'Item', value => { biblionumber => $from_biblio->{biblionumber}, }, -- 1.7.10.4