From 6e8c365e2d47c0a732f8baf85f9a825559103866 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 29 Sep 2020 10:13:59 -0300 Subject: [PATCH] Bug 26555: (QA follow-up) Add ->reset_messages Signed-off-by: David Nind --- Koha/Object.pm | 15 +++++++++++++++ t/db_dependent/Koha/Object.t | 12 ++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Koha/Object.pm b/Koha/Object.pm index da9315dcc8..3e50181672 100644 --- a/Koha/Object.pm +++ b/Koha/Object.pm @@ -375,6 +375,21 @@ sub add_message { return $self; } +=head3 $object->reset_messages + + $object->reset_messages; + +Reset the current object's messages. + +=cut + +sub reset_messages { + my ( $self ) = @_; + + $self->{_messages} = []; + return $self; +} + =head3 $object->TO_JSON Returns an unblessed representation of the object, suitable for JSON output. diff --git a/t/db_dependent/Koha/Object.t b/t/db_dependent/Koha/Object.t index 9031533113..42fb92fa17 100755 --- a/t/db_dependent/Koha/Object.t +++ b/t/db_dependent/Koha/Object.t @@ -868,9 +868,9 @@ subtest 'set_or_blank' => sub { $schema->storage->txn_rollback; }; -subtest 'messages() and add_message() tests' => sub { +subtest 'messages(), add_message() and reset_messages() tests' => sub { - plan tests => 6; + plan tests => 8; my $patron = Koha::Patron->new; @@ -887,4 +887,12 @@ subtest 'messages() and add_message() tests' => sub { is( ref($messages[1]), 'Koha::Object::Message', 'Right type returned' ); is( $messages[0]->message, 'message_1', 'Right message recorded' ); is( $messages[1]->message, 'message_2', 'Right message recorded' ); + + $patron->reset_messages; + @messages = @{ $patron->messages }; + is( scalar @messages, 0, 'No messages are returned' ); + + $patron->reset_messages; + @messages = @{ $patron->messages }; + is( scalar @messages, 0, 'No messages are returned, things ok when calling on already empty list' ); }; -- 2.11.0