From 96bc0afee25f16953279c4c91f21c9cf2fc62f4b Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 17 Apr 2020 13:36:39 +0100 Subject: [PATCH] Bug 21901: (RM follow-up) Use TestBuilder to fix tests A few tests failed due to missing values for foreign key relationships. Switching to TestBuilder for data mocking resolves this elegantly. Signed-off-by: Martin Renvoize --- t/db_dependent/Letters/TemplateToolkit.t | 61 ++++++++++++------------ t/db_dependent/Serials.t | 55 ++++++++++++++++----- 2 files changed, 74 insertions(+), 42 deletions(-) diff --git a/t/db_dependent/Letters/TemplateToolkit.t b/t/db_dependent/Letters/TemplateToolkit.t index 6f6c3b87c3..6f55a8a93e 100644 --- a/t/db_dependent/Letters/TemplateToolkit.t +++ b/t/db_dependent/Letters/TemplateToolkit.t @@ -65,38 +65,37 @@ my $library = $builder->build( { source => 'Branch' } ); my $patron = $builder->build( { source => 'Borrower' } ); my $patron2 = $builder->build( { source => 'Borrower' } ); -my $biblio = Koha::Biblio->new( +my $item = $builder->build_sample_item(); +my $hold = $builder->build_object( { - title => 'Test Biblio' - } -)->store(); - -my $biblioitem = Koha::Biblioitem->new( - { - biblionumber => $biblio->id() + class => 'Koha::Holds', + value => { + borrowernumber => $patron->{borrowernumber}, + biblionumber => $item->biblionumber + } } -)->store(); +); -my $item = Koha::Item->new( +my $news = $builder->build_object( { - biblionumber => $biblio->id(), - biblioitemnumber => $biblioitem->id() + class => 'Koha::News', + value => { title => 'a news title', content => 'a news content' } } -)->store(); - -my $hold = Koha::Hold->new( +); +my $serial = $builder->build_object( { class => 'Koha::Serials' } ); +my $subscription = $builder->build_object( { class => 'Koha::Subscriptions' } ); +my $suggestion = $builder->build_object( { class => 'Koha::Suggestions' } ); +my $checkout = $builder->build_object( + { class => 'Koha::Checkouts', value => { itemnumber => $item->id } } ); +my $modification = $builder->build_object( { - borrowernumber => $patron->{borrowernumber}, - biblionumber => $biblio->id() + class => 'Koha::Patron::Modifications', + value => { + verification_token => "TEST", + changed_fields => 'firstname,surname' + } } -)->store(); - -my $news = Koha::NewsItem->new({ title => 'a news title', content => 'a news content'})->store(); -my $serial = Koha::Serial->new()->store(); -my $subscription = Koha::Subscription->new()->store(); -my $suggestion = Koha::Suggestion->new()->store(); -my $checkout = Koha::Checkout->new( { itemnumber => $item->id() } )->store(); -my $modification = Koha::Patron::Modification->new( { verification_token => "TEST", changed_fields => 'firstname,surname' } )->store(); +); my $prepared_letter; @@ -143,11 +142,11 @@ $prepared_letter = GetPreparedLetter( module => 'test', letter_code => 'TEST_BIBLIO', tables => { - biblio => $biblio->id(), + biblio => $item->biblionumber, }, ) ); -is( $prepared_letter->{content}, $biblio->id, 'Biblio object used correctly' ); +is( $prepared_letter->{content}, $item->biblionumber, 'Biblio object used correctly' ); $sth->execute( "TEST_LIBRARY", "[% branch.id %]" ); $prepared_letter = GetPreparedLetter( @@ -191,7 +190,7 @@ $prepared_letter = GetPreparedLetter( module => 'test', letter_code => 'TEST_HOLD', tables => { - reserves => { borrowernumber => $patron->{borrowernumber}, biblionumber => $biblio->id() }, + reserves => { borrowernumber => $patron->{borrowernumber}, biblionumber => $item->biblionumber }, }, ) ); @@ -203,7 +202,7 @@ eval { module => 'test', letter_code => 'TEST_HOLD', tables => { - reserves => [ $patron->{borrowernumber}, $biblio->id() ], + reserves => [ $patron->{borrowernumber}, $item->biblionumber ], }, ) ) @@ -219,8 +218,8 @@ $prepared_letter = GetPreparedLetter( tables => { 'branches' => $library, 'borrowers' => $patron, - 'biblio' => $biblio->id, - 'biblioitems' => $biblioitem->id, + 'biblio' => $item->biblionumber, + 'biblioitems' => $item->biblioitemnumber, 'reserves' => $hold->unblessed, 'items' => $hold->itemnumber, } diff --git a/t/db_dependent/Serials.t b/t/db_dependent/Serials.t index 735af75430..53bfed49e1 100755 --- a/t/db_dependent/Serials.t +++ b/t/db_dependent/Serials.t @@ -250,33 +250,66 @@ subtest 'test_updateClaim' => sub { is($result_0, undef, 'Got the expected undef from update claim with nothin'); # Given ... 3 serial. 2 of them updated. - my $serialids_1 = [90980, 90981]; my $claimdate_1 = dt_from_string('2001-01-13'); # arbitrary date some time in the past. my $claim_count_1 = 5; - Koha::Serial->new( { serialid => $serialids_1->[0], serialseq => 'serialseq', subscriptionid => $subscriptionid, status => 3, - biblionumber => 12345, claimdate => $claimdate_1, claims_count => $claim_count_1, } )->store(); - Koha::Serial->new( { serialid => $serialids_1->[1], serialseq => 'serialseq', subscriptionid => $subscriptionid, status => 3, - biblionumber => 12345, claimdate => $claimdate_1, claims_count => $claim_count_1, } )->store(); - Koha::Serial->new( { serialid => 90982, serialseq => 'serialseq', subscriptionid => $subscriptionid, status => 3, - biblionumber => 12345, claimdate => $claimdate_1, claims_count => $claim_count_1, } )->store(); + my $biblio = $builder->build_sample_biblio; + my $serial1 = $builder->build_object( + { + class => 'Koha::Serials', + value => { + serialseq => 'serialseq', + subscriptionid => $subscriptionid, + status => 3, + biblionumber => $biblio->biblionumber, + claimdate => $claimdate_1, + claims_count => $claim_count_1, + } + } + ); + my $serial2 = $builder->build_object( + { + class => 'Koha::Serials', + value => { + serialseq => 'serialseq', + subscriptionid => $subscriptionid, + status => 3, + biblionumber => $biblio->biblionumber, + claimdate => $claimdate_1, + claims_count => $claim_count_1, + } + } + ); + my $serial3 = $builder->build_object( + { + class => 'Koha::Serials', + value => { + serialseq => 'serialseq', + subscriptionid => $subscriptionid, + status => 3, + biblionumber => $biblio->biblionumber, + claimdate => $claimdate_1, + claims_count => $claim_count_1, + } + } + ); # When ... - my $result_1 = C4::Serials::updateClaim($serialids_1); + my $result_1 = C4::Serials::updateClaim([$serial1->serialid, $serial2->serialid]); # Then ... is($result_1, 2, 'Got the expected 2 from update claim with 2 serial ids'); - my @late_or_missing_issues_1_0 = C4::Serials::GetLateOrMissingIssues(undef, $serialids_1->[0]); + my @late_or_missing_issues_1_0 = C4::Serials::GetLateOrMissingIssues(undef, $serial1->serialid); is($late_or_missing_issues_1_0[0]->{claimdate}, $today, 'Got the expected first different claim date from update claim'); is($late_or_missing_issues_1_0[0]->{claims_count}, $claim_count_1+1, 'Got the expected first claim count from update claim'); is($late_or_missing_issues_1_0[0]->{status}, 7, 'Got the expected first claim status from update claim'); - my @late_or_missing_issues_1_1 = C4::Serials::GetLateOrMissingIssues(undef, $serialids_1->[1]); + my @late_or_missing_issues_1_1 = C4::Serials::GetLateOrMissingIssues(undef, $serial2->serialid); is($late_or_missing_issues_1_1[0]->{claimdate}, $today, 'Got the expected second different claim date from update claim'); is($late_or_missing_issues_1_1[0]->{claims_count}, $claim_count_1+1, 'Got the expected second claim count from update claim'); is($late_or_missing_issues_1_1[0]->{status}, 7, 'Got the expected second claim status from update claim'); - my @late_or_missing_issues_1_2 = C4::Serials::GetLateOrMissingIssues(undef, 90982); + my @late_or_missing_issues_1_2 = C4::Serials::GetLateOrMissingIssues(undef, $serial3->serialid); is($late_or_missing_issues_1_2[0]->{claimdate}, output_pref({ dt => $claimdate_1, dateonly => 1}), 'Got the expected unchanged claim date from update claim'); is($late_or_missing_issues_1_2[0]->{claims_count}, $claim_count_1, 'Got the expected unchanged claim count from update claim'); is($late_or_missing_issues_1_2[0]->{status}, 3, 'Got the expected unchanged claim status from update claim'); -- 2.39.5