From 5685d33d0316955e983677d5034dc041ad38146d Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 12 Nov 2020 13:11:13 +0100 Subject: [PATCH] Bug 26984: Make tests pass if AnonymousPatron is set There is only 1 place where it can be tricky to not remove them as we want exactly 10 patrons to be present in the DB Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi Signed-off-by: Jonathan Druart (cherry picked from commit a25b651cf257f41fd0a8c601e70acad74b479724) Signed-off-by: Andrew Fuerste-Henry --- t/db_dependent/Accounts.t | 26 ++++----------------- t/db_dependent/Koha/Biblio.t | 20 +++++++--------- t/db_dependent/Koha/Objects.t | 1 + t/db_dependent/Template/Plugin/Categories.t | 14 ++++------- 4 files changed, 18 insertions(+), 43 deletions(-) diff --git a/t/db_dependent/Accounts.t b/t/db_dependent/Accounts.t index 56665ae7cf..b0432a0910 100644 --- a/t/db_dependent/Accounts.t +++ b/t/db_dependent/Accounts.t @@ -56,10 +56,6 @@ my $dbh = C4::Context->dbh; my $builder = t::lib::TestBuilder->new; my $library = $builder->build( { source => 'Branch' } ); -$dbh->do(q|DELETE FROM accountlines|); -$dbh->do(q|DELETE FROM issues|); -$dbh->do(q|DELETE FROM borrowers|); - my $branchcode = $library->{branchcode}; my $context = new Test::MockModule('C4::Context'); @@ -1132,23 +1128,9 @@ subtest "Payment notice tests" => sub { plan tests => 8; - Koha::Account::Lines->delete(); - Koha::Patrons->delete(); Koha::Notice::Messages->delete(); - # Create a borrower - my $categorycode = $builder->build({ source => 'Category' })->{ categorycode }; - my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode }; - - my $borrower = Koha::Patron->new( - { - cardnumber => 'chelseahall', - surname => 'Hall', - firstname => 'Chelsea', - email => 'chelsea@example.com', - categorycode => $categorycode, - branchcode => $branchcode, - } - )->store(); + # Create a patron + my $patron = $builder->build_object({ class => 'Koha::Patrons' }); my $manager = $builder->build_object({ class => "Koha::Patrons" }); my $context = new Test::MockModule('C4::Context'); @@ -1158,11 +1140,11 @@ subtest "Payment notice tests" => sub { branch => $manager->branchcode, }; }); - my $account = Koha::Account->new({ patron_id => $borrower->id }); + my $account = Koha::Account->new({ patron_id => $patron->borrowernumber }); my $line = Koha::Account::Line->new( { - borrowernumber => $borrower->borrowernumber, + borrowernumber => $patron->borrowernumber, amountoutstanding => 27, interface => 'commandline', debit_type_code => 'LOST' diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/Biblio.t index cf359edf32..4283460699 100644 --- a/t/db_dependent/Koha/Biblio.t +++ b/t/db_dependent/Koha/Biblio.t @@ -185,19 +185,12 @@ subtest 'is_serial() tests' => sub { }; subtest 'pickup_locations' => sub { - plan tests => 29; + plan tests => 8; $schema->storage->txn_begin; - my $dbh = C4::Context->dbh; - - # Cleanup database - Koha::Holds->search->delete; - Koha::Patrons->search->delete; - Koha::Items->search->delete; - Koha::Libraries->search->delete; + my $nb_libraries = Koha::Libraries->count; Koha::CirculationRules->search->delete; - $dbh->do('DELETE FROM issues'); Koha::CirculationRules->set_rules( { categorycode => undef, @@ -222,6 +215,8 @@ subtest 'pickup_locations' => sub { my $library7 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); my $library8 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 0 } } ); + our @branchcodes = map { $_->branchcode } ($library1, $library2, $library3, $library4, $library5, $library6, $library7, $library8); + Koha::CirculationRules->set_rules( { branchcode => $library1->branchcode, @@ -373,11 +368,11 @@ subtest 'pickup_locations' => sub { my $patron8 = $builder->build_object( { class => 'Koha::Patrons', value => { firstname=>'8', branchcode => $library8->branchcode } } ); my $results = { - "ItemHomeLibrary-1-1" => 6, + "ItemHomeLibrary-1-1" => 6 + $nb_libraries, "ItemHomeLibrary-1-8" => 1, "ItemHomeLibrary-2-1" => 2, "ItemHomeLibrary-2-8" => 0, - "PatronLibrary-1-1" => 6, + "PatronLibrary-1-1" => 6 + $nb_libraries, "PatronLibrary-1-8" => 3, "PatronLibrary-2-1" => 0, "PatronLibrary-2-8" => 3, @@ -390,6 +385,9 @@ subtest 'pickup_locations' => sub { my @pl = @{ $biblio->pickup_locations( { patron => $patron} ) }; foreach my $pickup_location (@pl) { + next + unless grep { $pickup_location eq $_ } @branchcodes; + is( ref($pickup_location), 'Koha::Library', 'Object type is correct' ); } diff --git a/t/db_dependent/Koha/Objects.t b/t/db_dependent/Koha/Objects.t index c8b86d2c77..b0fb3ef441 100644 --- a/t/db_dependent/Koha/Objects.t +++ b/t/db_dependent/Koha/Objects.t @@ -262,6 +262,7 @@ subtest '->is_paged and ->pager tests' => sub { $schema->storage->txn_begin; # Delete existing patrons + t::lib::Mocks::mock_preference('AnonymousPatron', ''); Koha::Checkouts->delete; Koha::Patrons->delete; # Create 10 patrons diff --git a/t/db_dependent/Template/Plugin/Categories.t b/t/db_dependent/Template/Plugin/Categories.t index b6080c7519..0d99a85465 100644 --- a/t/db_dependent/Template/Plugin/Categories.t +++ b/t/db_dependent/Template/Plugin/Categories.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 5; +use Test::More tests => 4; use t::lib::Mocks; use t::lib::TestBuilder; @@ -30,24 +30,18 @@ use Koha::Template::Plugin::Categories; my $schema = Koha::Database->new->schema; $schema->storage->txn_begin; -# Delete all categories -Koha::Checkouts->search->delete; -Koha::Patrons->search->delete; -Koha::Patron::Categories->search->delete; - my $builder = t::lib::TestBuilder->new; -is( Koha::Template::Plugin::Categories->new->all->count, - 0, '->all returns 0 results if no categories defined' ); +my $nb_categories = Koha::Patron::Categories->count; # Create sample categories my $category_1 = $builder->build( { source => 'Category' } ); my @categories = Koha::Template::Plugin::Categories->new->all; -is( scalar(@categories), 1, '->all returns all defined categories' ); +is( scalar(@categories), 1 + $nb_categories, '->all returns all defined categories' ); my $category_2 = $builder->build( { source => 'Category' } ); @categories = Koha::Template::Plugin::Categories->new->all; -is( scalar(@categories), 2, '->all returns all defined categories' ); +is( scalar(@categories), 2 + $nb_categories, '->all returns all defined categories' ); is( Koha::Template::Plugin::Categories->GetName( $category_1->{categorycode} -- 2.39.5