@@ -, +, @@ prove t/db_dependent/Koha/News.t --- Koha/NewsItem.pm | 6 ++++-- t/db_dependent/Koha/News.t | 11 +++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) --- a/Koha/NewsItem.pm +++ a/Koha/NewsItem.pm @@ -47,8 +47,10 @@ Return the Koha::Patron object for the patron who authored this news item =cut sub author { - my ( $self ) = @_; - return Koha::Patron->_new_from_dbic($self->_result->borrowernumber); + my ($self) = @_; + my $author_rs = $self->_result->borrowernumber; + return unless $author_rs; + return Koha::Patron->_new_from_dbic($author_rs); } =head3 _type --- a/t/db_dependent/Koha/News.t +++ a/t/db_dependent/Koha/News.t @@ -55,10 +55,17 @@ $retrieved_news_item_1->delete; is( Koha::News->search->count, $nb_of_news + 1, 'Delete should have deleted the news_item' ); subtest '->author' => sub { - plan tests => 1; + plan tests => 3; my $news_item = $builder->build_object({ class => 'Koha::News' }); - is( ref($news_item->author), 'Koha::Patron', 'Koha::NewsItem->author returns a Koha::Patron object' ); + my $author = $news_item->author; + is( ref($author), 'Koha::Patron', 'Koha::NewsItem->author returns a Koha::Patron object' ); + + $author->delete; + + $news_item = Koha::News->find($news_item->idnew); + is( ref($news_item), 'Koha::NewsItem', 'News are not deleted alongwith the author' ); + is( $news_item->author, undef, '->author returns undef is the author has been deleted' ); }; $schema->storage->txn_rollback; --