From 0b2cfd9d71f727a5ada696e7fbe73ce77885b256 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 30 Jan 2020 12:26:57 +0100 Subject: [PATCH] Bug 22685: Use DBIx::Class relationships in Koha::Acq::Bookseller methods To match PERL15 we change the behavior of Koha::Object methods to make them use the DBIx::Class relationships. Test plan: - Create a vendor, basket and contact - Edit the vendor => the contact must appears - Go to the view of a vendor => you cannot delete the vendor, it has a basket attached - Create another vendor, without basket - Go to the view of the vendor => You can delete it Additionally: % prove t/db_dependent/Koha/Acquisition/Booksellers.t must return green Signed-off-by: David Nind --- Koha/Acquisition/Bookseller.pm | 7 +++++-- t/db_dependent/Koha/Acquisition/Booksellers.t | 13 ++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Koha/Acquisition/Bookseller.pm b/Koha/Acquisition/Bookseller.pm index 708ae51461..3456cdc545 100644 --- a/Koha/Acquisition/Bookseller.pm +++ b/Koha/Acquisition/Bookseller.pm @@ -41,7 +41,8 @@ Returns the list of baskets for the vendor sub baskets { my ( $self ) = @_; - return $self->{_result}->aqbaskets; + my $baskets_rs = $self->_result->aqbaskets; + return Koha::Acquisition::Baskets->_new_from_dbic( $baskets_rs ); } =head3 contacts @@ -55,7 +56,8 @@ Returns the list of contacts for the vendor sub contacts { my ($self) = @_; - return Koha::Acquisition::Bookseller::Contacts->search( { booksellerid => $self->id } ); + my $contacts_rs = $self->_result->aqcontacts; + return Koha::Acquisition::Bookseller::Contacts->_new_from_dbic( $contacts_rs ); } =head3 subscriptions @@ -70,6 +72,7 @@ Returns the list of subscriptions for the vendor sub subscriptions { my ($self) = @_; + # FIXME FK missing at DB level return Koha::Subscriptions->search( { aqbooksellerid => $self->id } ); } diff --git a/t/db_dependent/Koha/Acquisition/Booksellers.t b/t/db_dependent/Koha/Acquisition/Booksellers.t index e3870cd9f8..5b5f58c100 100644 --- a/t/db_dependent/Koha/Acquisition/Booksellers.t +++ b/t/db_dependent/Koha/Acquisition/Booksellers.t @@ -43,7 +43,7 @@ subtest '->baskets() tests' => sub { my $vendor = $builder->build_object( { class => 'Koha::Acquisition::Booksellers' } ); - is( $vendor->baskets, 0, 'Vendor has no baskets' ); + is( $vendor->baskets->count, 0, 'Vendor has no baskets' ); # Add two baskets my $basket_1_id = C4::Acquisition::NewBasket( $vendor->id, $patron->borrowernumber, 'basketname1' ); @@ -51,7 +51,7 @@ subtest '->baskets() tests' => sub { # Re-fetch vendor $vendor = Koha::Acquisition::Booksellers->find( $vendor->id ); - is( $vendor->baskets, 2, 'Vendor has two baskets' ); + is( $vendor->baskets->count, 2, 'Vendor has two baskets' ); $schema->storage->txn_rollback(); }; @@ -139,7 +139,7 @@ subtest '->subscriptions() tests' => sub { subtest '->contacts() tests' => sub { - plan tests => 4; + plan tests => 3; $schema->storage->txn_begin(); @@ -161,10 +161,9 @@ subtest '->contacts() tests' => sub { # Re-fetch vendor $vendor = Koha::Acquisition::Booksellers->find( $vendor->id ); - is( $vendor->contacts->count, 2, 'Vendor has two contacts' ); - foreach my $contact ( $vendor->contacts ) { - is( ref($contact), 'Koha::Acquisition::Bookseller::Contact', 'Type is correct' ); - } + my $contacts = $vendor->contacts; + is( $contacts->count, 2, 'Vendor has two contacts' ); + is( ref($contacts), 'Koha::Acquisition::Bookseller::Contacts', 'Type is correct' ); $schema->storage->txn_rollback(); }; -- 2.11.0